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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user