hgxkzh
This commit is contained in:
parent
3c35cd8594
commit
afc744f0ee
@ -359,24 +359,30 @@ function registerTeamModeHandlers(io, socket, mode) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Helper: Event direkt an beide Spieler eines Matches senden ── */
|
/* ── Helper: Event an beide Spieler senden (direkt + Room-Fallback) ── */
|
||||||
function emitToMatch(io, matchId, event, data) {
|
function emitToMatch(io, matchId, event, data) {
|
||||||
const room = io._arenaRooms?.get(matchId);
|
const room = io._arenaRooms?.get(matchId);
|
||||||
if (!room) return;
|
// Direkt an bekannte Socket-IDs senden
|
||||||
["player1", "player2"].forEach((slot) => {
|
if (room) {
|
||||||
if (room.sockets[slot]) {
|
["player1", "player2"].forEach((slot) => {
|
||||||
io.to(room.sockets[slot]).emit(event, data);
|
if (room.sockets[slot]) {
|
||||||
}
|
io.to(room.sockets[slot]).emit(event, data);
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Zusätzlich Room-Broadcast als Fallback (z.B. nach Reconnect)
|
||||||
|
io.to("arena_" + matchId).emit(event, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitToOpponent(io, matchId, senderSlot, event, data) {
|
function emitToOpponent(io, matchId, senderSlot, event, data) {
|
||||||
const room = io._arenaRooms?.get(matchId);
|
const room = io._arenaRooms?.get(matchId);
|
||||||
if (!room) return;
|
|
||||||
const opponentSlot = senderSlot === "player1" ? "player2" : "player1";
|
const opponentSlot = senderSlot === "player1" ? "player2" : "player1";
|
||||||
if (room.sockets[opponentSlot]) {
|
// Direkt an Gegner-Socket senden
|
||||||
|
if (room?.sockets[opponentSlot]) {
|
||||||
io.to(room.sockets[opponentSlot]).emit(event, data);
|
io.to(room.sockets[opponentSlot]).emit(event, data);
|
||||||
}
|
}
|
||||||
|
// Zusätzlich Room-Broadcast als Fallback
|
||||||
|
io.to("arena_" + matchId).emit(event, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ═══════════════════════════════════════════════════════════
|
/* ═══════════════════════════════════════════════════════════
|
||||||
|
|||||||
@ -880,7 +880,7 @@
|
|||||||
socket.on("turn_change", (data) => {
|
socket.on("turn_change", (data) => {
|
||||||
// Duplikat-Schutz: identisches Event innerhalb 500ms ignorieren
|
// Duplikat-Schutz: identisches Event innerhalb 500ms ignorieren
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastTurnChangeTs < 500) return;
|
if (now - lastTurnChangeTs < 200) return;
|
||||||
lastTurnChangeTs = now;
|
lastTurnChangeTs = now;
|
||||||
|
|
||||||
const nowMyTurn = data.activeSlot === mySlot;
|
const nowMyTurn = data.activeSlot === mySlot;
|
||||||
@ -1359,17 +1359,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* ── Gegner hat Karte gespielt → auf Board anzeigen ── */
|
/* ── Gegner hat Karte gespielt → auf Board anzeigen ── */
|
||||||
const receivedCardEvents = new Set(); // Duplikat-Schutz
|
|
||||||
socket.on("card_played", (data) => {
|
socket.on("card_played", (data) => {
|
||||||
// Eigene Aktionen ignorieren (bereits lokal gesetzt)
|
// Eigene Aktionen ignorieren (lokal bereits gesetzt)
|
||||||
if (data.slot === mySlot) return;
|
if (data.slot === mySlot) return;
|
||||||
|
|
||||||
// Duplikat-Schutz: dasselbe boardSlot-Event nicht doppelt verarbeiten
|
// Slot bereits belegt → ignorieren
|
||||||
const eventKey = data.boardSlot + "_" + (data.card?.name || "");
|
if (boardState[data.boardSlot]) return;
|
||||||
if (receivedCardEvents.has(eventKey)) return;
|
|
||||||
receivedCardEvents.add(eventKey);
|
|
||||||
// Key nach 2s wieder freigeben (für spätere Karten auf demselben Slot)
|
|
||||||
setTimeout(() => receivedCardEvents.delete(eventKey), 2000);
|
|
||||||
|
|
||||||
const slotEl = document.getElementById(data.boardSlot);
|
const slotEl = document.getElementById(data.boardSlot);
|
||||||
if (!slotEl) {
|
if (!slotEl) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user