mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 15:07:24 +00:00
Remove duplicate code in world auth handlers
This commit is contained in:
parent
5bf149236a
commit
33fe814273
@ -14,17 +14,40 @@ handle_version_check = login.handle_version_check
|
||||
handle_random_key = login.handle_random_key
|
||||
|
||||
|
||||
async def world_login(p, data):
|
||||
if len(p.server.penguins_by_id) >= p.server.server_config['Capacity']:
|
||||
return await p.send_error_and_disconnect(103)
|
||||
|
||||
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(f'{data.username} logged in successfully')
|
||||
|
||||
p.data = data
|
||||
await p.send_xt('l')
|
||||
|
||||
|
||||
@handlers.handler(XMLPacket('login'), client=ClientType.Vanilla)
|
||||
@handlers.allow_once
|
||||
@handlers.depends_on_packet(XMLPacket('verChk'), XMLPacket('rndK'))
|
||||
async def handle_login(p, credentials: WorldCredentials):
|
||||
if len(p.server.penguins_by_id) >= p.server.server_config['Capacity']:
|
||||
return await p.send_error_and_disconnect(103)
|
||||
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.get('{}.lkey'.format(credentials.username))
|
||||
tr.get('{}.ckey'.format(credentials.username))
|
||||
tr.delete('{}.lkey'.format(credentials.username), '{}.ckey'.format(credentials.username))
|
||||
tr.get(f'{credentials.username}.lkey')
|
||||
tr.get(f'{credentials.username}.ckey')
|
||||
tr.delete(f'{credentials.username}.lkey', f'{credentials.username}.ckey')
|
||||
login_key, confirmation_hash, _ = await tr.execute()
|
||||
|
||||
if login_key is None or confirmation_hash is None:
|
||||
@ -41,40 +64,18 @@ async def handle_login(p, credentials: WorldCredentials):
|
||||
|
||||
data = await Penguin.get(credentials.id)
|
||||
|
||||
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')
|
||||
await world_login(p, data)
|
||||
|
||||
|
||||
@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):
|
||||
if len(p.server.penguins_by_id) >= p.server.server_config['Capacity']:
|
||||
return await p.send_error_and_disconnect(103)
|
||||
|
||||
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()
|
||||
tr.get(f'{credentials.username}.lkey')
|
||||
tr.delete(f'{credentials.username}.lkey', '{credentials.username}.ckey')
|
||||
login_key, _ = await tr.execute()
|
||||
|
||||
login_key = login_key.decode()
|
||||
login_hash = Crypto.encrypt_password(login_key + config.client['AuthStaticKey']) + login_key
|
||||
@ -84,24 +85,5 @@ async def handle_legacy_login(p, credentials: Credentials):
|
||||
|
||||
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')
|
||||
await world_login(p, data)
|
||||
|
Loading…
Reference in New Issue
Block a user