fixing game history and removing comments

This commit is contained in:
Edd
2026-01-03 16:59:14 +00:00
parent 3ba3487f81
commit b6845ee0ea
8 changed files with 453 additions and 3021 deletions
+4 -7
View File
@@ -48,11 +48,9 @@ class BiscaGame {
this.dealInitialCards();
// --- FIX: Ensure currentTurn uses the original ID type (Number) ---
// Object.keys returns strings ("1"), which breaks strict checks against user.id (1)
const playerKeys = Object.keys(this.players);
const startKey = playerKeys.find((key) => key != 1) || playerKeys[0];
this.currentTurn = this.players[startKey].id;
this.currentTurn = this.players[startKey].id;
this.startTime = Date.now();
this.status = "playing";
@@ -192,7 +190,6 @@ class BiscaGame {
this.players[winnerId].tricks += 1;
this.currentTurn = winnerId;
// --- FIX: Always draw if deck has cards (Removed type check) ---
if (this.deck.length > 0 || this.trumpCard) {
this.drawCard(winnerId);
this.drawCard(this.getOpponentId(winnerId));
@@ -222,8 +219,8 @@ class BiscaGame {
const finalLoser = isDraw
? null
: gameWinnerId == p1Obj.id
? p2Obj.id
: p1Obj.id;
? p2Obj.id
: p1Obj.id;
const result = {
action: "game_ended",
@@ -237,7 +234,7 @@ class BiscaGame {
player2_points: p2Obj.points,
totalTime: totalTime,
};
if (this.onGameEnd) {
this.onGameEnd(result);
}
+2 -14
View File
@@ -12,7 +12,7 @@ export const server = {
const API_URL = "http://localhost:8000/api/v1";
const disconnectTimers = new Map();
const RECONNECT_GRACE_PERIOD = 1 * 60 * 1000; // 1 minutes
const RECONNECT_GRACE_PERIOD = 1 * 60 * 1000;
const userId = (socket) => socket.user && socket.user.id;
@@ -86,7 +86,6 @@ export const serverStart = (port) => {
});
socket.on("disconnect", () => {
// Remove from active socket list
removeUser(socket.id);
if (socket.isVoluntaryDisconnect) {
@@ -94,24 +93,15 @@ export const serverStart = (port) => {
return;
}
if (userId) {
if (userId) {
console.log(`[Disconnect] User ${userId} disconnected. Waiting ${RECONNECT_GRACE_PERIOD / 1000}s...`);
// -----------------------------------------------------------
// 2. START SURRENDER TIMER
// -----------------------------------------------------------
const timer = setTimeout(async () => {
console.log(`[Timeout] User ${userId} did not return. Forcing surrender.`);
// A. Find the Game ID this user is playing (You need a way to look this up)
// Ideally, your 'socket' object or a global map knows which gameID the user is in.
// For this example, let's assume you stored `socket.activeGameId` when they joined.
const gameId = socket.activeGameId;
if (gameId) {
try {
// B. Call Laravel API to resign on their behalf
// We use the token we saved during the handshake
await axios.post(`${API_URL}/games/${gameId}/resign`, {}, {
headers: {
Authorization: socket.handshake.auth.token,
@@ -119,8 +109,6 @@ export const serverStart = (port) => {
}
});
// C. Notify the room (The API likely triggers a Pusher/Socket event,
// but we can also emit locally if needed)
server.io.to(gameId).emit("game_over", {
winner: "opponent",
reason: "disconnect"