修复多人模式成绩问题

This commit is contained in:
咕谷酱
2025-08-22 06:42:59 +08:00
parent 845aab4aed
commit 42f17d0c66
2 changed files with 152 additions and 5 deletions

View File

@@ -237,7 +237,7 @@ class SpectatorHub(Hub[StoreClientState]):
# Check all active multiplayer rooms for playing users
for room_id, server_room in MultiplayerHubs.rooms.items():
for room_user in server_room.room.users:
# If user is playing in multiplayer but we don't have their spectator state
# Send state for users who are playing or in results
if (
room_user.state.is_playing
and room_user.user_id not in self.state
@@ -266,6 +266,35 @@ class SpectatorHub(Hub[StoreClientState]):
logger.debug(
f"[SpectatorHub] Failed to create synthetic state: {e}"
)
# Critical addition: Notify about finished players in multiplayer games
elif (
room_user.state == MultiplayerUserState.RESULTS
and room_user.user_id not in self.state
):
try:
# Create a synthetic finished state
finished_state = SpectatorState(
beatmap_id=server_room.queue.current_item.beatmap_id,
ruleset_id=room_user.ruleset_id or 0,
mods=room_user.mods,
state=SpectatedUserState.Passed, # Assume passed for results
maximum_statistics={},
)
await self.call_noblock(
client,
"UserFinishedPlaying",
room_user.user_id,
finished_state,
)
logger.debug(
f"[SpectatorHub] Sent synthetic finished state for user {room_user.user_id}"
)
except Exception as e:
logger.debug(
f"[SpectatorHub] Failed to create synthetic finished state: {e}"
)
except Exception as e:
logger.debug(f"[SpectatorHub] Failed to sync with MultiplayerHub: {e}")