Add support for moderator-only servers

This commit is contained in:
Ben 2020-01-02 23:03:34 +00:00
parent d3bd9ac1e3
commit ac8b20fcfe
4 changed files with 11 additions and 7 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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)

View File

@ -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)