mirror of
https://github.com/solero/houdini.git
synced 2024-11-25 23:17:24 +00:00
Move buddy presence generation to login module
This commit is contained in:
parent
ffdc515880
commit
ad122f1987
@ -1,7 +1,11 @@
|
||||
import config
|
||||
|
||||
from houdini import handlers
|
||||
from houdini.handlers import XMLPacket
|
||||
from houdini.converters import VersionChkConverter
|
||||
|
||||
from houdini.data.buddy import BuddyList
|
||||
|
||||
|
||||
@handlers.handler(XMLPacket('verChk'))
|
||||
@handlers.allow_once
|
||||
@ -17,3 +21,31 @@ async def handle_version_check(p, version: VersionChkConverter):
|
||||
@handlers.allow_once
|
||||
async def handle_random_key(p, data):
|
||||
await p.send_xml({'body': {'action': 'rndK', 'r': '-1'}, 'k': 'houdini'})
|
||||
|
||||
|
||||
async def get_server_presence(p, pid):
|
||||
buddy_worlds = []
|
||||
world_populations = []
|
||||
|
||||
for server_name, server_config in config.servers.items():
|
||||
if server_config['World']:
|
||||
server_population = await p.server.redis.hget('population', server_name)
|
||||
server_population = (7 if int(server_population) == server_config['Capacity']
|
||||
else int(server_population) / (server_config['Capacity'] / 6)) \
|
||||
if server_population else 0
|
||||
|
||||
world_populations.append('{},{}'.format(server_config['Id'], server_population))
|
||||
|
||||
server_key = '{}.players'.format(server_config['Id'])
|
||||
|
||||
if await p.server.redis.scard(server_key):
|
||||
async with p.server.db.transaction():
|
||||
buddies = BuddyList.select('buddy_id').where(BuddyList.penguin_id == pid).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()
|
||||
if any(online_buddies):
|
||||
buddy_worlds.append(server_config['Id'])
|
||||
|
||||
return '|'.join(world_populations), '|'.join(buddy_worlds)
|
||||
|
@ -1,8 +1,8 @@
|
||||
from houdini import handlers
|
||||
from houdini.handlers import XMLPacket, login
|
||||
from houdini.handlers.login import get_server_presence
|
||||
from houdini.converters import Credentials
|
||||
from houdini.data.penguin import Penguin
|
||||
from houdini.data.buddy import BuddyList
|
||||
from houdini.data.moderator import Ban
|
||||
from houdini.crypto import Crypto
|
||||
|
||||
@ -88,35 +88,11 @@ async def handle_login(p, credentials: Credentials):
|
||||
tr.setex('{}.ckey'.format(data.id), p.server.server_config['KeyTTL'], confirmation_hash)
|
||||
await tr.execute()
|
||||
|
||||
buddy_worlds = []
|
||||
world_populations = []
|
||||
|
||||
servers_config = config.servers
|
||||
|
||||
for server_name, server_config in servers_config.items():
|
||||
if server_config['World']:
|
||||
server_population = await p.server.redis.get('{}.population'.format(server_name))
|
||||
server_population = (7 if int(server_population) == server_config['Capacity']
|
||||
else int(server_population) / (server_config['Capacity'] / 6)) \
|
||||
if server_population else 0
|
||||
|
||||
server_players = await p.server.redis.smembers('{}.players'.format(server_name))
|
||||
|
||||
world_populations.append('{},{}'.format(server_config['Id'], server_population))
|
||||
|
||||
if not len(server_players) > 0:
|
||||
p.logger.debug('Skipping buddy iteration for {}'.format(server_name))
|
||||
continue
|
||||
|
||||
buddies = await BuddyList.select('BuddyID').where(BuddyList.PenguinID == data.ID).gino.all()
|
||||
for buddy_id in buddies:
|
||||
if str(buddy_id) in server_players:
|
||||
buddy_worlds.append(server_config['Id'])
|
||||
break
|
||||
world_populations, buddy_presence = await get_server_presence(p, data.id)
|
||||
|
||||
raw_login_data = '|'.join([str(data.id), str(data.id), data.username, login_key, str(data.approval),
|
||||
str(data.rejection)])
|
||||
await p.send_xt('l', raw_login_data, confirmation_hash, '', '|'.join(world_populations), '|'.join(buddy_worlds),
|
||||
await p.send_xt('l', raw_login_data, confirmation_hash, '', world_populations, buddy_presence,
|
||||
data.email)
|
||||
|
||||
handle_version_check = login.handle_version_check
|
||||
|
Loading…
Reference in New Issue
Block a user