dtkmtz
This commit is contained in:
parent
0e23a4ec57
commit
a766fc7fe9
@ -480,12 +480,25 @@ function registerArenaHandlers(io, socket) {
|
|||||||
const readySet = io._arenaReady.get(matchId);
|
const readySet = io._arenaReady.get(matchId);
|
||||||
readySet.add(slot);
|
readySet.add(slot);
|
||||||
const readyData = { readyCount: readySet.size, readySlots: Array.from(readySet) };
|
const readyData = { readyCount: readySet.size, readySlots: Array.from(readySet) };
|
||||||
// Direkt an beide Spieler senden (zuverlässiger als Room-Broadcast)
|
|
||||||
emitToMatch(io, matchId, "ready_status", readyData);
|
emitToMatch(io, matchId, "ready_status", readyData);
|
||||||
console.log(`[1v1] ready_status: ${readySet.size}/2 bereit | Match ${matchId}`);
|
console.log(`[1v1] ready_status: ${readySet.size}/2 bereit | Match ${matchId}`);
|
||||||
|
|
||||||
if (readySet.size >= 2) {
|
if (readySet.size >= 2) {
|
||||||
stopReadyTimer(io, matchId);
|
stopReadyTimer(io, matchId);
|
||||||
io._arenaReady.delete(matchId);
|
io._arenaReady.delete(matchId);
|
||||||
|
|
||||||
|
// Server startet Zug direkt – kein end_turn_init vom Client nötig
|
||||||
|
// Startspieler: player1 (deterministisch, kein Flip nötig auf Server-Seite)
|
||||||
|
const starterSlot = "player1";
|
||||||
|
if (!io._turnInit) io._turnInit = new Set();
|
||||||
|
if (!io._turnInit.has(matchId)) {
|
||||||
|
io._turnInit.add(matchId);
|
||||||
|
setTimeout(() => io._turnInit?.delete(matchId), 60000);
|
||||||
|
const room = io._arenaRooms?.get(matchId);
|
||||||
|
const boardCards = room?.boardCards || [];
|
||||||
|
emitToMatch(io, matchId, "turn_change", { activeSlot: starterSlot, boardSync: boardCards });
|
||||||
|
console.log(`[1v1] Spiel startet → ${starterSlot} beginnt | Match ${matchId}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -994,12 +994,9 @@
|
|||||||
// Festlegen ob ich der linke Spieler bin
|
// Festlegen ob ich der linke Spieler bin
|
||||||
amILeftPlayer = flip ? mySlot === "player2" : mySlot === "player1";
|
amILeftPlayer = flip ? mySlot === "player2" : mySlot === "player1";
|
||||||
|
|
||||||
// Nur player1 sendet end_turn_init → verhindert Doppelverarbeitung
|
// Server startet Zug automatisch wenn beide bereit sind
|
||||||
// turn_change vom Server setzt dann den korrekten Zustand für BEIDE Spieler
|
// turn_change kommt vom Server → kein end_turn_init nötig
|
||||||
const starterSlot = flip ? "player2" : "player1";
|
console.log("[1v1] Beide bereit – warte auf turn_change vom Server...");
|
||||||
if (mySlot === "player1") {
|
|
||||||
socket.emit("end_turn_init", { matchId, starterSlot });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user