From 2e414e0f5aea4aaa44b19a31a5f0f31e5930f5fc Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 19 Aug 2019 02:24:47 +0100 Subject: [PATCH] AS3 player data lookup handlers --- houdini/handlers/play/player.py | 51 ++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/houdini/handlers/play/player.py b/houdini/handlers/play/player.py index a3f57cd..f6055e7 100644 --- a/houdini/handlers/play/player.py +++ b/houdini/handlers/play/player.py @@ -1,4 +1,4 @@ -from houdini import handlers +from houdini import handlers, ClientType from houdini.handlers import XTPacket from houdini.data.penguin import Penguin @@ -49,6 +49,55 @@ async def handle_get_player(p, penguin_id: int): @handlers.cooldown(1) async def handle_get_mascot(p, mascot_id: int): await p.send_xt('gmo', await get_mascot_string(p, mascot_id)) + + +@handlers.handler(XTPacket('u', 'pbi'), client=ClientType.Vanilla) +@handlers.cooldown(1) +async def handle_get_player_by_id(p, penguin_id: int): + await p.send_xt('pbi', penguin_id) + + +@handlers.handler(XTPacket('u', 'pbs'), client=ClientType.Vanilla) +@handlers.cooldown(1) +async def handle_get_player_by_swid(p, penguin_id: int): + if penguin_id in p.server.penguins_by_id: + nickname = p.server.penguins_by_id[penguin_id].data.nickname + else: + nickname = await Penguin.select('nickname').where(Penguin.id == penguin_id).gino.scalar() + await p.send_xt('pbs', penguin_id, penguin_id, nickname) + + +@handlers.handler(XTPacket('u', 'pbn'), client=ClientType.Vanilla) +@handlers.cooldown(1) +async def handle_get_player_by_name(p, player_name: str): + player_name = player_name.lower() + if player_name in p.server.penguins_by_username: + player = p.server.penguins_by_username[player_name] + await p.send_xt('pbn', player.data.id, player.data.id, player.data.nickname) + else: + player_id, nickname = await Penguin.select('id', 'nickname').where( + Penguin.username == player_name).gino.first() + if player_id is not None: + await p.send_xt('pbn', player_id, player_id, nickname) + else: + await p.send_xt('pbn') + + +@handlers.handler(XTPacket('u', 'pbsms'), client=ClientType.Vanilla) +async def handle_pbsm_start(p): + await p.send_xt('pbsms') + + +@handlers.handler(XTPacket('u', 'pbsm'), client=ClientType.Vanilla) +async def handle_get_player_ids(p, ids: str): + await p.send_xt('pbsm', ids) + + +@handlers.handler(XTPacket('u', 'pbsmf'), client=ClientType.Vanilla) +async def handle_pbsm_finish(p): + await p.send_xt('pbsmf') + + @handlers.handler(XTPacket('u', 'sp')) async def handle_set_player_position(p, x: int, y: int): p.x, p.y = x, y