From 78d042b1a3af360e9781b004bce1d0f95c42faf5 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 9 Sep 2019 22:21:14 +0100 Subject: [PATCH] Move client disconnect functionality into dummy event listener --- houdini/handlers/play/navigation.py | 13 +++++++++++++ houdini/penguin.py | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/houdini/handlers/play/navigation.py b/houdini/handlers/play/navigation.py index ff2fa23..e1cb7f5 100644 --- a/houdini/handlers/play/navigation.py +++ b/houdini/handlers/play/navigation.py @@ -59,3 +59,16 @@ async def handle_join_room(p, room: Room, x: int, y: int): @handlers.handler(XTPacket('j', 'grs')) async def handle_refresh_room(p): await p.room.refresh(p) + + +@handlers.disconnected +@handlers.player_attribute(joined_world=True) +async def handle_disconnect_room(p): + await p.room.remove_penguin(p) + + del p.server.penguins_by_id[p.data.id] + del p.server.penguins_by_username[p.data.username] + + server_key = '{}.players'.format(p.server.server_config['Id']) + await p.server.redis.srem(server_key, p.data.id) + await p.server.redis.hincrby('population', p.server.server_config['Id'], -1) diff --git a/houdini/penguin.py b/houdini/penguin.py index 105b23a..20334e5 100644 --- a/houdini/penguin.py +++ b/houdini/penguin.py @@ -310,18 +310,6 @@ class Penguin(Spheniscidae): self.data.username, item.name) if item else '{} removed their background item'.format( self.data.username)) - - async def _client_disconnected(self): - if self.joined_world: - if self.room is not None: - await self.room.remove_penguin(self) - - del self.server.penguins_by_id[self.data.id] - del self.server.penguins_by_username[self.data.username] - - await self.server.redis.hincrby('population', self.server.server_config['Id'], -1) - - await super()._client_disconnected() def __repr__(self): if self.data is not None: