diff --git a/steam/client/__init__.py b/steam/client/__init__.py index 37dfdd3..2709f8d 100644 --- a/steam/client/__init__.py +++ b/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): diff --git a/steam/core/cm.py b/steam/core/cm.py index 9c12f58..c84a926 100644 --- a/steam/core/cm.py +++ b/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("