add db commands and test payout (worked!)

This commit is contained in:
jwinterm
2025-11-23 13:33:04 -05:00
parent fa61d60bc0
commit deca4a4685
20 changed files with 403 additions and 1277 deletions
Binary file not shown.
+26 -18
View File
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<title>Wowgue - A Wownero Roguelike</title>
<title>Wownerogue - A Wownero Roguelike</title>
<link rel="stylesheet" type="text/css" href="styles/stylesheet.css">
<link rel="icon" type="image/x-icon" href="favicon.ico">
@@ -13,7 +13,7 @@
(function(){
let opts = {};
try {
const existing = localStorage.getItem('wowngeon_token');
const existing = localStorage.getItem('wownerogue_token');
if (existing) {
opts.query = { resumeToken: existing };
}
@@ -38,6 +38,7 @@
<!-- Other modules -->
<script src="js/ui/ui.js"></script>
<script src="js/ui/paymentUI.js"></script>
<script src="js/ui/audioAlerts.js"></script>
<script src="js/ui/addressModal.js"></script>
<script src="js/network/socketHandlers.js"></script>
@@ -59,6 +60,9 @@
<button id="startButton" style="background: #0a5c0a; color: #ff0; border: 2px solid #0f0; padding: 8px 16px; font-weight: bold; cursor: pointer; margin-top: 5px; display: none;">
🎮 START GAME
</button>
<button id="shopButton" style="background: #004400; color: #0f0; border: 2px solid #0f0; padding: 8px 16px; font-weight: bold; cursor: pointer; margin-top: 5px; margin-left: 10px; display: none;">
🛒 SHOP
</button>
<button id="animationToggleButton" style="background: #5c5c0a; color: #ff0; border: 2px solid #aa0; padding: 6px 12px; font-weight: bold; cursor: pointer; margin-top: 5px; margin-left: 10px; display: none;">
🎬 DISABLE ANIMATION
</button>
@@ -71,21 +75,21 @@
</div>
<!-- Payment System UI -->
<div id="payment-ui" class="payment-section" style="display: none; background: rgba(0,50,0,0.9); border: 2px solid #0f0; padding: 10px; margin: 5px; color: #0f0;">
<div id="payment-ui" class="payment-section" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2000; background: rgba(0,20,0,0.95); border: 2px solid #0f0; padding: 20px; color: #0f0; min-width: 400px; box-shadow: 0 0 20px rgba(0,255,0,0.2);">
<div class="payment-header">
<strong>🎮 Game Mode Selection</strong>
<button id="close-payment" style="float: right; background: #500; color: #f00; border: 1px solid #f00; padding: 2px 6px;">✕</button>
<button id="close-payment" style="float: right; background: #500; color: #f00; border: 1px solid #f00; padding: 2px 6px; cursor: pointer;">✕</button>
</div>
<div class="game-modes" style="margin: 10px 0;">
<div class="mode-option" data-mode="FREE" style="padding: 8px; margin: 5px 0; border: 1px solid #555; cursor: pointer;">
<div class="game-modes" style="margin: 15px 0;">
<div class="mode-option" data-mode="FREE" style="padding: 10px; margin: 5px 0; border: 1px solid #555; cursor: pointer; background: rgba(0,0,0,0.5);">
<strong>🆓 FREE PLAY</strong> - No cost, no rewards
</div>
<div class="mode-option" data-mode="PAID_SINGLE" style="padding: 8px; margin: 5px 0; border: 1px solid #555; cursor: pointer;">
<strong>💰 PAID SINGLE</strong> - 0.005 XMR per game, 2x payout for escape, 3x with treasure
<div class="mode-option" data-mode="PAID_SINGLE" style="padding: 10px; margin: 5px 0; border: 1px solid #555; cursor: pointer; background: rgba(0,0,0,0.5);">
<strong>💰 PAID SINGLE</strong> - 0.005 WOW per game, 2x payout for escape, 3x with treasure
</div>
<div class="mode-option" data-mode="PAID_CREDITS" style="padding: 8px; margin: 5px 0; border: 1px solid #555; cursor: pointer;">
<strong>🎫 CREDITS PACKAGE</strong> - 0.03 XMR for 10 games, no payouts
<div class="mode-option" data-mode="PAID_CREDITS" style="padding: 10px; margin: 5px 0; border: 1px solid #555; cursor: pointer; background: rgba(0,0,0,0.5);">
<strong>🎫 CREDITS PACKAGE</strong> - 0.03 WOW for 10 games, no payouts
</div>
</div>
@@ -93,15 +97,19 @@
<strong>Credits remaining: <span id="credits-count">0</span></strong>
</div>
<div id="payment-details" style="display: none; margin: 10px 0;">
<div><strong>Payment Required:</strong></div>
<div>Amount: <span id="payment-amount">0</span> XMR</div>
<div>Address: <input id="payment-address" type="text" readonly style="width: 100%; background: #000; color: #0f0; border: 1px solid #0f0; padding: 5px;"></div>
<div style="margin: 10px 0;">
<button id="copy-address" style="background: #050; color: #0f0; border: 1px solid #0f0; padding: 5px 10px;">📋 Copy Address</button>
<button id="check-payment" style="background: #005; color: #0f0; border: 1px solid #0f0; padding: 5px 10px;">🔄 Check Payment</button>
<div id="payment-details" style="display: none; margin: 15px 0;">
<div style="margin-bottom: 5px;"><strong>Payment Required:</strong></div>
<div style="font-size: 1.2em; margin-bottom: 10px;">Amount: <span id="payment-amount" style="color: #ff0;">0</span></div>
<div style="margin-bottom: 5px;">Address:</div>
<input id="payment-address" type="text" readonly style="width: 100%; background: #000; color: #0f0; border: 1px solid #0f0; padding: 8px; font-family: monospace; margin-bottom: 10px;">
<div style="margin: 10px 0; display: flex; gap: 10px;">
<button id="copy-address" style="flex: 1; background: #050; color: #0f0; border: 1px solid #0f0; padding: 8px; cursor: pointer;">📋 Copy Address</button>
<button id="check-payment" style="flex: 1; background: #005; color: #0f0; border: 1px solid #0f0; padding: 8px; cursor: pointer;">🔄 Check Payment</button>
</div>
<div id="payment-status" style="margin: 10px 0; font-weight: bold; text-align: center;"></div>
<div style="font-size: 0.8em; color: #aaa; text-align: center; margin-top: 15px; border-top: 1px solid #333; padding-top: 10px;">
ℹ️ You can close this window. The payment information is also available in the sidebar/chat area.
</div>
<div id="payment-status" style="margin: 10px 0; font-weight: bold;"></div>
</div>
</div>
+40 -4
View File
@@ -1,5 +1,5 @@
/**
* Socket event handlers for the Wowngeon game
* Socket event handlers for the Wownerogue game
*/
const SocketHandlers = {
_initialized: false,
@@ -53,6 +53,7 @@ const SocketHandlers = {
socket.on('address_confirmed', this.onAddressConfirmed);
socket.on('address_update_error', this.onAddressUpdateError);
socket.on('address_prompt', this.onAddressPrompt);
socket.on('game_mode_info', this.onGameModeInfo);
socket.on('payment_created', this.onPaymentCreated);
socket.on('payment_confirmed', this.onPaymentConfirmed);
socket.on('payment_detected', this.onPaymentDetected);
@@ -67,7 +68,7 @@ const SocketHandlers = {
SocketHandlers._didConnect = true;
// Include stored session token in a lightweight resume emit (if server did not get it via handshake)
try {
const existing = localStorage.getItem('wowngeon_token');
const existing = localStorage.getItem('wownerogue_token');
if (existing) {
// If we later decide to rely solely on query param at io() creation, this is harmless redundancy.
socket.io.opts.query = socket.io.opts.query || {};
@@ -84,7 +85,7 @@ const SocketHandlers = {
onSessionToken: function(data) {
if (data && data.token) {
try { localStorage.setItem('wowngeon_token', data.token); } catch(e) {}
try { localStorage.setItem('wownerogue_token', data.token); } catch(e) {}
$('#messages').append($('<li class="status">').text('New session established. Token stored.'));
UI.scrollChat();
}
@@ -92,7 +93,7 @@ const SocketHandlers = {
onSessionResumed: function(data) {
if (data && data.token) {
try { localStorage.setItem('wowngeon_token', data.token); } catch(e) {}
try { localStorage.setItem('wownerogue_token', data.token); } catch(e) {}
$('#messages').append($('<li class="status">').text('Session resumed.'));
UI.scrollChat();
}
@@ -301,6 +302,18 @@ const SocketHandlers = {
onAddressConfirmed: function(data) {
console.log('Address confirmed:', data);
// Cleanup previous address-related messages to reduce clutter
$('#messages li').each(function() {
const text = $(this).text();
if (text.includes('Paste your payout address') ||
text.includes('Detected payout address') ||
text.includes('Type \'confirm\' to save') ||
text.includes('Address detected. Type confirm')) {
$(this).remove();
}
});
$('#messages').append($('<li class="address-confirmed" style="color: #0f0; white-space: pre-line;">').text(data.message));
UI.scrollChat();
if (typeof AddressModal !== 'undefined') {
@@ -323,9 +336,32 @@ const SocketHandlers = {
}
},
onGameModeInfo: function(data) {
console.log('Game mode info received:', data);
if (typeof UI !== 'undefined' && UI.updateGameTitle) {
UI.updateGameTitle(data.cryptoType);
}
if (typeof PaymentUI !== 'undefined') {
PaymentUI.updateConfig(data);
// Show shop button if payments enabled
if (data.paymentsEnabled) {
$('#shopButton').show();
} else {
$('#shopButton').hide();
}
}
},
onPaymentCreated: function(data) {
console.log('Payment created:', data);
if (typeof AudioAlerts !== 'undefined') { AudioAlerts.playRequestCoin(); }
if (typeof PaymentUI !== 'undefined') {
PaymentUI.showPaymentRequest(data);
}
const parts = [];
const reusedCopy = data.reused
? '🔁 <strong>Pending payment request still active.</strong> Use the same amount and address below.'
+165
View File
@@ -0,0 +1,165 @@
/**
* Payment UI Manager
* Handles the game mode selection and payment modal interactions
*/
const PaymentUI = {
config: null,
init: function() {
console.log("Initializing PaymentUI...");
// Bind close button
$('#close-payment').on('click', function() {
$('#payment-ui').hide();
});
// Bind mode options
$('.mode-option').on('click', function() {
const mode = $(this).data('mode');
PaymentUI.handleModeSelection(mode);
});
// Bind check payment button
$('#check-payment').on('click', function() {
const paymentId = $(this).data('payment-id');
if (paymentId && window.socket) {
window.socket.emit('check_payment_status', { paymentId });
$(this).text('Checking...');
setTimeout(() => $('#check-payment').text('🔄 Check Payment'), 1000);
}
});
// Bind copy button
$('#copy-address').on('click', function() {
const addr = $('#payment-address').val();
if(addr) {
// Try modern clipboard API first
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(addr).then(() => {
$('#copy-address').text('Copied!');
setTimeout(() => $('#copy-address').html('📋 Copy Address'), 2000);
});
} else {
// Fallback
const $temp = $("<input>");
$("body").append($temp);
$temp.val(addr).select();
document.execCommand("copy");
$temp.remove();
$('#copy-address').text('Copied!');
setTimeout(() => $('#copy-address').html('📋 Copy Address'), 2000);
}
}
});
// Bind Shop Button (will be added to index.html)
$('#shopButton').on('click', function() {
PaymentUI.show();
});
},
updateConfig: function(config) {
console.log("PaymentUI config updated:", config);
this.config = config;
this.render();
},
render: function() {
if (!this.config) return;
const currency = this.config.cryptoType || 'WOW';
const decimals = currency === 'XMR' ? 12 : 11;
const divisor = Math.pow(10, decimals);
// Update PAID_SINGLE
if (this.config.directModeEnabled) {
const price = (this.config.singleGamePrice / divisor).toFixed(decimals === 12 ? 4 : 2);
const $el = $('.mode-option[data-mode="PAID_SINGLE"]');
$el.html(`<strong>💰 PAID SINGLE</strong> - ${price} ${currency} per game<br><span style="font-size:0.8em;color:#aaa;">Payouts enabled for winners</span>`);
$el.show();
} else {
$('.mode-option[data-mode="PAID_SINGLE"]').hide();
}
// Update PAID_CREDITS
if (this.config.creditsModeEnabled) {
// Note: config.creditsPackagePrice is for the default package
const price = (this.config.creditsPackagePrice / divisor).toFixed(decimals === 12 ? 4 : 2);
// We assume the default package size is 10 if not specified, but let's be vague if unsure
// Ideally we'd get package info. For now, "Credits Package" is safe.
const $el = $('.mode-option[data-mode="PAID_CREDITS"]');
$el.html(`<strong>🎫 CREDITS PACKAGE</strong> - ${price} ${currency}<br><span style="font-size:0.8em;color:#aaa;">Bulk discount, no payouts</span>`);
$el.show();
} else {
$('.mode-option[data-mode="PAID_CREDITS"]').hide();
}
// Update FREE
if (!this.config.paymentsEnabled) {
$('.mode-option[data-mode="FREE"]').show();
// If payments are disabled, maybe hide the others?
// The logic above handles hiding if enabled flags are false.
} else {
// If payments are enabled, FREE is usually disabled/hidden
$('.mode-option[data-mode="FREE"]').hide();
}
},
handleModeSelection: function(mode) {
console.log("Mode selected:", mode);
if (mode === 'FREE') {
$('#payment-ui').hide();
return;
}
let paymentType = 'single_game';
if (mode === 'PAID_CREDITS') {
paymentType = 'credits_package';
}
if (window.socket) {
window.socket.emit('request_payment', { type: paymentType });
// Show loading state
$('.game-modes').hide();
$('#payment-details').show();
$('#payment-status').text('Requesting payment address...');
$('#payment-amount').text('...');
$('#payment-address').val('Loading...');
}
},
showPaymentRequest: function(data) {
$('#payment-ui').show();
$('#payment-details').show();
$('.game-modes').hide(); // Hide selection, show payment
$('.payment-header strong').text('💳 Payment Required');
const displayAmount = data.humanAmount || data.amountFormatted || data.amount;
$('#payment-amount').text(displayAmount + ' ' + (data.currency || ''));
$('#payment-address').val(data.address);
$('#check-payment').data('payment-id', data.id);
if (data.reused) {
$('#payment-status').html('<span style="color:#ff0">♻️ Using existing pending payment</span>');
} else {
$('#payment-status').text('Waiting for payment...');
}
},
show: function() {
$('#payment-ui').show();
$('.game-modes').show();
$('#payment-details').hide();
$('.payment-header strong').text('🎮 Game Mode Selection');
}
};
// Expose globally
window.PaymentUI = PaymentUI;
// Initialize when DOM is ready
$(document).ready(function() {
PaymentUI.init();
});
+20 -2
View File
@@ -33,7 +33,7 @@ const UI = {
// Initialize teletype animation
initTeletype: function() {
$('#banner').teletype({
text: ["Welcome traveler...", "You have arrived at...", "The Wowngeon"],
text: ["Welcome traveler...", "You have arrived at...", "The Dungeon"],
typeDelay: 100,
backDelay: 50,
pause: 1500
@@ -42,11 +42,29 @@ const UI = {
// After animations are complete, set static text
setTimeout(function() {
$('#banner, #bannercursor').fadeOut(500, function() {
$('#staticbanner').text("WOWGUE - A Wownero Roguelike").fadeIn(500);
const title = UI._gameTitleFull || "WOWNEROGUE - A Wownero Roguelike";
$('#staticbanner').text(title).fadeIn(500);
});
}, 14000);
},
_gameTitleFull: "WOWNEROGUE - A Wownero Roguelike",
updateGameTitle: function(cryptoType) {
if (cryptoType === 'XMR') {
document.title = "XMROGUE - A Monero Roguelike";
this._gameTitleFull = "XMROGUE - A Monero Roguelike";
} else {
document.title = "Wownerogue - A Wownero Roguelike";
this._gameTitleFull = "WOWNEROGUE - A Wownero Roguelike";
}
// If the static banner is already visible (animation finished), update it immediately
if ($('#staticbanner').is(':visible') && !$('#banner').is(':visible')) {
$('#staticbanner').text(this._gameTitleFull);
}
},
// Initialize browser detection
initBrowserDetection: function() {
setTimeout(function() {