mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-25 09:08:34 +01:00
add db commands and test payout (worked!)
This commit is contained in:
+2
-2
@@ -1,4 +1,4 @@
|
||||
# Wowngeon Server Configuration
|
||||
# Wownerogue Server Configuration
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Unified Payment System (recommended configuration)
|
||||
@@ -71,7 +71,7 @@ RPC_POLL_INTERVAL=2000
|
||||
# Database Configuration
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
DB_NAME=wowgue
|
||||
DB_NAME=wownerogue
|
||||
DB_USER=jw
|
||||
DB_PASSWORD=jw
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class DatabaseManager {
|
||||
this.pool = new Pool({
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
port: process.env.DB_PORT || 5432,
|
||||
database: process.env.DB_NAME || 'wowgue',
|
||||
database: process.env.DB_NAME || 'wownerogue',
|
||||
user: process.env.DB_USER || 'jw',
|
||||
password: process.env.DB_PASSWORD || 'jw',
|
||||
max: 20, // Maximum number of clients in the pool
|
||||
@@ -97,9 +97,6 @@ class DatabaseManager {
|
||||
this.connected = true;
|
||||
console.log('✅ Database connected successfully');
|
||||
|
||||
// Run migrations
|
||||
await this.runMigrations();
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('❌ Database connection failed:', error.message);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ const CONSOLE_LOGGING = process.env.NODE_ENV === 'debug' || process.env.NODE_ENV
|
||||
const client = new Client({
|
||||
user: 'postgres',
|
||||
host: 'localhost',
|
||||
database: 'bitdungeon',
|
||||
database: 'wownerogue',
|
||||
password: 'postgres',
|
||||
port: 5432,
|
||||
});
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ const path = require('path');
|
||||
var app = express();
|
||||
var http = require('http').Server(app);
|
||||
var io = require('socket.io')(http);
|
||||
var db = require('./db/dbcalls.js');
|
||||
|
||||
// Load environment configuration
|
||||
require('dotenv').config();
|
||||
@@ -210,7 +209,7 @@ async function startServer() {
|
||||
|
||||
// Start HTTP server
|
||||
http.listen(3000, function() {
|
||||
console.log('🚀 Wowngeon server listening on *:3000');
|
||||
console.log('🚀 Wownerogue server listening on *:3000');
|
||||
console.log(`🐛 Debug mode: ${debugManager.getDebugStatus().debugMode ? 'ENABLED' : 'DISABLED'}`);
|
||||
console.log(`💰 Payment system: ${paymentSystemReady ? 'ENABLED' : 'FREE MODE ONLY'}`);
|
||||
const summary = paymentConfigManager.summarize();
|
||||
|
||||
@@ -94,7 +94,7 @@ class AddressManager {
|
||||
if (this.gameModeManager) {
|
||||
try {
|
||||
await this.gameModeManager.setUserPayoutAddress(socketId, pending);
|
||||
this.broadcastManager?.sendStatusUpdate(socketId, 'success', 'Payout address saved.');
|
||||
// this.broadcastManager?.sendStatusUpdate(socketId, 'success', 'Payout address saved.'); // Removed duplicate
|
||||
this.io.to(socketId).emit('address_confirmed', { address: pending, message: 'Payout address saved.' });
|
||||
} catch (e) {
|
||||
const normalized = normalizeError?.(e, 'Failed to save address') || e;
|
||||
@@ -105,7 +105,7 @@ class AddressManager {
|
||||
}
|
||||
} else {
|
||||
this.pending.delete(socketId);
|
||||
this.broadcastManager?.sendStatusUpdate(socketId, 'success', 'Payout address accepted (session only).');
|
||||
// this.broadcastManager?.sendStatusUpdate(socketId, 'success', 'Payout address accepted (session only).'); // Removed duplicate
|
||||
this.io.to(socketId).emit('address_confirmed', { address: pending, message: 'Payout address accepted (session only).' });
|
||||
}
|
||||
if (this.onConfirmed) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Broadcast Manager Module
|
||||
* Handles all socket.io event broadcasting for the Wowngeon game server
|
||||
* Handles all socket.io event broadcasting for the Wownerogue game server
|
||||
* Supports current player-specific events and future spectator broadcasting
|
||||
*/
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ class ConnectionHandler {
|
||||
this.io.to(socket.id).emit('blockheight', { blockHeight: currentBlock });
|
||||
|
||||
// Send connection status
|
||||
this.broadcastManager.sendStatusUpdate(socket.id, 'connection', 'Connected to Wowngeon server');
|
||||
this.broadcastManager.sendStatusUpdate(socket.id, 'connection', 'Connected to Wownerogue server');
|
||||
}
|
||||
|
||||
_cleanupExistingMappings(socketId, clientId) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Socket Event Handlers Module
|
||||
* Handles all socket.io event processing for the Wowngeon game server
|
||||
* Handles all socket.io event processing for the Wownerogue game server
|
||||
*/
|
||||
|
||||
const user = require('../db/user');
|
||||
@@ -313,6 +313,11 @@ class SocketHandlers {
|
||||
const connectionResult = await this.connectionHandler.handleConnection(socket);
|
||||
if (!connectionResult) return; // Connection was rejected or failed
|
||||
|
||||
// Send game mode info to client
|
||||
if (this.gameModeManager) {
|
||||
socket.emit('game_mode_info', this.gameModeManager.getGameModeInfo());
|
||||
}
|
||||
|
||||
// Register event handlers
|
||||
socket.on('chat message', (msg) => this.chatHandler.handleChatMessage(socket, msg, {
|
||||
handleGameQueue: (socket) => this.queueHandler.handleGameQueue(socket, (socketId) => this.connectionHandler.getUserBySocket(socketId)),
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "bitrogue",
|
||||
"name": "wownerogue",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
@@ -7,7 +7,10 @@
|
||||
"start": "NODE_ENV=production node index.js",
|
||||
"dev": "NODE_ENV=development node index.js",
|
||||
"debug": "NODE_ENV=debug node index.js",
|
||||
"test": "jest --runInBand"
|
||||
"test": "jest --runInBand",
|
||||
"db:create": "node scripts/setup_db.js",
|
||||
"db:drop": "node scripts/setup_db.js drop",
|
||||
"db:reset": "npm run db:drop && npm run db:create"
|
||||
},
|
||||
"config": {
|
||||
"debug": {
|
||||
|
||||
@@ -51,7 +51,7 @@ class MoneroPayService {
|
||||
|
||||
const response = await axios.post(`${this.endpoint}/receive`, {
|
||||
amount: parseInt(amount),
|
||||
description: description || `Wowgue ${paymentType}`,
|
||||
description: description || `Wownerogue ${paymentType}`,
|
||||
callback_url: callbackUrl
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
require('dotenv').config({ path: '../.env' });
|
||||
const { Client } = require('pg');
|
||||
|
||||
const DB_CONFIG = {
|
||||
user: process.env.DB_USER || 'jw',
|
||||
password: process.env.DB_PASSWORD || 'jw',
|
||||
host: process.env.DB_HOST || 'localhost',
|
||||
port: process.env.DB_PORT || 5432,
|
||||
database: process.env.DB_NAME || 'wownerogue'
|
||||
};
|
||||
|
||||
// Admin config to create user/db
|
||||
const ADMIN_CONFIG = {
|
||||
user: process.env.DB_ADMIN_USER || 'postgres',
|
||||
password: process.env.DB_ADMIN_PASSWORD || 'postgres', // Try default
|
||||
host: DB_CONFIG.host,
|
||||
port: DB_CONFIG.port,
|
||||
database: 'postgres'
|
||||
};
|
||||
|
||||
async function setup() {
|
||||
console.log('🔧 Starting database setup...');
|
||||
|
||||
// Try to connect as admin
|
||||
const client = new Client(ADMIN_CONFIG);
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
console.log('✅ Connected as admin');
|
||||
} catch (err) {
|
||||
console.log('⚠️ Could not connect as admin (postgres/postgres). Trying with current user...');
|
||||
// Fallback: try connecting with current user to 'postgres' db
|
||||
client.end();
|
||||
const fallbackClient = new Client({
|
||||
...ADMIN_CONFIG,
|
||||
user: process.env.USER || 'postgres',
|
||||
password: '', // often passwordless for local socket
|
||||
});
|
||||
try {
|
||||
await fallbackClient.connect();
|
||||
console.log('✅ Connected as ' + (process.env.USER || 'postgres'));
|
||||
// Swap client
|
||||
Object.assign(client, fallbackClient);
|
||||
} catch (e) {
|
||||
console.error('❌ Could not connect to postgres instance. Please ensure PostgreSQL is running and you have rights to create databases.');
|
||||
console.error('Error:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Create User if not exists
|
||||
const userRes = await client.query(`SELECT 1 FROM pg_roles WHERE rolname=$1`, [DB_CONFIG.user]);
|
||||
if (userRes.rowCount === 0) {
|
||||
console.log(`👤 Creating user ${DB_CONFIG.user}...`);
|
||||
await client.query(`CREATE USER "${DB_CONFIG.user}" WITH PASSWORD '${DB_CONFIG.password}' CREATEDB`);
|
||||
} else {
|
||||
console.log(`👤 User ${DB_CONFIG.user} already exists`);
|
||||
}
|
||||
|
||||
// 2. Create Database if not exists
|
||||
const dbRes = await client.query(`SELECT 1 FROM pg_database WHERE datname=$1`, [DB_CONFIG.database]);
|
||||
if (dbRes.rowCount === 0) {
|
||||
console.log(`📦 Creating database ${DB_CONFIG.database}...`);
|
||||
await client.query(`CREATE DATABASE "${DB_CONFIG.database}" OWNER "${DB_CONFIG.user}"`);
|
||||
} else {
|
||||
console.log(`📦 Database ${DB_CONFIG.database} already exists`);
|
||||
}
|
||||
|
||||
console.log('✅ Setup complete!');
|
||||
} catch (err) {
|
||||
console.error('❌ Setup failed:', err.message);
|
||||
} finally {
|
||||
await client.end();
|
||||
}
|
||||
}
|
||||
|
||||
async function drop() {
|
||||
console.log('🔥 Dropping database...');
|
||||
const client = new Client(ADMIN_CONFIG);
|
||||
try {
|
||||
await client.connect();
|
||||
// Terminate connections first
|
||||
await client.query(`
|
||||
SELECT pg_terminate_backend(pid)
|
||||
FROM pg_stat_activity
|
||||
WHERE datname = $1
|
||||
`, [DB_CONFIG.database]);
|
||||
|
||||
await client.query(`DROP DATABASE IF EXISTS "${DB_CONFIG.database}"`);
|
||||
console.log(`✅ Database ${DB_CONFIG.database} dropped`);
|
||||
} catch (err) {
|
||||
console.error('❌ Drop failed:', err.message);
|
||||
} finally {
|
||||
await client.end();
|
||||
}
|
||||
}
|
||||
|
||||
const action = process.argv[2];
|
||||
if (action === 'drop') {
|
||||
drop();
|
||||
} else {
|
||||
setup();
|
||||
}
|
||||
Reference in New Issue
Block a user