From ac8b20fcfec6e0978a65412067b7911ee5d53d43 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 2 Jan 2020 23:03:34 +0000 Subject: [PATCH] Add support for moderator-only servers --- bootstrap.py | 1 + houdini/handlers/login/__init__.py | 10 +++++----- houdini/handlers/login/login.py | 4 ++-- houdini/handlers/login/world.py | 3 +++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index b7e4721..e969ca1 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -31,6 +31,7 @@ if __name__ == '__main__': type=int) login_group.add_argument('--login-failure-timer', action='store', default=3600, help='Timeout after flood limit', type=int) + login_group.add_argument('-S', '--staff', action='store_true', help='Staff-only server mode') logging_group = parser.add_argument_group('logging') logging_group.add_argument('-lg', '--logging-general', action='store', diff --git a/houdini/handlers/login/__init__.py b/houdini/handlers/login/__init__.py index 1adfbf7..050ae43 100644 --- a/houdini/handlers/login/__init__.py +++ b/houdini/handlers/login/__init__.py @@ -30,22 +30,22 @@ async def handle_random_key(p, _): await p.send_xml({'body': {'action': 'rndK', 'r': '-1'}, 'k': p.server.config.auth_key}) -async def get_server_presence(p, pid): +async def get_server_presence(p, pdata): buddy_worlds = [] world_populations = [] pops = await p.server.redis.hgetall('houdini.population') for server_id, server_population in pops.items(): - server_population = (7 if int(server_population) == p.server.config.capacity - else int(server_population) // (p.server.config.capacity // 6)) \ - if server_population else 0 + server_population = 7 if int(server_population) == p.server.config.capacity \ + else int(server_population) // (p.server.config.capacity // 6) + server_population = server_population if not pdata.moderator else 0 world_populations.append(f'{int(server_id)},{int(server_population)}') server_key = f'houdini.players.{int(server_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() + 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) diff --git a/houdini/handlers/login/login.py b/houdini/handlers/login/login.py index 60171cf..9927c78 100644 --- a/houdini/handlers/login/login.py +++ b/houdini/handlers/login/login.py @@ -102,7 +102,7 @@ async def handle_login(p, credentials: Credentials): 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.id) + world_populations, buddy_presence = await get_server_presence(p, data) if p.client_type == ClientType.Vanilla: raw_login_data = '|'.join([str(data.id), str(data.id), data.username, login_key, str(data.approval), @@ -113,4 +113,4 @@ async def handle_login(p, credentials: Credentials): else: await p.send_xt('l', raw_login_data, confirmation_hash, '', world_populations, buddy_presence, data.email) else: - await p.send_xt('l', data.id, login_key, world_populations, buddy_presence) + await p.send_xt('l', data.id, login_key, buddy_presence, world_populations) diff --git a/houdini/handlers/login/world.py b/houdini/handlers/login/world.py index 9ae9043..a091d07 100644 --- a/houdini/handlers/login/world.py +++ b/houdini/handlers/login/world.py @@ -16,6 +16,9 @@ async def world_login(p, data): if len(p.server.penguins_by_id) >= p.server.config.capacity: return await p.send_error_and_disconnect(103) + if p.server.config.staff and not data.moderator: + return await p.send_error_and_disconnect(103) + if data is None: return await p.send_error_and_disconnect(100)