dtzktrz
This commit is contained in:
parent
c3a1ddfc85
commit
0e23a4ec57
@ -188,16 +188,16 @@ function startReadyTimer(io, matchId) {
|
|||||||
if (io._arenaTimers.has(matchId)) return;
|
if (io._arenaTimers.has(matchId)) return;
|
||||||
|
|
||||||
let remaining = READY_TIMEOUT;
|
let remaining = READY_TIMEOUT;
|
||||||
io.to("arena_" + matchId).emit("ready_timer", { remaining });
|
emitToMatch(io, matchId, "ready_timer", { remaining });
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
remaining--;
|
remaining--;
|
||||||
io.to("arena_" + matchId).emit("ready_timer", { remaining });
|
emitToMatch(io, matchId, "ready_timer", { remaining });
|
||||||
if (remaining <= 0) {
|
if (remaining <= 0) {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
io._arenaTimers.delete(matchId);
|
io._arenaTimers.delete(matchId);
|
||||||
console.log(`[1v1] Match ${matchId} abgebrochen – Zeit abgelaufen.`);
|
console.log(`[1v1] Match ${matchId} abgebrochen – Zeit abgelaufen.`);
|
||||||
io.to("arena_" + matchId).emit("match_cancelled", {
|
emitToMatch(io, matchId, "match_cancelled", {
|
||||||
reason: "timeout",
|
reason: "timeout",
|
||||||
message: "Zeit abgelaufen.",
|
message: "Zeit abgelaufen.",
|
||||||
});
|
});
|
||||||
@ -359,16 +359,30 @@ function registerTeamModeHandlers(io, socket, mode) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Helper: Event an beide Spieler senden (Room-Broadcast) ── */
|
/* ── Hilfsfunktionen: Direkte Socket-Zustellung ── */
|
||||||
function emitToMatch(io, matchId, event, data) {
|
function getRoom(io, matchId) {
|
||||||
io.to("arena_" + matchId).emit(event, data);
|
return io._arenaRooms?.get(matchId) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sendet an beide Spieler über ihre gespeicherten Socket-IDs
|
||||||
|
function emitToMatch(io, matchId, event, data) {
|
||||||
|
const room = getRoom(io, matchId);
|
||||||
|
if (!room) { console.warn(`[emitToMatch] Kein Room für ${matchId}`); return; }
|
||||||
|
["player1", "player2"].forEach((slot) => {
|
||||||
|
if (room.sockets[slot]) {
|
||||||
|
io.to(room.sockets[slot]).emit(event, data);
|
||||||
|
console.log(`[emitToMatch] ${event} → ${slot} (${room.sockets[slot]})`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sendet an den Gegner des Senders
|
||||||
function emitToOpponent(io, matchId, senderSlot, event, data) {
|
function emitToOpponent(io, matchId, senderSlot, event, data) {
|
||||||
const opponentSlot = senderSlot === "player1" ? "player2" : "player1";
|
const room = getRoom(io, matchId);
|
||||||
const room = io._arenaRooms?.get(matchId);
|
if (!room) return;
|
||||||
if (room?.sockets[opponentSlot]) {
|
const oppSlot = senderSlot === "player1" ? "player2" : "player1";
|
||||||
io.to(room.sockets[opponentSlot]).emit(event, data);
|
if (room.sockets[oppSlot]) {
|
||||||
|
io.to(room.sockets[oppSlot]).emit(event, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,10 +479,10 @@ function registerArenaHandlers(io, socket) {
|
|||||||
if (!io._arenaReady.has(matchId)) io._arenaReady.set(matchId, new Set());
|
if (!io._arenaReady.has(matchId)) io._arenaReady.set(matchId, new Set());
|
||||||
const readySet = io._arenaReady.get(matchId);
|
const readySet = io._arenaReady.get(matchId);
|
||||||
readySet.add(slot);
|
readySet.add(slot);
|
||||||
io.to("arena_" + matchId).emit("ready_status", {
|
const readyData = { readyCount: readySet.size, readySlots: Array.from(readySet) };
|
||||||
readyCount: readySet.size,
|
// Direkt an beide Spieler senden (zuverlässiger als Room-Broadcast)
|
||||||
readySlots: Array.from(readySet),
|
emitToMatch(io, matchId, "ready_status", readyData);
|
||||||
});
|
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);
|
||||||
|
|||||||
@ -930,6 +930,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("ready_status", (data) => {
|
socket.on("ready_status", (data) => {
|
||||||
|
console.log("[1v1] ready_status empfangen:", data);
|
||||||
const pip1 = document.getElementById("pip-player1");
|
const pip1 = document.getElementById("pip-player1");
|
||||||
const pip2 = document.getElementById("pip-player2");
|
const pip2 = document.getElementById("pip-player2");
|
||||||
if (data.readySlots) {
|
if (data.readySlots) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user