Fix direct payment game start, reduce prod logging, QR improvements

- Fix game start failure in direct payment mode when payment confirms
  before mempool detection (add player to queue if not already there)
- Fix debug logging in production: correct indentation in debugRegisteredUsers,
  swap console_logging config (false in prod, true in debug)
- Add close button to QR code container
- Auto-hide QR on payment detected, confirmed, and game start
This commit is contained in:
jwinterm
2026-01-13 16:04:50 -05:00
parent a91aed84a5
commit 9330b3b943
4 changed files with 63 additions and 13 deletions
+22 -2
View File
@@ -370,6 +370,9 @@ const SocketHandlers = {
SocketHandlers._isQueued = false;
SocketHandlers._updateEarlyEntryButton();
// Hide any lingering QR code
SocketHandlers.hidePaymentQR();
$('#messages').append($('<li class="game-start">').text("Starting game..."));
// Display provably fair commitment if present
@@ -683,12 +686,14 @@ const SocketHandlers = {
if (statusDiv) {
qrHolder = document.createElement('div');
qrHolder.id = 'paymentQRContainer';
qrHolder.style.cssText = 'margin-top:6px;padding:8px;border:1px solid #0f0;background:#000;display:block;width:calc(100% - 18px);text-align:center;';
qrHolder.style.cssText = 'position:relative;margin-top:6px;padding:8px;border:1px solid #0f0;background:#000;display:block;width:calc(100% - 18px);text-align:center;';
statusDiv.appendChild(qrHolder);
}
}
if (qrHolder) {
qrHolder.innerHTML = '<img style="image-rendering:pixelated;width:100%;height:auto;display:block;margin:0 auto;max-width:320px;" src="' + data.qr + '" alt="Payment QR" />';
// Create close button
const closeBtn = '<div onclick="SocketHandlers.hidePaymentQR()" style="position:absolute;top:4px;right:8px;cursor:pointer;font-size:16px;color:#0f0;font-weight:bold;z-index:10;" title="Close QR code">✕</div>';
qrHolder.innerHTML = closeBtn + '<img style="image-rendering:pixelated;width:100%;height:auto;display:block;margin:0 auto;max-width:320px;" src="' + data.qr + '" alt="Payment QR" />';
}
} else {
console.warn('Payment created but no QR data supplied by server.');
@@ -707,6 +712,14 @@ const SocketHandlers = {
}
}
},
// Helper to hide/remove the payment QR code container
hidePaymentQR: function() {
const qrHolder = document.getElementById('paymentQRContainer');
if (qrHolder) {
qrHolder.remove();
}
},
onShowPaymentOptions: function(data) {
console.log('Show payment options:', data);
@@ -727,6 +740,9 @@ const SocketHandlers = {
SocketHandlers._lastDisplayedConfirmation = data.paymentId;
SocketHandlers._confirmationTimestamps[data.paymentId] = Date.now();
// Hide the QR code now that payment is confirmed
SocketHandlers.hidePaymentQR();
if (typeof Game !== 'undefined' && Game.drawWaitingScreen) {
Game.drawWaitingScreen();
}
@@ -751,6 +767,10 @@ const SocketHandlers = {
if (SocketHandlers._mempoolShownForPayment.has(data.paymentId)) return;
SocketHandlers._mempoolShownForPayment.add(data.paymentId);
SocketHandlers._mempoolTimestamps[data.paymentId] = Date.now();
// Hide the QR code now that payment was detected
SocketHandlers.hidePaymentQR();
if (typeof Game !== 'undefined') {
Game._pendingPaymentDetected(data);
if (Game.drawWaitingScreen) Game.drawWaitingScreen();
+4 -4
View File
@@ -913,10 +913,10 @@ function debugRegisteredUsers() {
console.log("📊 REGISTERED USERS DEBUG:");
const allUsers = require('./db/user').getAllUsers();
console.log(`Total registered users: ${allUsers.length}`);
allUsers.forEach(u => {
// u.id is the socket/server id; there is no separate socketId property on User
console.log(` - User ID: ${u.id}, Socket: ${u.id}, Client: ${u.clientId}`);
});
allUsers.forEach(u => {
// u.id is the socket/server id; there is no separate socketId property on User
console.log(` - User ID: ${u.id}, Socket: ${u.id}, Client: ${u.clientId}`);
});
console.log(`Active games: ${activeGames.size}`);
}
}
+33 -3
View File
@@ -310,14 +310,44 @@ class PaymentHandlers {
}
socket.emit('payment_confirmed', { paymentId: paymentRequest.id, message: 'Payment confirmed in block!', confirmations: status.confirmations });
this.queueManager.markConfirmed(socket.id);
// IMPORTANT: If payment confirmed before mempool detection (fast blocks),
// the player may not be in the queue yet. Add them now with confirmed=true.
const existingIdx = this.queueManager.getPlayerIndex(socket.id);
if (existingIdx === -1) {
console.log(`[PaymentHandlers] Payment confirmed but player not in queue - adding now (socket: ${socket.id})`);
// Try to get DB userId from session
let userId = null;
if (this.sessionManager?.sessions?.has(socket.id)) {
userId = this.sessionManager.sessions.get(socket.id).id;
}
this.queueManager.addPlayer({
serverId: socket.id,
clientId: currentUser ? currentUser.clientId : null,
userId: userId,
paymentId: paymentRequest.id,
requiresConfirmation: false, // Already confirmed
confirmed: true
});
} else {
// Player was in queue from mempool detection, just mark confirmed
this.queueManager.markConfirmed(socket.id);
}
// Attempt immediate game start so user doesn't wait another full block
const currentBlock = this.debugManager.getCurrentBlockHeight ? this.debugManager.getCurrentBlockHeight() : null;
if (currentBlock !== null) {
const started = await this.queueManager.startGameImmediately(socket.id, currentBlock);
if (!started && this.debugManager.CONSOLE_LOGGING) {
console.log(`[PaymentHandlers] Immediate start skipped (not queued or still unconfirmed) for ${socket.id}`);
if (!started) {
console.log(`[PaymentHandlers] Immediate start failed for ${socket.id} - player will start on next block`);
if (this.debugManager.CONSOLE_LOGGING) {
this.queueManager.debugDumpQueue();
}
} else {
console.log(`[PaymentHandlers] ✅ Immediate game start successful for ${socket.id}`);
}
} else {
console.log(`[PaymentHandlers] No block height available - player will start on next block`);
}
}
}
+4 -4
View File
@@ -14,14 +14,14 @@
},
"config": {
"debug": {
"enabled": false,
"console_logging": false,
"debug_hotkeys": false,
"enabled": true,
"console_logging": true,
"debug_hotkeys": true,
"simulated_blocks": false
},
"production": {
"enabled": true,
"console_logging": true,
"console_logging": false,
"debug_hotkeys": false,
"simulated_blocks": false
}