Core: Improve join/leave messages, add "HintGame" tag (#2859)
* Add better "verbs" on joining msg, and improve leaving msgs * Add 'HintGame' tag, for projects like BKSudoku/APSudoku/HintMachine * data in one place instead of 3 * Clean up 'ignore_game' loop to use any() instead --------- Co-authored-by: beauxq <beauxq@yahoo.com>
This commit is contained in:
parent
6f8b8fc9c9
commit
ea6235e0d9
|
@ -803,14 +803,25 @@ async def on_client_disconnected(ctx: Context, client: Client):
|
||||||
await on_client_left(ctx, client)
|
await on_client_left(ctx, client)
|
||||||
|
|
||||||
|
|
||||||
|
_non_game_messages = {"HintGame": "hinting", "Tracker": "tracking", "TextOnly": "viewing"}
|
||||||
|
""" { tag: ui_message } """
|
||||||
|
|
||||||
|
|
||||||
async def on_client_joined(ctx: Context, client: Client):
|
async def on_client_joined(ctx: Context, client: Client):
|
||||||
if ctx.client_game_state[client.team, client.slot] == ClientStatus.CLIENT_UNKNOWN:
|
if ctx.client_game_state[client.team, client.slot] == ClientStatus.CLIENT_UNKNOWN:
|
||||||
update_client_status(ctx, client, ClientStatus.CLIENT_CONNECTED)
|
update_client_status(ctx, client, ClientStatus.CLIENT_CONNECTED)
|
||||||
version_str = '.'.join(str(x) for x in client.version)
|
version_str = '.'.join(str(x) for x in client.version)
|
||||||
verb = "tracking" if "Tracker" in client.tags else "playing"
|
|
||||||
|
for tag, verb in _non_game_messages.items():
|
||||||
|
if tag in client.tags:
|
||||||
|
final_verb = verb
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
final_verb = "playing"
|
||||||
|
|
||||||
ctx.broadcast_text_all(
|
ctx.broadcast_text_all(
|
||||||
f"{ctx.get_aliased_name(client.team, client.slot)} (Team #{client.team + 1}) "
|
f"{ctx.get_aliased_name(client.team, client.slot)} (Team #{client.team + 1}) "
|
||||||
f"{verb} {ctx.games[client.slot]} has joined. "
|
f"{final_verb} {ctx.games[client.slot]} has joined. "
|
||||||
f"Client({version_str}), {client.tags}.",
|
f"Client({version_str}), {client.tags}.",
|
||||||
{"type": "Join", "team": client.team, "slot": client.slot, "tags": client.tags})
|
{"type": "Join", "team": client.team, "slot": client.slot, "tags": client.tags})
|
||||||
ctx.notify_client(client, "Now that you are connected, "
|
ctx.notify_client(client, "Now that you are connected, "
|
||||||
|
@ -825,8 +836,19 @@ async def on_client_left(ctx: Context, client: Client):
|
||||||
if len(ctx.clients[client.team][client.slot]) < 1:
|
if len(ctx.clients[client.team][client.slot]) < 1:
|
||||||
update_client_status(ctx, client, ClientStatus.CLIENT_UNKNOWN)
|
update_client_status(ctx, client, ClientStatus.CLIENT_UNKNOWN)
|
||||||
ctx.client_connection_timers[client.team, client.slot] = datetime.datetime.now(datetime.timezone.utc)
|
ctx.client_connection_timers[client.team, client.slot] = datetime.datetime.now(datetime.timezone.utc)
|
||||||
|
|
||||||
|
version_str = '.'.join(str(x) for x in client.version)
|
||||||
|
|
||||||
|
for tag, verb in _non_game_messages.items():
|
||||||
|
if tag in client.tags:
|
||||||
|
final_verb = f"stopped {verb}"
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
final_verb = "left"
|
||||||
|
|
||||||
ctx.broadcast_text_all(
|
ctx.broadcast_text_all(
|
||||||
"%s (Team #%d) has left the game" % (ctx.get_aliased_name(client.team, client.slot), client.team + 1),
|
f"{ctx.get_aliased_name(client.team, client.slot)} (Team #{client.team + 1}) has {final_verb} the game. "
|
||||||
|
f"Client({version_str}), {client.tags}.",
|
||||||
{"type": "Part", "team": client.team, "slot": client.slot})
|
{"type": "Part", "team": client.team, "slot": client.slot})
|
||||||
|
|
||||||
|
|
||||||
|
@ -1631,7 +1653,9 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict):
|
||||||
else:
|
else:
|
||||||
team, slot = ctx.connect_names[args['name']]
|
team, slot = ctx.connect_names[args['name']]
|
||||||
game = ctx.games[slot]
|
game = ctx.games[slot]
|
||||||
ignore_game = ("TextOnly" in args["tags"] or "Tracker" in args["tags"]) and not args.get("game")
|
|
||||||
|
ignore_game = not args.get("game") and any(tag in _non_game_messages for tag in args["tags"])
|
||||||
|
|
||||||
if not ignore_game and args['game'] != game:
|
if not ignore_game and args['game'] != game:
|
||||||
errors.add('InvalidGame')
|
errors.add('InvalidGame')
|
||||||
minver = min_client_version if ignore_game else ctx.minimum_client_versions[slot]
|
minver = min_client_version if ignore_game else ctx.minimum_client_versions[slot]
|
||||||
|
|
Loading…
Reference in New Issue