From 562df25d0ae08b7147e097b52a9bdaf712096fca Mon Sep 17 00:00:00 2001 From: sophie Date: Mon, 8 Jul 2024 01:20:54 +0300 Subject: [PATCH] autoreconnect --- index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/index.ts b/index.ts index 4945b26..2c69943 100644 --- a/index.ts +++ b/index.ts @@ -3,6 +3,8 @@ import { Rcon } from "./rcon"; import config from "./config.json" assert { type: "json" }; const rcon = new Rcon(config.rcon.host, config.rcon.port, config.rcon.password); +let rconReconnectTimeout: Timer | null | undefined; + const client = new Client({ intents: [ GatewayIntentBits.Guilds, @@ -19,6 +21,15 @@ rcon.on("auth", () => { console.log("RCON authenicated."); }); +rcon.on("end", () => { + console.log("RCON ended. Reconnecting in 1000ms.") + if(rconReconnectTimeout) { + clearTimeout(rconReconnectTimeout); + } + rconReconnectTimeout = setTimeout(() => { + rcon.connect() + }, 1000) +}) client.once(Events.ClientReady, async (readyClient) => { console.log(`Ready! Logged in as ${readyClient.user.tag}`); let playerUsernames: string[] = [];