From 90ae61b79e1f924a585a0a06a410a5f29c019b21 Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Mon, 11 Jan 2016 21:18:58 +0000 Subject: [PATCH] added GC proxy object --- Makefile | 9 ++- protobuf_list.txt | 1 + steam/client/gc.py | 51 ++++++++++++ steam/core/msg.py | 81 +++++++++++++++++++ steam/protobufs/gc_pb2.py | 161 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 301 insertions(+), 2 deletions(-) create mode 100644 steam/client/gc.py create mode 100644 steam/protobufs/gc_pb2.py diff --git a/Makefile b/Makefile index 685a792..7c83a2d 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,11 @@ pb_fetch: wget -nv --show-progress -N -P ./steam/protobufs/ -i protobuf_list.txt pb_compile: - protoc --python_out ./steam/protobufs/ --proto_path=/usr/include --proto_path=./steam/protobufs ./steam/protobufs/*.proto + for filepath in `ls ./steam/protobufs/*.proto`; do \ + protoc --python_out ./steam/protobufs/ --proto_path=/usr/include --proto_path=./steam/protobufs "$$filepath"; \ + done; -pb_update: pb_fetch pb_compile +pb_clear: + rm -f ./stema/protobufs/*.proto + +pb_update: pb_fetch pb_compile pb_clear diff --git a/protobuf_list.txt b/protobuf_list.txt index 16b7a54..472613e 100644 --- a/protobuf_list.txt +++ b/protobuf_list.txt @@ -2,3 +2,4 @@ https://github.com/SteamRE/SteamKit/raw/master/Resources/Protobufs/steamclient/e https://github.com/SteamRE/SteamKit/raw/master/Resources/Protobufs/steamclient/steammessages_base.proto https://github.com/SteamRE/SteamKit/raw/master/Resources/Protobufs/steamclient/steammessages_clientserver.proto https://github.com/SteamRE/SteamKit/raw/master/Resources/Protobufs/steamclient/steammessages_clientserver_2.proto +https://github.com/SteamRE/SteamKit/raw/master/Resources/Protobufs/gc/gc.proto diff --git a/steam/client/gc.py b/steam/client/gc.py new file mode 100644 index 0000000..ae30a9e --- /dev/null +++ b/steam/client/gc.py @@ -0,0 +1,51 @@ +import logging +import gevent +from steam.util.events import EventEmitter +from steam.util import set_proto_bit, clear_proto_bit, is_proto +from steam.enums.emsg import EMsg +from steam.enums import EResult +from steam.core.msg import GCMsgHdr, GCMsgHdrProto, MsgProto + + +class GameCoordinator(EventEmitter): + def __init__(self, client, app_id): + self.client = client + self.app_id = app_id + self._log = logging.getLogger("GC(appid:%d)" % app_id) + + # listen for GC messages + self.client.on(EMsg.ClientFromGC, self._handle_from_gc) + + def emit(self, event, *args): + if event is not None: + self._log.debug("Emit event: %s" % repr(event)) + super(GameCoordinator, self).emit(event, *args) + + def send(self, header, body): + message = MsgProto(EMsg.ClientToGC) + message.header.routing_appid = self.app_id + message.body.appid = self.app_id + message.body.msgtype = (set_proto_bit(header.msg) + if header.proto + else header.msg + ) + message.body.payload = header.serialize() + body + + self.client.send(message) + + def _handle_from_gc(self, msg): + if msg.body.appid != self.app_id: + return + + emsg = msg.body.msgtype + + if is_proto(emsg): + header = GCMsgHdrProto(emsg, msg.body.payload) + header_size = GCMsgHdrProto._size + header.headerLength + else: + header = GCMsgHdr(emsg, msg.body.payload) + header_size = GCMsgHdr._size + + body = msg.body.payload[header_size:] + + self.emit(clear_proto_bit(emsg), header, body) diff --git a/steam/core/msg.py b/steam/core/msg.py index 31e0f4c..0531770 100644 --- a/steam/core/msg.py +++ b/steam/core/msg.py @@ -5,6 +5,7 @@ from steam.enums.emsg import EMsg from steam.protobufs import steammessages_base_pb2 from steam.protobufs import steammessages_clientserver_pb2 from steam.protobufs import steammessages_clientserver_2_pb2 +from steam.protobufs import gc_pb2 from steam.util import set_proto_bit, clear_proto_bit @@ -382,3 +383,83 @@ class ClientLogOnResponse: def __str__(self): return "eresult: %s" % repr(self.eresult) + + +class GCMsgHdr: + _size = struct.calcsize("