more temporary hardcoding address

This commit is contained in:
Robert MacRae 2026-01-24 21:39:40 -04:00
parent 4896f59a6e
commit a166f27d23
2 changed files with 88 additions and 33 deletions

View File

@ -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) {

View File

@ -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();
// 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'
}
});
// Show error message to user
this.showLoginNotice(`Failed to connect to server: ${response.status}`, 'error');
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);
}
}