more temporary hardcoding address
This commit is contained in:
parent
4896f59a6e
commit
a166f27d23
@ -14,7 +14,7 @@ class GameInitializer {
|
|||||||
this.currentUser = null;
|
this.currentUser = null;
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
this.apiBaseUrl = 'https://api.korvarix.com/api'; // API Server
|
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) {
|
updateServerUrls(apiUrl, gameUrl) {
|
||||||
|
|||||||
@ -24,7 +24,8 @@ class LiveMainMenu {
|
|||||||
this.currentUser = null;
|
this.currentUser = null;
|
||||||
this.servers = []; // Renamed from serverList to avoid conflict with DOM element
|
this.servers = []; // Renamed from serverList to avoid conflict with DOM element
|
||||||
this.apiBaseUrl = 'https://api.korvarix.com/api'; // API Server URL
|
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
|
this.isLocalMode = false; // Track if we're in local mode
|
||||||
|
|
||||||
console.log('[LIVE MAIN MENU] Initializing elements');
|
console.log('[LIVE MAIN MENU] Initializing elements');
|
||||||
@ -446,43 +447,69 @@ class LiveMainMenu {
|
|||||||
try {
|
try {
|
||||||
let response;
|
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) {
|
if (this.isLocalMode && window.localServerManager && window.localServerManager.localServer && window.localServerManager.localServer.mockRequest) {
|
||||||
console.log('[LIVE MAIN MENU] Using SimpleLocalServer mock API for server list');
|
console.log('[LIVE MAIN MENU] Using SimpleLocalServer mock API for local server');
|
||||||
response = await window.localServerManager.localServer.mockRequest('GET', '/api/servers');
|
const localResponse = await window.localServerManager.localServer.mockRequest('GET', '/api/servers');
|
||||||
} else {
|
if (localResponse.success && localResponse.servers) {
|
||||||
console.log('[LIVE MAIN MENU] Fetching server list from:', `${this.apiBaseUrl}/servers`);
|
servers.push(...localResponse.servers);
|
||||||
response = await fetch(`${this.apiBaseUrl}/servers`, {
|
}
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Authorization': `Bearer ${this.authToken}`,
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[LIVE MAIN MENU] Server list response status:', response.status);
|
// Add dev game server
|
||||||
|
try {
|
||||||
// Check if response is HTML (error page) instead of JSON
|
const devServerResponse = await fetch('http://localhost:3002/health');
|
||||||
const contentType = response.headers ? response.headers.get('content-type') : 'application/json';
|
if (devServerResponse.ok) {
|
||||||
if (!contentType || !contentType.includes('application/json')) {
|
const devServerInfo = await devServerResponse.json();
|
||||||
throw new Error('API server is not available. Please check your connection.');
|
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) {
|
// Add API servers
|
||||||
const data = await response.json();
|
console.log('[LIVE MAIN MENU] Fetching server list from:', `${this.apiBaseUrl}/servers`);
|
||||||
this.servers = data.servers || [];
|
const apiResponse = await fetch(`${this.apiBaseUrl}/servers`, {
|
||||||
console.log('[LIVE MAIN MENU] Server list loaded:', this.servers);
|
method: 'GET',
|
||||||
this.renderServerList();
|
headers: {
|
||||||
} else {
|
'Authorization': `Bearer ${this.authToken}`,
|
||||||
const errorText = await response.text();
|
'Content-Type': 'application/json'
|
||||||
console.error('[LIVE MAIN MENU] Failed to load server list - Status:', response.status, 'Error:', errorText);
|
}
|
||||||
this.servers = [];
|
});
|
||||||
this.renderServerList();
|
|
||||||
|
if (apiResponse.ok) {
|
||||||
// Show error message to user
|
const apiData = await apiResponse.json();
|
||||||
this.showLoginNotice(`Failed to connect to server: ${response.status}`, 'error');
|
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) {
|
} catch (error) {
|
||||||
console.error('[LIVE MAIN MENU] Server list error:', error);
|
console.error('[LIVE MAIN MENU] Server list error:', error);
|
||||||
this.servers = [];
|
this.servers = [];
|
||||||
@ -1229,6 +1256,20 @@ Status: ${this.selectedServer.status}
|
|||||||
|
|
||||||
// Now initialize multiplayer mode through GameInitializer
|
// Now initialize multiplayer mode through GameInitializer
|
||||||
if (window.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);
|
window.gameInitializer.initializeMultiplayer(server, serverData, this.authToken, this.currentUser);
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
@ -1244,6 +1285,20 @@ Status: ${this.selectedServer.status}
|
|||||||
|
|
||||||
// Initialize multiplayer mode through GameInitializer
|
// Initialize multiplayer mode through GameInitializer
|
||||||
if (window.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);
|
window.gameInitializer.initializeMultiplayer(server, serverData, this.authToken, this.currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user