autoreconnect
This commit is contained in:
parent
de2fdf77ec
commit
562df25d0a
11
index.ts
11
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[] = [];
|
||||
|
|
Loading…
Reference in a new issue