fix server not closing on timeout

This commit is contained in:
hippoz 2022-03-12 17:08:52 +02:00
parent 3900cf39c4
commit 694e0e45ed
Signed by: hippoz
GPG key ID: 7C52899193467641

View file

@ -11,7 +11,6 @@ import { spawn } from "node:child_process";
import Rcon from "rcon"; import Rcon from "rcon";
const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN0YWdpbmctbWluZWNyYWZ0LWJyaWRnZSIsImF2YXRhclVSTCI6bnVsbCwiZGlzY29yZElEIjoiMCIsImd1aWxkQWNjZXNzIjpbIjczNjI5MjUwOTEzNDc0OTgwNyJdLCJpc1N1cGVyVG9rZW4iOnRydWUsImlhdCI6MTY0NDQ1MzM4MX0.-XIBl6VLnXVwve9iqhWs51ABZkm1i_v1tS6X01SPk3U"; // A supertoken is required to send messages from Minecraft. const TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN0YWdpbmctbWluZWNyYWZ0LWJyaWRnZSIsImF2YXRhclVSTCI6bnVsbCwiZGlzY29yZElEIjoiMCIsImd1aWxkQWNjZXNzIjpbIjczNjI5MjUwOTEzNDc0OTgwNyJdLCJpc1N1cGVyVG9rZW4iOnRydWUsImlhdCI6MTY0NDQ1MzM4MX0.-XIBl6VLnXVwve9iqhWs51ABZkm1i_v1tS6X01SPk3U"; // A supertoken is required to send messages from Minecraft.
const TARGET_GUILD_ID = "_"; const TARGET_GUILD_ID = "_";
const TARGET_CHANNEL_ID = "_"; const TARGET_CHANNEL_ID = "_";
@ -370,6 +369,9 @@ class Bridge {
setTimeout(() => { setTimeout(() => {
if (this.playerCount === 0) { if (this.playerCount === 0) {
console.log("server job: no players on server after 5 minutes, closing..."); console.log("server job: no players on server after 5 minutes, closing...");
if (this.process) {
this.process.kill("SIGINT");
}
this.sendBridgeMessageAs(TARGET_GUILD_ID, TARGET_CHANNEL_ID, ":pensive: Server was started, yet no one joined after 5 minutes. Closing again...", null, null); this.sendBridgeMessageAs(TARGET_GUILD_ID, TARGET_CHANNEL_ID, ":pensive: Server was started, yet no one joined after 5 minutes. Closing again...", null, null);
} }
}, 300000); }, 300000);