From 961512be2664373789d31363e5cc45e2b5581cb9 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Tue, 29 Dec 2015 18:30:58 +0000 Subject: [PATCH] set steam/session id for outgoing msgs --- steam/client/cm.py | 15 +++++++-------- steam/client/msg.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/steam/client/cm.py b/steam/client/cm.py index 93c1f52..c1003b0 100644 --- a/steam/client/cm.py +++ b/steam/client/cm.py @@ -113,9 +113,6 @@ class CMClient: self.steam_id = None self.session_id = None - self.cell_id = None - self.webapi_nonce = None - self._recv_loop = None self._heartbeat_loop = None @@ -123,6 +120,11 @@ class CMClient: if not isinstance(message, (Msg, MsgProto)): raise ValueError("Expected Msg or MsgProto, got %s" % message) + if self.steam_id: + message.steamID = self.steam_id + if self.session_id: + message.sessionID = self.session_id + if self.verbose_debug: logger.debug("Outgoing: %s\n%s" % (repr(message), str(message))) else: @@ -175,7 +177,7 @@ class CMClient: ) raise - self.dispatch_message(emsg, msg) + gevent.spawn(self.dispatch_message, emsg, msg) def dispatch_message(self, emsg, msg): if self.verbose_debug: @@ -190,7 +192,7 @@ class CMClient: self.unregister_callback(emsg, callback) callback.set((emsg, msg)) else: - gevent.spawn(callback, emsg, msg) + callback(emsg, msg) def register_callback(self, emsg, callback): if emsg not in self.registered_callbacks: @@ -284,9 +286,6 @@ class CMClient: self.steam_id = SteamID(msg.header.steamid) self.session_id = msg.header.client_sessionid - self.cell_id = msg.body.cell_id - self.webapi_nonce = msg.body.webapi_authenticate_user_nonce - if self._heartbeat_loop: self._heartbeat_loop.kill() diff --git a/steam/client/msg.py b/steam/client/msg.py index ed3a5db..f1d0a40 100644 --- a/steam/client/msg.py +++ b/steam/client/msg.py @@ -135,7 +135,7 @@ class MsgHdrProtoBuf: self.proto.ParseFromString(data[size:self._fullsize]) -class Msg: +class Msg(object): def __init__(self, msg, data=None, extended=False): self.extended = extended self.header = ExtendedMsgHdr(data) if extended else MsgHdr(data) @@ -159,6 +159,30 @@ class Msg: def serialize(self): return self.header.serialize() + self.body.serialize() + @property + def steamID(self): + return (self.header.steamID + if isinstance(self.header, ExtendedMsgHdr) + else None + ) + + @steamID.setter + def steamID(self, value): + if isinstance(self.header, ExtendedMsgHdr): + self.header.steamID = value + + @property + def sessionID(self): + return (self.header.sessionID + if isinstance(self.header, ExtendedMsgHdr) + else None + ) + + @sessionID.setter + def sessionID(self, value): + if isinstance(self.header, ExtendedMsgHdr): + self.header.sessionID = value + def __repr__(self): return "" % repr(self.msg) @@ -214,7 +238,7 @@ def get_cmsg(emsg): return None -class MsgProto: +class MsgProto(object): def __init__(self, msg, data=None): self._header = MsgHdrProtoBuf(data) self._header.msg = msg @@ -230,6 +254,22 @@ class MsgProto: def serialize(self): return self._header.serialize() + self.body.SerializeToString() + @property + def steamID(self): + return self.header.steamid + + @steamID.setter + def steamID(self, value): + self.header.steamid = value + + @property + def sessionID(self): + return self.header.client_sessionid + + @sessionID.setter + def sessionID(self, value): + self.header.client_sessionid = value + def __repr__(self): return "" % repr(self.msg)