diff --git a/plugin_manager.py b/plugin_manager.py index 63ca51f..0dfabf5 100644 --- a/plugin_manager.py +++ b/plugin_manager.py @@ -32,13 +32,13 @@ def list_plugins(self): return self._plugins @asyncio.coroutine - def do(self, connection, action: str, packet: dict): + def do(self, connection, action: str, packet: dict, direction): """ Calls an action on all loaded plugins. """ try: if ("on_%s" % action) in self._overrides: - packet = yield from self._packet_parser.parse(packet) + packet = yield from self._packet_parser.parse(packet, direction) send_flag = True for plugin in self._plugins.values(): p = getattr(plugin, "on_%s" % action) diff --git a/pparser.py b/pparser.py index 74ae5ca..b4ac0e9 100644 --- a/pparser.py +++ b/pparser.py @@ -71,7 +71,7 @@ def __init__(self, config: ConfigurationManager): self._reaper = self.loop.create_task(self._reap()) @asyncio.coroutine - def parse(self, packet): + def parse(self, packet, direction): """ Given a packet preped packet from the stream, parse it down to its parts. First check if the packet is one we've seen before; if it is, @@ -91,7 +91,7 @@ def parse(self, packet): else: packet = yield from self._parse_and_cache_packet(packet) else: - packet = yield from self._parse_packet(packet) + packet = yield from self._parse_packet(packet, direction) except Exception as e: print("Error during parsing.") print(traceback.print_exc()) @@ -127,7 +127,7 @@ def _parse_and_cache_packet(self, packet): return packet @asyncio.coroutine - def _parse_packet(self, packet): + def _parse_packet(self, packet, direction): """ Parse the packet by giving it to the appropriate parser. @@ -135,6 +135,7 @@ def _parse_packet(self, packet): :return: Fully parsed packet. """ res = parse_map[packet["type"]] + if res is None: packet["parsed"] = {} else: @@ -142,7 +143,7 @@ def _parse_packet(self, packet): # self.loop.executor, res.parse, packet["data"]) # Removed due to issues with testers. Need to evaluate what's going # on. - packet["parsed"] = res.parse(packet["data"]) + packet["parsed"] = res.parse(packet["data"], direction) return packet # def __del__(self): diff --git a/server.py b/server.py index 907ab96..63b5e1b 100644 --- a/server.py +++ b/server.py @@ -54,7 +54,7 @@ def server_loop(self): # if packet['type'] not in [17, 40, 41, 43, 48, 51]: # logger.debug('c->s {}'.format(packet['type'])) - if (yield from self.check_plugins(packet)): + if (yield from self.check_plugins(packet, Direction.TO_SERVER)): yield from self.write_client(packet) except asyncio.IncompleteReadError: # Pass on these errors. These occur when a player disconnects badly @@ -83,7 +83,7 @@ def client_loop(self): # if packet['type'] not in [7, 17, 23, 27, 31, 43, 49, 51]: # logger.debug('s->c {}'.format(packet['type'])) - send_flag = yield from self.check_plugins(packet) + send_flag = yield from self.check_plugins(packet, Direction.TO_CLIENT) if send_flag: yield from self.write(packet) except asyncio.IncompleteReadError: @@ -176,11 +176,11 @@ def die(self): self._alive = False @asyncio.coroutine - def check_plugins(self, packet): + def check_plugins(self, packet, direction): return (yield from self.factory.plugin_manager.do( self, packets[packet['type']], - packet)) + packet, direction)) def __del__(self): try: