Legacy client world authentication handler

This commit is contained in:
Ben 2019-08-06 22:55:26 +01:00
parent 4fa0f4dfe0
commit 9d945a8a28

View File

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