MultiClient: fix roominfo sort

This commit is contained in:
Bonta-kun 2020-01-15 03:00:30 +01:00
parent 71cd0b917c
commit 2d26d63cce
2 changed files with 7 additions and 10 deletions

View File

@ -618,13 +618,13 @@ async def process_server_cmd(ctx : Context, cmd, args):
if len(args['players']) < 1:
print('No player connected')
else:
args['players'].sort(key=lambda _, t, s: (t, s))
args['players'].sort()
current_team = 0
print('Connected players:')
print(' Team #1')
for name, team, slot in args['players']:
for team, slot, name in args['players']:
if team != current_team:
print(' Team #d' % team + 1)
print(f' Team #{team + 1}')
current_team = team
print(' %s (Player %d)' % (name, slot))
await server_auth(ctx, args['password'])

View File

@ -39,12 +39,6 @@ class Context:
self.clients = []
self.received_items = {}
def get_room_info(ctx : Context):
return {
'password': ctx.password is not None,
'players': [(client.name, client.team, client.slot) for client in ctx.clients if client.auth]
}
async def send_msgs(websocket, msgs):
if not websocket or not websocket.open or websocket.closed:
return
@ -100,7 +94,10 @@ async def server(websocket, path, ctx : Context):
ctx.clients.remove(client)
async def on_client_connected(ctx : Context, client : Client):
await send_msgs(client.socket, [['RoomInfo', get_room_info(ctx)]])
await send_msgs(client.socket, [['RoomInfo', {
'password': ctx.password is not None,
'players': [(client.team, client.slot, client.name) for client in ctx.clients if client.auth]
}]])
async def on_client_disconnected(ctx : Context, client : Client):
if client.auth: