mirror of
https://github.com/solero/houdini.git
synced 2024-11-09 20:58:20 +00:00
Add support for moderator-only servers
This commit is contained in:
parent
d3bd9ac1e3
commit
ac8b20fcfe
@ -31,6 +31,7 @@ if __name__ == '__main__':
|
|||||||
type=int)
|
type=int)
|
||||||
login_group.add_argument('--login-failure-timer', action='store', default=3600, help='Timeout after flood limit',
|
login_group.add_argument('--login-failure-timer', action='store', default=3600, help='Timeout after flood limit',
|
||||||
type=int)
|
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 = parser.add_argument_group('logging')
|
||||||
logging_group.add_argument('-lg', '--logging-general', action='store',
|
logging_group.add_argument('-lg', '--logging-general', action='store',
|
||||||
|
@ -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})
|
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 = []
|
buddy_worlds = []
|
||||||
world_populations = []
|
world_populations = []
|
||||||
|
|
||||||
pops = await p.server.redis.hgetall('houdini.population')
|
pops = await p.server.redis.hgetall('houdini.population')
|
||||||
for server_id, server_population in pops.items():
|
for server_id, server_population in pops.items():
|
||||||
server_population = (7 if int(server_population) == p.server.config.capacity
|
server_population = 7 if int(server_population) == p.server.config.capacity \
|
||||||
else int(server_population) // (p.server.config.capacity // 6)) \
|
else int(server_population) // (p.server.config.capacity // 6)
|
||||||
if server_population else 0
|
server_population = server_population if not pdata.moderator else 0
|
||||||
|
|
||||||
world_populations.append(f'{int(server_id)},{int(server_population)}')
|
world_populations.append(f'{int(server_id)},{int(server_population)}')
|
||||||
|
|
||||||
server_key = f'houdini.players.{int(server_id)}'
|
server_key = f'houdini.players.{int(server_id)}'
|
||||||
if await p.server.redis.scard(server_key):
|
if await p.server.redis.scard(server_key):
|
||||||
async with p.server.db.transaction():
|
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()
|
tr = p.server.redis.multi_exec()
|
||||||
async for buddy_id, in buddies:
|
async for buddy_id, in buddies:
|
||||||
tr.sismember(server_key, buddy_id)
|
tr.sismember(server_key, buddy_id)
|
||||||
|
@ -102,7 +102,7 @@ async def handle_login(p, credentials: Credentials):
|
|||||||
tr.setex(f'{data.username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
tr.setex(f'{data.username}.ckey', p.server.config.auth_ttl, confirmation_hash)
|
||||||
await tr.execute()
|
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:
|
if p.client_type == ClientType.Vanilla:
|
||||||
raw_login_data = '|'.join([str(data.id), str(data.id), data.username, login_key, str(data.approval),
|
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:
|
else:
|
||||||
await p.send_xt('l', raw_login_data, confirmation_hash, '', world_populations, buddy_presence, data.email)
|
await p.send_xt('l', raw_login_data, confirmation_hash, '', world_populations, buddy_presence, data.email)
|
||||||
else:
|
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)
|
||||||
|
@ -16,6 +16,9 @@ async def world_login(p, data):
|
|||||||
if len(p.server.penguins_by_id) >= p.server.config.capacity:
|
if len(p.server.penguins_by_id) >= p.server.config.capacity:
|
||||||
return await p.send_error_and_disconnect(103)
|
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:
|
if data is None:
|
||||||
return await p.send_error_and_disconnect(100)
|
return await p.send_error_and_disconnect(100)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user