World authentication handlers

This commit is contained in:
Ben 2019-05-29 23:06:02 +01:00
parent 99ef5363a8
commit 05d37165a2
4 changed files with 84 additions and 0 deletions

View File

@ -1,5 +1,50 @@
from houdini import handlers
from houdini.handlers import XMLPacket, login
from houdini.converters import WorldCredentials
from houdini.data.penguin import Penguin
from houdini.data.moderator import Ban
from datetime import datetime
handle_version_check = login.handle_version_check
handle_random_key = login.handle_random_key
@handlers.handler(XMLPacket('login'))
@handlers.allow_once()
async def handle_login(p, credentials: WorldCredentials):
tr = p.server.redis.multi_exec()
tr.get('{}.lkey'.format(credentials.id))
tr.get('{}.ckey'.format(credentials.id))
tr.delete('{}.lkey'.format(credentials.id), '{}.ckey'.format(credentials.id))
login_key, confirmation_hash, _ = await tr.execute()
if login_key is None or confirmation_hash is None:
return await p.close()
if login_key.decode() != credentials.login_key or confirmation_hash.decode() != credentials.confirmation_hash:
return await p.close()
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 = credentials.login_key
await p.send_xt('l')

View File

@ -0,0 +1,24 @@
from houdini import handlers
from houdini.handlers import XTPacket
import random
@handlers.handler(XTPacket('j', 'js'), pre_login=True)
@handlers.allow_once()
async def handle_join_server(p, penguin_id: int, login_key: str, lang: str):
if penguin_id != p.data.id:
return await p.close()
if login_key != p.login_key:
return await p.close()
await p.send_xt('activefeatures')
await p.send_xt('js', int(p.data.agent_status), int(0),
int(p.data.moderator), int(p.data.book_modified))
spawn = random.choice(p.server.spawn_rooms)
await spawn.add_penguin(p)
await p.load()
p.joined_world = True

View File

@ -0,0 +1,7 @@
from houdini import handlers
from houdini.handlers import XTPacket
@handlers.handler(XTPacket('p', 'getdigcooldown'), pre_login=True)
async def handle_get_dig_cooldown(p):
await p.send_xt('getdigcooldown', 1)

View File

@ -0,0 +1,8 @@
from houdini import handlers
from houdini.handlers import XTPacket
@handlers.handler(XTPacket('u', 'h'))
@handlers.cooldown(59)
async def handle_heartbeat(p):
await p.send_xt('h')