MultiServer: add !status command
This commit is contained in:
parent
6b0b78d8e0
commit
45f92536a6
|
@ -166,6 +166,7 @@ class CommonContext():
|
||||||
self.server = None
|
self.server = None
|
||||||
self.server_task = None
|
self.server_task = None
|
||||||
|
|
||||||
|
# noinspection PyAttributeOutsideInit
|
||||||
def set_getters(self, data_package: dict, network=False):
|
def set_getters(self, data_package: dict, network=False):
|
||||||
if not network: # local data; check if newer data was already downloaded
|
if not network: # local data; check if newer data was already downloaded
|
||||||
local_package = Utils.persistent_load().get("datapackage", {}).get("latest", {})
|
local_package = Utils.persistent_load().get("datapackage", {}).get("latest", {})
|
||||||
|
|
|
@ -420,13 +420,7 @@ class Context:
|
||||||
|
|
||||||
def get_aliased_name(self, team: int, slot: int):
|
def get_aliased_name(self, team: int, slot: int):
|
||||||
if (team, slot) in self.name_aliases:
|
if (team, slot) in self.name_aliases:
|
||||||
if self.client_game_state[team,slot] == ClientStatus.CLIENT_GOAL:
|
|
||||||
return f"*{self.name_aliases[team, slot]}* ({self.player_names[team, slot]})"
|
|
||||||
else:
|
|
||||||
return f"{self.name_aliases[team, slot]} ({self.player_names[team, slot]})"
|
return f"{self.name_aliases[team, slot]} ({self.player_names[team, slot]})"
|
||||||
else:
|
|
||||||
if self.client_game_state[team,slot] == ClientStatus.CLIENT_GOAL:
|
|
||||||
return f"*{self.player_names[team, slot]}*"
|
|
||||||
else:
|
else:
|
||||||
return self.player_names[team, slot]
|
return self.player_names[team, slot]
|
||||||
|
|
||||||
|
@ -573,6 +567,18 @@ def get_players_string(ctx: Context):
|
||||||
return f'{len(auth_clients)} players of {len(ctx.player_names)} connected ' + text[:-1]
|
return f'{len(auth_clients)} players of {len(ctx.player_names)} connected ' + text[:-1]
|
||||||
|
|
||||||
|
|
||||||
|
def get_status_string(ctx: Context, team):
|
||||||
|
text = "Player Status on your team:"
|
||||||
|
for team in ctx.clients:
|
||||||
|
for slot in ctx.locations:
|
||||||
|
connected = len(ctx.clients[team][slot])
|
||||||
|
completion_text = f"({len(ctx.location_checks[team, slot])}/{len(ctx.locations[slot])})"
|
||||||
|
goal_text = " and has finished." if ctx.client_game_state[team, slot] == ClientStatus.CLIENT_GOAL else "."
|
||||||
|
text += f"\n{ctx.get_aliased_name(team, slot)} has {connected} connection{'' if connected == 1 else 's'}" \
|
||||||
|
f"{goal_text} {completion_text}"
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def get_received_items(ctx: Context, team: int, player: int) -> typing.List[NetworkItem]:
|
def get_received_items(ctx: Context, team: int, player: int) -> typing.List[NetworkItem]:
|
||||||
return ctx.received_items.setdefault((team, player), [])
|
return ctx.received_items.setdefault((team, player), [])
|
||||||
|
|
||||||
|
@ -920,6 +926,11 @@ class ClientMessageProcessor(CommonCommandProcessor):
|
||||||
self.output(get_players_string(self.ctx))
|
self.output(get_players_string(self.ctx))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _cmd_status(self) -> bool:
|
||||||
|
"""Get status information about your team."""
|
||||||
|
self.output(get_status_string(self.ctx, self.client.team))
|
||||||
|
return True
|
||||||
|
|
||||||
def _cmd_forfeit(self) -> bool:
|
def _cmd_forfeit(self) -> bool:
|
||||||
"""Surrender and send your remaining items out to their recipients"""
|
"""Surrender and send your remaining items out to their recipients"""
|
||||||
if self.ctx.allow_forfeits.get((self.client.team, self.client.slot), False):
|
if self.ctx.allow_forfeits.get((self.client.team, self.client.slot), False):
|
||||||
|
|
Loading…
Reference in New Issue