From 9704af5115a7feb284ba0106104765fcc4d9384a Mon Sep 17 00:00:00 2001 From: MaksSlyzar Date: Wed, 1 Apr 2026 16:59:39 +0300 Subject: [PATCH 1/3] update readme.md --- readme.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/readme.md b/readme.md index 4c38d8d..41fdca0 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,34 @@ Multiplayer space-themed game built with React, Socket.io. To automatically install all dependencies in the correct sub-projects (`api`, `game-server`, `client`) at once, run: +### 1. API Server (api/.env) + +```env +MONGODB_URI=mongodb://localhost:27017 +PORT=PORT +GAME_SERVER_SECRET=game_server_pass_123 +JWT_SECRET=secret_123 +``` + +### 2. GameServer (game-server/.env) + +```env +PORT=5003 +API_SERVER_URL=http://localhost:3000/api +SERVER_NAME=Alpha-Centauri-3 +SERVER_SECRET=game_server_pass_123 +JWT_SECRET=secret_123 +DESCRIPTION="Welcome to Alpha-Centauri-3, a high-tech frontier station drifting on the edge of the known galaxy." +REGION=UK +channel_binding=require +``` + +### 3. Client (client/.env) + +```env +VITE_API_URL=http://localhost:3000/api +``` + ```bash npm run install-all npm run dev From 15c312729e651e25d850b43cb5b671aa3f59721e Mon Sep 17 00:00:00 2001 From: MaksSlyzar Date: Wed, 1 Apr 2026 20:43:07 +0300 Subject: [PATCH 2/3] fix .env files --- client/src/context/SocketContext.jsx | 6 ++---- game-server/src/config/config.js | 1 + game-server/src/index.js | 6 ++++-- readme.md | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/context/SocketContext.jsx b/client/src/context/SocketContext.jsx index 46b5463..7771900 100644 --- a/client/src/context/SocketContext.jsx +++ b/client/src/context/SocketContext.jsx @@ -22,11 +22,9 @@ export const SocketProvider = ({ children }) => { } const userInfo = JSON.parse(localStorage.getItem("user")); - - console.log(url.replace("game-api", "socket.io")); const newSocket = io(url.replace("/game-api", ""), { - path: "/socket.io/", -auth: { token, username: userInfo?.username }, + path: "/socket.io/", + auth: { token, username: userInfo?.username }, transports: ["websocket"], reconnectionAttempts: 5, }); diff --git a/game-server/src/config/config.js b/game-server/src/config/config.js index 2e6146e..d946a57 100644 --- a/game-server/src/config/config.js +++ b/game-server/src/config/config.js @@ -8,6 +8,7 @@ const config = { serverDescription: process.env.DESCRIPTION, serverRegion: process.env.REGION, dbUri: process.env.DB_URI || "local", + host: process.env.HOST, }; module.exports = config; diff --git a/game-server/src/index.js b/game-server/src/index.js index 0ffd09a..36759da 100644 --- a/game-server/src/index.js +++ b/game-server/src/index.js @@ -50,13 +50,15 @@ const registerInApi = async () => { try { await axios.post(`${config.apiBaseUrl}/servers/register`, { name: config.serverName, - url: `https://dev-test.galaxystrike.online/game-api`, + url: config.host, secret: config.serverSecret, isModded: false, description: config.serverDescription, region: config.serverRegion, }); } catch (error) { + console.log(`Error: API server not found at ${config.apiBaseUrl}`); + console.log("Please configure API_SERVER_URL= in your .env file"); process.exit(1); } }; @@ -81,7 +83,7 @@ server.listen(config.port, async () => { economyService.init(io); await registerInApi(); setInterval(sendHeartbeat, HEARTBEAT_INTERVAL); - console.log(`🚀 Server running on port ${config.port}`); + console.log(`Server running on ${config.host}. PORT: ${config.port}`); } catch (error) { console.log(error); process.exit(1); diff --git a/readme.md b/readme.md index 41fdca0..49a5cf5 100644 --- a/readme.md +++ b/readme.md @@ -28,6 +28,7 @@ JWT_SECRET=secret_123 ```env PORT=5003 +HOST=http://localhost:5003 API_SERVER_URL=http://localhost:3000/api SERVER_NAME=Alpha-Centauri-3 SERVER_SECRET=game_server_pass_123 From 552d664eb2b46929a28c3f71bf8ecc69babec664 Mon Sep 17 00:00:00 2001 From: MaksSlyzar Date: Thu, 2 Apr 2026 03:59:54 +0300 Subject: [PATCH 3/3] added server status indicator and added server status logic --- api/src/services/serverService.js | 4 +- .../views/MainMenu/sections/ServerSection.css | 51 +++++++++++++++---- .../views/MainMenu/sections/ServerSection.jsx | 5 +- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/api/src/services/serverService.js b/api/src/services/serverService.js index d3484b8..73e8468 100644 --- a/api/src/services/serverService.js +++ b/api/src/services/serverService.js @@ -43,8 +43,8 @@ const checkServerHealth = async () => { }; const getAvailableServers = async () => { - return await GameServer.find({ status: "online" }).select( - "name url playersOnline maxPlayers", + return await GameServer.find({}).select( + "name url playersOnline status maxPlayers", ); }; const getServerConnectionDetails = async (serverId) => { diff --git a/client/src/views/MainMenu/sections/ServerSection.css b/client/src/views/MainMenu/sections/ServerSection.css index 8ec6c74..70b48b2 100644 --- a/client/src/views/MainMenu/sections/ServerSection.css +++ b/client/src/views/MainMenu/sections/ServerSection.css @@ -1,4 +1,3 @@ -/* Основні контроллери (фільтри та кнопка Refresh) */ .server-controls { display: flex; justify-content: space-between; @@ -30,7 +29,6 @@ border-color: var(--primary-color); } -/* Контейнер списку серверів */ .server-list { max-height: calc(100vh - 350px); overflow-y: auto; @@ -41,7 +39,6 @@ padding: 10px; } -/* КАРТКА СЕРВЕРА */ .server-card { display: flex; justify-content: space-between; @@ -52,10 +49,8 @@ border-radius: 2px; border: 1px solid var(--border-color); position: relative; - /* Прибрано загальний transition для трансформацій */ } -/* Синя лінія зліва (фіксована, без виїзду) */ .server-card::before { content: ""; position: absolute; @@ -77,7 +72,6 @@ opacity: 1; } -/* Інформація про сервер */ .server-info { display: flex; align-items: center; @@ -101,9 +95,9 @@ background: rgba(0, 0, 0, 0.3); padding: 2px 8px; border-radius: 4px; + max-width: 100px; } -/* Індикатор статусу */ .status-indicator.online { width: 10px; height: 10px; @@ -126,7 +120,6 @@ } } -/* Заголовок секції */ .server-section-title { font-family: "Orbitron", sans-serif; font-size: 1.5rem; @@ -137,7 +130,6 @@ letter-spacing: 4px; } -/* Стани завантаження та порожнього списку */ .server-loading, .server-empty { text-align: center; @@ -206,7 +198,6 @@ display: flex; flex-direction: column; } -/* Адаптивність */ @media screen and (max-width: 600px) { .server-card { flex-direction: column; @@ -232,3 +223,43 @@ margin-bottom: 5px; } } + +.status-indicator { + width: 10px; + height: 10px; + border-radius: 50%; + margin-right: 15px; +} + +.status-indicator.online { + background: var(--success-color); + box-shadow: 0 0 10px var(--success-color); + animation: status-pulse 2s infinite ease-in-out; +} + +.status-indicator.offline { + background: #555; + box-shadow: none; + animation: none; + opacity: 0.5; +} + +@keyframes status-pulse { + 0%, + 100% { + opacity: 0.7; + transform: scale(1); + } + 50% { + opacity: 1; + transform: scale(1.15); + } +} + +@media screen and (max-width: 600px) { + .status-indicator.online, + .status-indicator.offline { + margin-right: 0; + margin-bottom: 5px; + } +} diff --git a/client/src/views/MainMenu/sections/ServerSection.jsx b/client/src/views/MainMenu/sections/ServerSection.jsx index 474ccba..d719c8d 100644 --- a/client/src/views/MainMenu/sections/ServerSection.jsx +++ b/client/src/views/MainMenu/sections/ServerSection.jsx @@ -19,7 +19,6 @@ const ServerSection = ({ onBack, onSelect }) => { const elapsedTime = Date.now() - startTime; const remainingTime = Math.max(0, 2000 - elapsedTime); await new Promise((resolve) => setTimeout(resolve, remainingTime)); - setServers(response.data); } catch (error) { console.error("Error fetching servers:", error); @@ -110,7 +109,9 @@ const ServerSection = ({ onBack, onSelect }) => { filteredServers.map((server) => (
-
+
{server.name}