This commit is contained in:
2025-10-13 14:00:39 -05:00
parent fc6d1237e9
commit 0e838b1f6e
2 changed files with 14 additions and 8 deletions

View File

@@ -12,7 +12,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"cors": "^2.8.5", "cors": "^2.8.5",
"minecraft-server-util": "^5.4.3", "minecraft-server-util": "^5.4.3",
"modern-rcon": "^1.2.1", "rcon-client": "^4.2.3",
"dockerode": "^4.0.2" "dockerode": "^4.0.2"
} }
} }

View File

@@ -1,7 +1,7 @@
import express from 'express'; import express from 'express';
import cors from 'cors'; import cors from 'cors';
import { status } from 'minecraft-server-util'; import { status } from 'minecraft-server-util';
import Rcon from 'modern-rcon'; import { Rcon } from 'rcon-client';
import Docker from 'dockerode'; import Docker from 'dockerode';
const app = express(); const app = express();
@@ -33,8 +33,11 @@ app.get('/api/status', async (req, res) => {
// Try to get additional info via RCON if server is online // Try to get additional info via RCON if server is online
try { try {
const rcon = new Rcon(MINECRAFT_HOST, RCON_PORT, RCON_PASSWORD); const rcon = await Rcon.connect({
await rcon.connect(); host: MINECRAFT_HOST,
port: RCON_PORT,
password: RCON_PASSWORD
});
// Get player list // Get player list
const listResponse = await rcon.send('list'); const listResponse = await rcon.send('list');
@@ -48,7 +51,7 @@ app.get('/api/status', async (req, res) => {
// spark might not be installed // spark might not be installed
} }
await rcon.disconnect(); rcon.end();
} catch (rconError) { } catch (rconError) {
console.error('RCON error:', rconError.message); console.error('RCON error:', rconError.message);
} }
@@ -127,11 +130,14 @@ app.post('/api/server/stop', async (req, res) => {
// Try graceful shutdown via RCON first // Try graceful shutdown via RCON first
try { try {
const rcon = new Rcon(MINECRAFT_HOST, RCON_PORT, RCON_PASSWORD); const rcon = await Rcon.connect({
await rcon.connect(); host: MINECRAFT_HOST,
port: RCON_PORT,
password: RCON_PASSWORD
});
await rcon.send('save-all'); await rcon.send('save-all');
await rcon.send('stop'); await rcon.send('stop');
await rcon.disconnect(); rcon.end();
} catch (rconError) { } catch (rconError) {
console.error('RCON shutdown error, using docker stop:', rconError.message); console.error('RCON shutdown error, using docker stop:', rconError.message);
await container.stop({ t: 30 }); // 30 second timeout await container.stop({ t: 30 }); // 30 second timeout