mirror of
https://github.com/solero/houdini.git
synced 2024-12-22 05:23:39 +00:00
commit
6b12be1c15
@ -45,10 +45,12 @@ async def get_server_presence(p, pdata):
|
||||
if await p.server.redis.scard(server_key):
|
||||
async with p.server.db.transaction():
|
||||
buddies = BuddyList.select('buddy_id').where(BuddyList.penguin_id == pdata.id).gino.iterate()
|
||||
tr = p.server.redis.multi_exec()
|
||||
async for buddy_id, in buddies:
|
||||
tr.sismember(server_key, buddy_id)
|
||||
online_buddies = await tr.execute()
|
||||
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
async for buddy_id, in buddies:
|
||||
tr.sismember(server_key, buddy_id)
|
||||
online_buddies = await tr.execute()
|
||||
|
||||
if any(online_buddies):
|
||||
buddy_worlds.append(str(int(server_id)))
|
||||
|
||||
|
@ -41,10 +41,10 @@ async def handle_login(p, credentials: Credentials):
|
||||
p.logger.info(f'{username} failed to login: incorrect password')
|
||||
|
||||
if await p.server.redis.exists(flood_key):
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.incr(flood_key)
|
||||
tr.expire(flood_key, p.server.config.login_failure_timer)
|
||||
failure_count, _ = await tr.execute()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.incr(flood_key)
|
||||
tr.expire(flood_key, p.server.config.login_failure_timer)
|
||||
failure_count, _ = await tr.execute()
|
||||
|
||||
if failure_count >= p.server.config.login_failure_limit:
|
||||
return await p.send_error_and_disconnect(150)
|
||||
@ -100,10 +100,11 @@ async def handle_login(p, credentials: Credentials):
|
||||
login_key = Crypto.hash(random_key[::-1])
|
||||
confirmation_hash = Crypto.hash(os.urandom(24))
|
||||
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.setex(f'{data.username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
tr.setex(f'{data.username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
||||
await tr.execute()
|
||||
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.setex(f'{data.username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
tr.setex(f'{data.username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
||||
await tr.execute()
|
||||
|
||||
world_populations, buddy_presence = await get_server_presence(p, data)
|
||||
|
||||
|
@ -41,11 +41,11 @@ async def world_login(p, data):
|
||||
@handlers.allow_once
|
||||
@handlers.depends_on_packet(XMLPacket('verChk'), XMLPacket('rndK'))
|
||||
async def handle_login(p, credentials: WorldCredentials):
|
||||
tr = p.server.redis.multi_exec()
|
||||
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()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
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:
|
||||
return await p.close()
|
||||
@ -69,10 +69,10 @@ async def handle_login(p, credentials: WorldCredentials):
|
||||
@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(f'{credentials.username}.lkey')
|
||||
tr.delete(f'{credentials.username}.lkey', f'{credentials.username}.ckey')
|
||||
login_key, _ = await tr.execute()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.get(f'{credentials.username}.lkey')
|
||||
tr.delete(f'{credentials.username}.lkey', f'{credentials.username}.ckey')
|
||||
login_key, _ = await tr.execute()
|
||||
|
||||
try:
|
||||
login_key = login_key.decode()
|
||||
|
@ -12,10 +12,10 @@ async def handle_join_redemption_server_vanilla(p, credentials: str, confirmatio
|
||||
if login_key != p.login_key:
|
||||
return await p.close()
|
||||
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.setex(f'{username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
tr.setex(f'{username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
||||
await tr.execute()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.setex(f'{username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
tr.setex(f'{username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
||||
await tr.execute()
|
||||
|
||||
redeemed_books = await PenguinRedemptionBook.query.where(PenguinRedemptionBook.penguin_id == p.id).gino.all()
|
||||
await p.send_xt('rjs', ','.join(str(redeemed_book.book_id) for redeemed_book in redeemed_books), 'houdini',
|
||||
@ -28,9 +28,9 @@ async def handle_join_redemption_server_legacy(p, _, login_key: str):
|
||||
if login_key != p.login_key:
|
||||
return await p.close()
|
||||
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.setex(f'{p.username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
await tr.execute()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.setex(f'{p.username}.lkey', p.server.config.auth_ttl, login_key)
|
||||
await tr.execute()
|
||||
|
||||
redeemed_books = await PenguinRedemptionBook.query.where(PenguinRedemptionBook.penguin_id == p.id).gino.all()
|
||||
await p.send_xt('rjs', ','.join(str(redeemed_book.book_id) for redeemed_book in redeemed_books), 'houdini',
|
||||
|
@ -37,10 +37,10 @@ async def handle_send_book_answer(p, book: int, question_id: int, answer: str):
|
||||
redemption_attempts_key = f'{p.id}.redemption_attempts'
|
||||
|
||||
if await p.server.redis.exists(redemption_attempts_key):
|
||||
tr = p.server.redis.multi_exec()
|
||||
tr.incr(redemption_attempts_key)
|
||||
tr.expire(redemption_attempts_key, p.server.config.login_failure_timer)
|
||||
failure_count, _ = await tr.execute()
|
||||
async with p.server.redis.pipeline(transaction=True) as tr:
|
||||
tr.incr(redemption_attempts_key)
|
||||
tr.expire(redemption_attempts_key, p.server.config.login_failure_timer)
|
||||
failure_count, _ = await tr.execute()
|
||||
|
||||
if failure_count >= 5:
|
||||
return await p.send_error(713)
|
||||
|
Loading…
Reference in New Issue
Block a user