autoreconnect

This commit is contained in:
Soph :3 2024-07-08 01:21:07 +03:00
parent 1aeebc8ae9
commit 0d952fed60
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -16,6 +16,7 @@ const client = new Rcon(
config.rcon.port, config.rcon.port,
config.rcon.password config.rcon.password
); );
let rconReconnectTimeout: Timer | null | undefined;
client.on("connect", () => { client.on("connect", () => {
console.log("RCON connected."); console.log("RCON connected.");
@ -25,7 +26,15 @@ client.on("auth", () => {
console.log("RCON authenicated."); console.log("RCON authenicated.");
authenicated = true; authenicated = true;
}); });
client.on("end", () => {
console.log("RCON ended. Reconnecting in 1000ms.")
if(rconReconnectTimeout) {
clearTimeout(rconReconnectTimeout);
}
rconReconnectTimeout = setTimeout(() => {
client.connect()
}, 1000)
})
client.on("response", (a: string) => { client.on("response", (a: string) => {
if (playerRegex.test(a)) { if (playerRegex.test(a)) {
const whitelistedPlayers = a.replace(playerRegex, "").split(", "); const whitelistedPlayers = a.replace(playerRegex, "").split(", ");