pushed
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
"express": "^4.18.2",
|
||||
"cors": "^2.8.5",
|
||||
"minecraft-server-util": "^5.4.3",
|
||||
"modern-rcon": "^1.2.1",
|
||||
"rcon-client": "^4.2.3",
|
||||
"dockerode": "^4.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
import { status } from 'minecraft-server-util';
|
||||
import Rcon from 'modern-rcon';
|
||||
import { Rcon } from 'rcon-client';
|
||||
import Docker from 'dockerode';
|
||||
|
||||
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 {
|
||||
const rcon = new Rcon(MINECRAFT_HOST, RCON_PORT, RCON_PASSWORD);
|
||||
await rcon.connect();
|
||||
const rcon = await Rcon.connect({
|
||||
host: MINECRAFT_HOST,
|
||||
port: RCON_PORT,
|
||||
password: RCON_PASSWORD
|
||||
});
|
||||
|
||||
// Get player list
|
||||
const listResponse = await rcon.send('list');
|
||||
@@ -48,7 +51,7 @@ app.get('/api/status', async (req, res) => {
|
||||
// spark might not be installed
|
||||
}
|
||||
|
||||
await rcon.disconnect();
|
||||
rcon.end();
|
||||
} catch (rconError) {
|
||||
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 {
|
||||
const rcon = new Rcon(MINECRAFT_HOST, RCON_PORT, RCON_PASSWORD);
|
||||
await rcon.connect();
|
||||
const rcon = await Rcon.connect({
|
||||
host: MINECRAFT_HOST,
|
||||
port: RCON_PORT,
|
||||
password: RCON_PASSWORD
|
||||
});
|
||||
await rcon.send('save-all');
|
||||
await rcon.send('stop');
|
||||
await rcon.disconnect();
|
||||
rcon.end();
|
||||
} catch (rconError) {
|
||||
console.error('RCON shutdown error, using docker stop:', rconError.message);
|
||||
await container.stop({ t: 30 }); // 30 second timeout
|
||||
|
||||
Reference in New Issue
Block a user