MultiClient: fix roominfo sort
This commit is contained in:
parent
71cd0b917c
commit
2d26d63cce
|
@ -618,13 +618,13 @@ async def process_server_cmd(ctx : Context, cmd, args):
|
||||||
if len(args['players']) < 1:
|
if len(args['players']) < 1:
|
||||||
print('No player connected')
|
print('No player connected')
|
||||||
else:
|
else:
|
||||||
args['players'].sort(key=lambda _, t, s: (t, s))
|
args['players'].sort()
|
||||||
current_team = 0
|
current_team = 0
|
||||||
print('Connected players:')
|
print('Connected players:')
|
||||||
print(' Team #1')
|
print(' Team #1')
|
||||||
for name, team, slot in args['players']:
|
for team, slot, name in args['players']:
|
||||||
if team != current_team:
|
if team != current_team:
|
||||||
print(' Team #d' % team + 1)
|
print(f' Team #{team + 1}')
|
||||||
current_team = team
|
current_team = team
|
||||||
print(' %s (Player %d)' % (name, slot))
|
print(' %s (Player %d)' % (name, slot))
|
||||||
await server_auth(ctx, args['password'])
|
await server_auth(ctx, args['password'])
|
||||||
|
|
|
@ -39,12 +39,6 @@ class Context:
|
||||||
self.clients = []
|
self.clients = []
|
||||||
self.received_items = {}
|
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):
|
async def send_msgs(websocket, msgs):
|
||||||
if not websocket or not websocket.open or websocket.closed:
|
if not websocket or not websocket.open or websocket.closed:
|
||||||
return
|
return
|
||||||
|
@ -100,7 +94,10 @@ async def server(websocket, path, ctx : Context):
|
||||||
ctx.clients.remove(client)
|
ctx.clients.remove(client)
|
||||||
|
|
||||||
async def on_client_connected(ctx : Context, client : 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):
|
async def on_client_disconnected(ctx : Context, client : Client):
|
||||||
if client.auth:
|
if client.auth:
|
||||||
|
|
Loading…
Reference in New Issue