reconexio
This commit is contained in:
@@ -368,12 +368,18 @@ adminRouter.post("/admin/shuffle-players", async (req: Request, res: Response) =
|
||||
|
||||
// 6. Assign players to rooms and roles randomly
|
||||
const assignments: { [roomId: string]: { p1: any; p2: any } } = {};
|
||||
// Shuffle rooms so pairs go to random rooms
|
||||
const shuffledRooms = [...roomsInfo];
|
||||
for (let i = shuffledRooms.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffledRooms[i], shuffledRooms[j]] = [shuffledRooms[j], shuffledRooms[i]];
|
||||
}
|
||||
|
||||
for (let i = 0; i < playerGroups.length && i < roomsInfo.length; i++) {
|
||||
for (let i = 0; i < playerGroups.length && i < shuffledRooms.length; i++) {
|
||||
const group = playerGroups[i];
|
||||
const roomInfo = roomsInfo[i];
|
||||
const roomInfo = shuffledRooms[i];
|
||||
|
||||
// Randomly assign P1 and P2 roles
|
||||
// Randomize roles P1/P2
|
||||
const [player1, player2] = Math.random() < 0.5 ? [group[0], group[1]] : [group[1], group[0]];
|
||||
|
||||
assignments[roomInfo.roomId] = {
|
||||
@@ -393,6 +399,17 @@ adminRouter.post("/admin/shuffle-players", async (req: Request, res: Response) =
|
||||
.catch(error => console.error(`Failed to clear room ${room.roomId}:`, error))
|
||||
);
|
||||
|
||||
// Clear current-room and reconnection tokens for all players to avoid resume during shuffle
|
||||
try {
|
||||
allPlayers.forEach(p => {
|
||||
const u = p.uuid;
|
||||
if (u) {
|
||||
NameManager.getInstance().clearCurrentRoom(u);
|
||||
(NameManager.getInstance() as any).clearReconnectToken?.(u);
|
||||
}
|
||||
});
|
||||
} catch {}
|
||||
|
||||
await Promise.allSettled(clearPromises);
|
||||
|
||||
// 8. Wait a bit for rooms to clear, then assign new players
|
||||
|
||||
Reference in New Issue
Block a user