fix payout calcs

This commit is contained in:
jwinterm
2025-12-24 20:03:26 -05:00
parent 0ff95d3142
commit 2c781ec043
4 changed files with 49 additions and 3 deletions
+24
View File
@@ -94,6 +94,7 @@ const SocketHandlers = {
socket.on('payment_detected', this.onPaymentDetected);
socket.on('show_payment_options', this.onShowPaymentOptions);
socket.on('credits_update', this.onCreditsUpdate);
socket.on('user_count', this.onUserCount);
// Block height handler
socket.on('blockheight', this.onBlockHeight);
@@ -704,6 +705,29 @@ const SocketHandlers = {
}
},
onUserCount: function(data) {
if (!data || typeof data.count !== 'number') return;
SocketHandlers._updateUserCountDisplay(data.count);
},
_updateUserCountDisplay: function(count) {
let el = document.getElementById('userCountDisplay');
if (!el) {
// Create display element next to connection status
const statusDiv = document.querySelector('.status') || document.getElementById('connectionStatus')?.parentElement;
if (statusDiv) {
el = document.createElement('div');
el.id = 'userCountDisplay';
el.style.cssText = 'font-size:12px;color:#0af;margin-top:2px;';
statusDiv.appendChild(el);
}
}
if (el) {
const plural = count === 1 ? '' : 's';
el.innerHTML = `👥 <span style="color:#4ade80;">${count}</span> player${plural} online`;
}
},
// ====== SPECTATOR HANDLERS ======
_spectatorMode: false,
+6 -3
View File
@@ -73,8 +73,8 @@ class GameModeManager {
this.singleGamePrice = parseAtomicEnvValue(process.env.SINGLE_GAME_PRICE, this.singleGamePrice);
this.creditsPackagePrice = parseAtomicEnvValue(process.env.CREDITS_PACKAGE_PRICE, this.creditsPackagePrice);
this.creditsPerGameCost = parseAtomicEnvValue(process.env.CREDITS_PER_GAME, 1) || 1;
this.creditsPayoutEnabled = /^true$/i.test(process.env.CREDITS_PAYOUT_ENABLED || 'false');
this.creditsPayoutBaseValue = this.singleGamePrice;
this.creditsPayoutEnabled = /^true$/i.test(process.env.CREDITS_PAYOUTS_ENABLED || process.env.CREDITS_PAYOUT_ENABLED || 'false');
this.creditsPayoutBaseValue = parseAtomicEnvValue(process.env.CREDITS_PAYOUT_BASE, this.singleGamePrice);
process.env.CREDITS_PER_GAME = String(this.creditsPerGameCost);
const directEscape = Number(process.env.DIRECT_PAYOUT_ESCAPE);
@@ -370,7 +370,7 @@ class GameModeManager {
console.log(`🧮 Payout multipliers - direct: ${JSON.stringify(this.directPayoutMultipliers)}, credits: ${JSON.stringify(this.creditPayoutMultipliers)}`);
console.log(`🔁 Mode availability - direct: ${this.directModeEnabled}, credits: ${this.creditsModeEnabled}, preferCreditsFirst: ${this.preferCreditsFirst}`);
if (this.creditsPayoutEnabled) {
console.log('🎁 Credits payout mode ENABLED (will pay rewards in PAID_CREDITS).');
console.log(`🎁 Credits payout mode ENABLED - base value: ${this.creditsPayoutBaseValue} atomic (~${this.formatAtomic(this.creditsPayoutBaseValue)} ${this.cryptoType})`);
}
console.log(`⚙️ Payments enabled: ${this.paymentsEnabled}`);
}
@@ -1011,6 +1011,9 @@ class GameModeManager {
* Get game mode info for frontend
*/
getGameModeInfo() {
// Debug: Log credits payout base value being sent
console.log(`📤 getGameModeInfo: creditsPayoutBaseValue = ${this.creditsPayoutBaseValue} (${this.formatAtomic(this.creditsPayoutBaseValue)} ${this.cryptoType})`);
// Determine if we should show a testnet warning
// Only for XMR on stagenet/testnet - WOW only has mainnet
const showTestnetWarning = this.cryptoType === 'XMR' && this.isTestNetwork;
+13
View File
@@ -8,10 +8,23 @@ class BroadcastManager {
constructor(io) {
this.io = io;
this._lastBroadcastBlock = null;
this._lastUserCount = -1;
}
// ====== GLOBAL BROADCASTS (All Clients) ======
/**
* Broadcast connected user count to all clients
*/
broadcastUserCount() {
const count = this.io.engine ? this.io.engine.clientsCount : 0;
// Only broadcast if count changed to avoid spam
if (count !== this._lastUserCount) {
this._lastUserCount = count;
this.io.emit('user_count', { count });
}
}
/**
* Broadcast block height to all connected clients
* @param {number} blockHeight - Current block height
+6
View File
@@ -64,6 +64,9 @@ class ConnectionHandler {
// Send current state
this._sendConnectionStatus(socket);
// Broadcast updated user count to all clients
this.broadcastManager.broadcastUserCount();
return { sessionInfo, memUser };
} catch (error) {
@@ -112,6 +115,9 @@ class ConnectionHandler {
// Clean up user records
user.removeUser(socket.client.id);
// Broadcast updated user count to all clients
this.broadcastManager.broadcastUserCount();
// Call additional cleanup if provided
if (additionalCleanup && typeof additionalCleanup === 'function') {
additionalCleanup(socket);