Browse Source

set steam/session id for outgoing msgs

pull/18/merge
Rossen Georgiev 9 years ago
parent
commit
961512be26
  1. 15
      steam/client/cm.py
  2. 44
      steam/client/msg.py

15
steam/client/cm.py

@ -113,9 +113,6 @@ class CMClient:
self.steam_id = None self.steam_id = None
self.session_id = None self.session_id = None
self.cell_id = None
self.webapi_nonce = None
self._recv_loop = None self._recv_loop = None
self._heartbeat_loop = None self._heartbeat_loop = None
@ -123,6 +120,11 @@ class CMClient:
if not isinstance(message, (Msg, MsgProto)): if not isinstance(message, (Msg, MsgProto)):
raise ValueError("Expected Msg or MsgProto, got %s" % message) 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: if self.verbose_debug:
logger.debug("Outgoing: %s\n%s" % (repr(message), str(message))) logger.debug("Outgoing: %s\n%s" % (repr(message), str(message)))
else: else:
@ -175,7 +177,7 @@ class CMClient:
) )
raise raise
self.dispatch_message(emsg, msg) gevent.spawn(self.dispatch_message, emsg, msg)
def dispatch_message(self, emsg, msg): def dispatch_message(self, emsg, msg):
if self.verbose_debug: if self.verbose_debug:
@ -190,7 +192,7 @@ class CMClient:
self.unregister_callback(emsg, callback) self.unregister_callback(emsg, callback)
callback.set((emsg, msg)) callback.set((emsg, msg))
else: else:
gevent.spawn(callback, emsg, msg) callback(emsg, msg)
def register_callback(self, emsg, callback): def register_callback(self, emsg, callback):
if emsg not in self.registered_callbacks: if emsg not in self.registered_callbacks:
@ -284,9 +286,6 @@ class CMClient:
self.steam_id = SteamID(msg.header.steamid) self.steam_id = SteamID(msg.header.steamid)
self.session_id = msg.header.client_sessionid 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: if self._heartbeat_loop:
self._heartbeat_loop.kill() self._heartbeat_loop.kill()

44
steam/client/msg.py

@ -135,7 +135,7 @@ class MsgHdrProtoBuf:
self.proto.ParseFromString(data[size:self._fullsize]) self.proto.ParseFromString(data[size:self._fullsize])
class Msg: class Msg(object):
def __init__(self, msg, data=None, extended=False): def __init__(self, msg, data=None, extended=False):
self.extended = extended self.extended = extended
self.header = ExtendedMsgHdr(data) if extended else MsgHdr(data) self.header = ExtendedMsgHdr(data) if extended else MsgHdr(data)
@ -159,6 +159,30 @@ class Msg:
def serialize(self): def serialize(self):
return self.header.serialize() + self.body.serialize() 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): def __repr__(self):
return "<Msg %s>" % repr(self.msg) return "<Msg %s>" % repr(self.msg)
@ -214,7 +238,7 @@ def get_cmsg(emsg):
return None return None
class MsgProto: class MsgProto(object):
def __init__(self, msg, data=None): def __init__(self, msg, data=None):
self._header = MsgHdrProtoBuf(data) self._header = MsgHdrProtoBuf(data)
self._header.msg = msg self._header.msg = msg
@ -230,6 +254,22 @@ class MsgProto:
def serialize(self): def serialize(self):
return self._header.serialize() + self.body.SerializeToString() 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): def __repr__(self):
return "<MsgProto %s>" % repr(self.msg) return "<MsgProto %s>" % repr(self.msg)

Loading…
Cancel
Save