From f65cb46261e3a57ef5835ee1c72bd7e38001b95f Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 26 Dec 2015 20:00:39 +0000 Subject: [PATCH] message debug; nozip multi fix --- steam/client/cm.py | 64 +++++++++++++++++++++++-------------- steam/client/msg.py | 77 ++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 111 insertions(+), 30 deletions(-) diff --git a/steam/client/cm.py b/steam/client/cm.py index 26d95f1..93c1f52 100644 --- a/steam/client/cm.py +++ b/steam/client/cm.py @@ -44,6 +44,7 @@ class CMClient: UDP = 1 def __init__(self, protocol=0): + self.verbose_debug = False self.reconnect = False self._init_attributes() @@ -94,7 +95,9 @@ class CMClient: self.connection.disconnect() self._recv_loop.kill(block=False) - self._heartbeat_loop.kill() + + if self._heartbeat_loop: + self._heartbeat_loop.kill() self._init_attributes() @@ -120,12 +123,16 @@ class CMClient: if not isinstance(message, (Msg, MsgProto)): raise ValueError("Expected Msg or MsgProto, got %s" % message) + if self.verbose_debug: + logger.debug("Outgoing: %s\n%s" % (repr(message), str(message))) + else: + logger.debug("Outgoing: %s", repr(message)) + data = message.serialize() if self.key: data = crypto.encrypt(data, self.key) - logger.debug("Outgoing: %s", repr(message.msg)) self.connection.put_message(data) def _recv_messages(self): @@ -149,8 +156,6 @@ class CMClient: emsg_id, = struct.unpack_from(" 0: size, = struct.unpack_from("" % repr(self.msg) + def __str__(self): - return '' + rows = ["Msg"] + + header = str(self.header) + if header: + rows.append("-------------- header --") + rows.append(header) + + body = str(self.body) + if body: + rows.append("---------------- body --") + rows.append(body) + + if len(rows) == 1: + rows[0] += " (empty)" + + return '\n'.join(rows) cmsg_lookup = None @@ -195,13 +230,26 @@ class MsgProto: def serialize(self): return self._header.serialize() + self.body.SerializeToString() + def __repr__(self): + return "" % repr(self.msg) + def __str__(self): - return '\n'.join(['MsgProto', - '-' * 20, - str(self.header), - '-' * 20, - str(self.body), - ]) + rows = ["MsgProto"] + + header = str(self.header).rstrip() + if header: + rows.append("-------------- header --") + rows.append(header) + + body = str(self.body).rstrip() + if body: + rows.append("---------------- body --") + rows.append(body) + + if len(rows) == 1: + rows[0] += " (empty)" + + return '\n'.join(rows) class ChannelEncryptRequest: @@ -222,6 +270,11 @@ class ChannelEncryptRequest: self.universe = EUniverse(universe) + def __str__(self): + return '\n'.join(["protocolVersion: %s" % self.protocolVersion, + "universe: %s" % repr(self.universe), + ]) + class ChannelEncryptResponse: def __init__(self, data=None): @@ -250,6 +303,13 @@ class ChannelEncryptResponse: _, ) = struct.unpack_from("