Browse Source

fix events not propagating in certain conditions

pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
94598631b1
  1. 11
      steam/core/cm.py
  2. 24
      steam/util/events.py

11
steam/core/cm.py

@ -93,6 +93,7 @@ class CMClient(EventEmitter):
def _init_attributes(self):
self.current_server_addr = None
self.connected = False
self.channel_secured = False
self.key = None
self.hmac_secret = None
@ -143,15 +144,16 @@ class CMClient(EventEmitter):
else:
message = crypto.symmetric_decrypt(message, self.key)
self._parse_message(message)
gevent.spawn(self._parse_message, message)
gevent.idle()
def _parse_message(self, message):
if not self.connected:
return
emsg_id, = struct.unpack_from("<I", message)
emsg = EMsg(clear_proto_bit(emsg_id))
if not self.connected and emsg != EMsg.ClientLogOnResponse:
return
if emsg in (EMsg.ChannelEncryptRequest,
EMsg.ChannelEncryptResponse,
EMsg.ChannelEncryptResult,
@ -214,6 +216,7 @@ class CMClient(EventEmitter):
else:
logger.debug("Channel secured (legacy mode)")
self.channel_secured = True
self.emit('channel_secured')
def _handle_multi(self, msg):

24
steam/util/events.py

@ -13,24 +13,22 @@ class EventEmitter(object):
Emit event with some arguments
"""
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)
if hasattr(self, '_event_callbacks'):
for callback in list(self._event_callbacks[event]):
if isinstance(callback, AsyncResult):
self.remove_listener(event, callback)
result = args
if len(args) == 1:
result = args[0]
result = args
if len(args) == 1:
result = args[0]
callback.set(result)
else:
gevent.spawn(callback, *args)
callback.set(result)
else:
gevent.spawn(callback, *args)
gevent.idle()
gevent.idle()
# every event is also emitted as None
if event is not None:

Loading…
Cancel
Save