From a166f27d23320e7ab57ee56bc2e32faea69c3a94 Mon Sep 17 00:00:00 2001 From: Robert MacRae Date: Sat, 24 Jan 2026 21:39:40 -0400 Subject: [PATCH] more temporary hardcoding address --- Client/js/GameInitializer.js | 2 +- Client/js/ui/LiveMainMenu.js | 119 +++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 33 deletions(-) diff --git a/Client/js/GameInitializer.js b/Client/js/GameInitializer.js index dbdec32..2e88c07 100644 --- a/Client/js/GameInitializer.js +++ b/Client/js/GameInitializer.js @@ -14,7 +14,7 @@ class GameInitializer { this.currentUser = null; this.socket = null; this.apiBaseUrl = 'https://api.korvarix.com/api'; // API Server - this.gameServerUrl = 'https://api.korvarix.com'; // Game Server for Socket.IO + this.gameServerUrl = 'https://dev.gameserver.galaxystrike.online'; // Game Server for Socket.IO (local dev server) } updateServerUrls(apiUrl, gameUrl) { diff --git a/Client/js/ui/LiveMainMenu.js b/Client/js/ui/LiveMainMenu.js index 71bfb34..4ffcb3f 100644 --- a/Client/js/ui/LiveMainMenu.js +++ b/Client/js/ui/LiveMainMenu.js @@ -24,7 +24,8 @@ class LiveMainMenu { this.currentUser = null; this.servers = []; // Renamed from serverList to avoid conflict with DOM element this.apiBaseUrl = 'https://api.korvarix.com/api'; // API Server URL - this.gameServerUrl = 'https://api.korvarix.com'; // Game Server URL for Socket.IO + this.gameServerUrl = 'https://dev.gameserver.galaxystrike.online'; // Game Server URL for Socket.IO (local dev server) + this.localGameServerUrl = 'http://localhost:3002'; // Local Game Server URL this.isLocalMode = false; // Track if we're in local mode console.log('[LIVE MAIN MENU] Initializing elements'); @@ -446,43 +447,69 @@ class LiveMainMenu { try { let response; - // Use SimpleLocalServer mock API if in local mode + // Build server list with local server, dev server, and API servers + const servers = []; + + // Add local server if available if (this.isLocalMode && window.localServerManager && window.localServerManager.localServer && window.localServerManager.localServer.mockRequest) { - console.log('[LIVE MAIN MENU] Using SimpleLocalServer mock API for server list'); - response = await window.localServerManager.localServer.mockRequest('GET', '/api/servers'); - } else { - console.log('[LIVE MAIN MENU] Fetching server list from:', `${this.apiBaseUrl}/servers`); - response = await fetch(`${this.apiBaseUrl}/servers`, { - method: 'GET', - headers: { - 'Authorization': `Bearer ${this.authToken}`, - 'Content-Type': 'application/json' - } - }); + console.log('[LIVE MAIN MENU] Using SimpleLocalServer mock API for local server'); + const localResponse = await window.localServerManager.localServer.mockRequest('GET', '/api/servers'); + if (localResponse.success && localResponse.servers) { + servers.push(...localResponse.servers); + } } - console.log('[LIVE MAIN MENU] Server list response status:', response.status); - - // Check if response is HTML (error page) instead of JSON - const contentType = response.headers ? response.headers.get('content-type') : 'application/json'; - if (!contentType || !contentType.includes('application/json')) { - throw new Error('API server is not available. Please check your connection.'); + // Add dev game server + try { + const devServerResponse = await fetch('http://localhost:3002/health'); + if (devServerResponse.ok) { + const devServerInfo = await devServerResponse.json(); + servers.push({ + id: 'dev-game-server', + name: 'Dev Game Server', + description: 'Development game server for testing', + type: 'development', + region: 'local', + maxPlayers: 8, + currentPlayers: 0, + owner: 'Developer', + address: 'localhost', + port: 3002, + status: 'online', + createdAt: new Date().toISOString(), + ping: 0, + isLocal: true, + isDev: true + }); + } + } catch (error) { + console.log('[LIVE MAIN MENU] Dev game server not available:', error.message); } - if (response.ok) { - const data = await response.json(); - this.servers = data.servers || []; - console.log('[LIVE MAIN MENU] Server list loaded:', this.servers); - this.renderServerList(); - } else { - const errorText = await response.text(); - console.error('[LIVE MAIN MENU] Failed to load server list - Status:', response.status, 'Error:', errorText); - this.servers = []; - this.renderServerList(); - - // Show error message to user - this.showLoginNotice(`Failed to connect to server: ${response.status}`, 'error'); + // Add API servers + console.log('[LIVE MAIN MENU] Fetching server list from:', `${this.apiBaseUrl}/servers`); + const apiResponse = await fetch(`${this.apiBaseUrl}/servers`, { + method: 'GET', + headers: { + 'Authorization': `Bearer ${this.authToken}`, + 'Content-Type': 'application/json' + } + }); + + if (apiResponse.ok) { + const apiData = await apiResponse.json(); + if (apiData.success && apiData.servers) { + servers.push(...apiData.servers); + } } + + this.servers = servers; + + console.log('[LIVE MAIN MENU] Server list loaded:', servers.length, 'servers found'); + + // Display servers + this.renderServerList(); + } catch (error) { console.error('[LIVE MAIN MENU] Server list error:', error); this.servers = []; @@ -1229,6 +1256,20 @@ Status: ${this.selectedServer.status} // Now initialize multiplayer mode through GameInitializer if (window.gameInitializer) { + // Determine the correct game server URL based on server type + let gameServerUrl = this.gameServerUrl; // Default to dev server + + if (server.isLocal) { + gameServerUrl = this.localGameServerUrl; + } else if (server.isDev) { + gameServerUrl = this.gameServerUrl; + } else { + // Use server address and port for remote servers + gameServerUrl = `http://${server.address}:${server.port}`; + } + + console.log('[LIVE MAIN MENU] Using game server URL:', gameServerUrl); + window.gameInitializer.updateServerUrls(this.apiBaseUrl, gameServerUrl); window.gameInitializer.initializeMultiplayer(server, serverData, this.authToken, this.currentUser); } }).catch(error => { @@ -1244,6 +1285,20 @@ Status: ${this.selectedServer.status} // Initialize multiplayer mode through GameInitializer if (window.gameInitializer) { + // Determine the correct game server URL based on server type + let gameServerUrl = this.gameServerUrl; // Default to dev server + + if (server.isLocal) { + gameServerUrl = this.localGameServerUrl; + } else if (server.isDev) { + gameServerUrl = this.gameServerUrl; + } else { + // Use server address and port for remote servers + gameServerUrl = `http://${server.address}:${server.port}`; + } + + console.log('[LIVE MAIN MENU] Using game server URL:', gameServerUrl); + window.gameInitializer.updateServerUrls(this.apiBaseUrl, gameServerUrl); window.gameInitializer.initializeMultiplayer(server, serverData, this.authToken, this.currentUser); } }