Move client disconnect functionality into dummy event listener

This commit is contained in:
Ben 2019-09-09 22:21:14 +01:00
parent c9996c57e7
commit 78d042b1a3
2 changed files with 13 additions and 12 deletions

View File

@ -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)

View File

@ -311,18 +311,6 @@ class Penguin(Spheniscidae):
'{} 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:
return '<Penguin ID=\'{}\' Username=\'{}\'>'.format(self.data.id, self.data.username)