From 97087b54ea869a31ae08fdab1e3b75bf670d5d92 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sun, 30 Jun 2019 16:44:03 +0100 Subject: [PATCH] add payload property to messages --- steam/core/msg/__init__.py | 27 +++++++++++++++++++++------ steam/core/msg/headers.py | 2 +- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/steam/core/msg/__init__.py b/steam/core/msg/__init__.py index 84aa219..0a254f3 100644 --- a/steam/core/msg/__init__.py +++ b/steam/core/msg/__init__.py @@ -42,7 +42,7 @@ def get_cmsg(emsg): """Get protobuf for a given EMsg :param emsg: EMsg - :type emsg: :class:`steam.enums.emsg.EMsg`, :class:`int` + :type emsg: :class:`steam.enums.emsg.EMsg`, :class:`int` :return: protobuf message """ if not isinstance(emsg, EMsg): @@ -60,7 +60,8 @@ def get_cmsg(emsg): class Msg(object): proto = False - body = '!!! NO BODY !!!' + body = '!!! Unknown message body !!!' #: message instance + payload = None #: Will contain body payload, if we fail to find correct message class def __init__(self, msg, data=None, extended=False): self.extended = extended @@ -74,6 +75,8 @@ class Msg(object): if deserializer: self.body = deserializer(data) + else: + self.payload = data @property def msg(self): @@ -124,12 +127,17 @@ class Msg(object): rows.append("---------------- body --") rows.append(body if body else "(empty)") + if self.payload: + rows.append("------------- payload --") + rows.append(repr(self.payload)) + return '\n'.join(rows) class MsgProto(object): proto = True - body = "!!! NO BODY !!!" + body = '!!! Unknown message body !!!' #: protobuf message instance + payload = None #: Will contain body payload, if we fail to find correct proto message def __init__(self, msg, data=None): self._header = MsgHdrProtoBuf(data) @@ -141,16 +149,19 @@ class MsgProto(object): if proto: self.body = proto() else: - self.body = '!! Can\'t resolve ServiceMethod: %s !!' % repr(self.header.target_job_name) + self.body = '!! Failed to resolve UM for: %s !!' % repr(self.header.target_job_name) else: proto = get_cmsg(msg) if proto: self.body = proto() - if data: - data = data[self._header._fullsize:] + if data: + data = data[self._header._fullsize:] + if proto: self.body.ParseFromString(data) + else: + self.payload = data @property def msg(self): @@ -193,5 +204,9 @@ class MsgProto(object): rows.append("---------------- body --") rows.append(body if body else "(empty)") + if self.payload: + rows.append("------------- payload --") + rows.append(repr(self.payload)) + return '\n'.join(rows) diff --git a/steam/core/msg/headers.py b/steam/core/msg/headers.py index ad72fff..dc74afa 100644 --- a/steam/core/msg/headers.py +++ b/steam/core/msg/headers.py @@ -83,7 +83,7 @@ class ExtendedMsgHdr: class MsgHdrProtoBuf: - _size = struct.calcsize("