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[] = [];