Move buddy and character disconnect to a dummy handler

This commit is contained in:
Ben 2019-09-09 22:14:01 +01:00
parent 90ce0a0ab7
commit d176b92e4a
2 changed files with 15 additions and 11 deletions

View File

@ -191,3 +191,18 @@ async def handle_toggle_best_character(p, character_id: int):
if character_id in p.data.character_buddies:
character_buddy_record = p.data.character_buddies[character_id]
await character_buddy_record.update(best_buddy=not character_buddy_record.best_buddy).apply()
@handlers.disconnected
@handlers.player_attribute(joined_world=True)
async def handle_disconnect_buddy(p):
if p.data.character is not None:
del p.server.penguins_by_character_id[p.data.character]
for penguin in p.server.penguins_by_id.values():
if p.data.character in penguin.data.character_buddies:
await penguin.send_xt('caof', p.data.character)
for buddy_id in p.data.buddies:
if buddy_id in p.server.penguins_by_id:
await p.server.penguins_by_id[buddy_id].send_xt('bof', p.data.id)

View File

@ -319,17 +319,6 @@ class Penguin(Spheniscidae):
del self.server.penguins_by_id[self.data.id]
del self.server.penguins_by_username[self.data.username]
if self.data.character is not None:
del self.server.penguins_by_character_id[self.data.character]
for penguin in self.server.penguins_by_id.values():
if self.data.character in penguin.data.character_buddies:
await penguin.send_xt('caof', self.data.character)
for buddy_id in self.data.buddies:
if buddy_id in self.server.penguins_by_id:
await self.server.penguins_by_id[buddy_id].send_xt('bof', self.data.id)
await self.server.redis.hincrby('population', self.server.server_config['Id'], -1)
await super()._client_disconnected()