From 9d945a8a289fd86c36bea5dd6a7d83fdb46a60e7 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 6 Aug 2019 22:55:26 +0100 Subject: [PATCH] Legacy client world authentication handler --- houdini/handlers/login/world.py | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/houdini/handlers/login/world.py b/houdini/handlers/login/world.py index 71fb68f..445a379 100644 --- a/houdini/handlers/login/world.py +++ b/houdini/handlers/login/world.py @@ -58,3 +58,43 @@ async def handle_login(p, credentials: WorldCredentials): p.data = data p.login_key = login_key await p.send_xt('l') + + +@handlers.handler(XMLPacket('login'), client=ClientType.Legacy) +@handlers.allow_once +@handlers.depends_on_packet(XMLPacket('verChk'), XMLPacket('rndK')) +async def handle_legacy_login(p, credentials: Credentials): + tr = p.server.redis.multi_exec() + tr.get('{}.lkey'.format(credentials.username)) + tr.delete('{}.lkey'.format(credentials.username), '{}.ckey'.format(credentials.username)) + login_key, _ = await tr.execute() + + login_key = login_key.decode() + login_hash = Crypto.encrypt_password(login_key + config.client['AuthStaticKey']) + login_key + + if login_key is None or login_hash != credentials.password: + return await p.close() + + data = await Penguin.query.where(Penguin.username == credentials.username).gino.first() + + if data is None: + return await p.send_error_and_disconnect(100) + + if not data.active: + return await p.close() + + if data.permaban: + return await p.close() + + active_ban = await Ban.query.where((Ban.penguin_id == data.id) & (Ban.expires >= datetime.now())).gino.scalar() + if active_ban is not None: + return await p.close() + + if data.id in p.server.penguins_by_id: + await p.server.penguins_by_id[data.id].close() + + p.logger.info('{} logged in successfully'.format(data.username)) + + p.data = data + p.login_key = login_key + await p.send_xt('l')