Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions pparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
Expand Down Expand Up @@ -127,22 +127,23 @@ 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.

:param packet: Packet with header information parsed.
:return: Fully parsed packet.
"""
res = parse_map[packet["type"]]

if res is None:
packet["parsed"] = {}
else:
#packet["parsed"] = yield from self.loop.run_in_executor(
# 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):
Expand Down
8 changes: 4 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down