Browse Source

improved event propagation + CM disconnect handling

pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
75311b72ba
  1. 9
      steam/client/__init__.py
  2. 3
      steam/core/cm.py
  3. 4
      steam/util/events.py

9
steam/client/__init__.py

@ -48,8 +48,8 @@ class SteamClient(EventEmitter):
result = EResult(msg.body.eresult)
if result == EResult.OK:
self.emit("logged_on")
self.logged_on = True
self.emit("logged_on")
return
# CM kills the connection on error anyway
@ -64,6 +64,9 @@ class SteamClient(EventEmitter):
self.emit("error", result)
def send(self, message):
if not self.connected:
raise RuntimeError("Cannot send message while not connected")
self.cm.send_message(message)
def anonymous_login(self):
@ -75,7 +78,6 @@ class SteamClient(EventEmitter):
if not self.connected:
self.connect()
self.wait_event("channel_secured")
message = MsgProto(EMsg.ClientLogon)
@ -113,8 +115,9 @@ class SteamClient(EventEmitter):
def logout(self):
if self.logged_on:
self.send(MsgProto(EMsg.ClientLogOff))
self.logged_on = False
self.send(MsgProto(EMsg.ClientLogOff))
self.wait_event('disconnected')
def games_played(self, app_ids):
if not isinstance(app_ids, list):

3
steam/core/cm.py

@ -156,6 +156,9 @@ class CMClient(EventEmitter):
self._parse_message(message)
def _parse_message(self, message):
if not self.connected:
return
emsg_id, = struct.unpack_from("<I", message)
emsg = EMsg(clear_proto_bit(emsg_id))

4
steam/util/events.py

@ -16,6 +16,8 @@ class EventEmitter(object):
if not hasattr(self, '_event_callbacks'):
return
gevent.idle()
for callback in list(self._event_callbacks[event]):
if isinstance(callback, AsyncResult):
self.remove_listener(event, callback)
@ -28,6 +30,8 @@ class EventEmitter(object):
else:
gevent.spawn(callback, *args)
gevent.idle()
# every event is also emitted as None
if event is not None:
self.emit(None, event, *args)

Loading…
Cancel
Save