autoreconnect
This commit is contained in:
parent
1aeebc8ae9
commit
0d952fed60
|
@ -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(", ");
|
||||||
|
|
Loading…
Reference in a new issue