Improve Redis key handling and spectator sync logic

Enhances Redis key type checks and cleanup in message system, adds periodic cleanup task, and improves error handling for Redis operations. Refines multiplayer and spectator hub logic to better synchronize player states and prevent invalid spectator sessions. Adds more detailed logging for channel/user join/leave events and spectator watch requests.
This commit is contained in:
咕谷酱
2025-08-22 23:53:53 +08:00
committed by MingxuanGame
parent d4f542c64b
commit 5959254de6
5 changed files with 166 additions and 30 deletions

View File

@@ -1018,6 +1018,18 @@ class MultiplayerHub(Hub[MultiplayerClientState]):
played_user,
ex=3600,
)
# Ensure spectator hub is aware of all active players for the new game.
# This helps spectators receive score data for every participant,
# especially in subsequent rounds where state may get out of sync.
for room_user in room.room.users:
if (client := self.get_client_by_id(str(room_user.user_id))) is not None:
try:
await self._sync_with_spectator_hub(client, room)
except Exception as e:
logger.debug(
f"[MultiplayerHub] Failed to resync spectator hub for user {room_user.user_id}: {e}"
)
else:
await room.queue.finish_current_item()