Merge branch 'main' of https://github.com/Korvarix/Galaxy-Strike-Online
This commit is contained in:
commit
fea891678e
@ -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) => {
|
||||
|
||||
@ -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 },
|
||||
auth: { token, username: userInfo?.username },
|
||||
transports: ["websocket"],
|
||||
reconnectionAttempts: 5,
|
||||
});
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) => (
|
||||
<div key={server._id || server.serverName} className="server-card">
|
||||
<div className="server-info">
|
||||
<div className="status-indicator online"></div>
|
||||
<div
|
||||
className={`status-indicator ${server.status === "online" ? "online" : "offline"}`}
|
||||
></div>
|
||||
<div className="server-details-text">
|
||||
<span className="server-name">{server.name}</span>
|
||||
<span className="server-players">
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
29
readme.md
29
readme.md
@ -15,6 +15,35 @@ 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
|
||||
HOST=http://localhost: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
|
||||
|
||||
Reference in New Issue
Block a user