From 6a7fa0baba003a3c3ccbaf51bffc9ebe5064b172 Mon Sep 17 00:00:00 2001 From: secret_online Date: Sun, 24 Jan 2016 09:26:07 +1300 Subject: Only have one RCON reconnect at the same time --- index.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'index.js') diff --git a/index.js b/index.js index 7a288f8..e034e9a 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ var debug = c.DEBUG; var shulker = new Discord.Client(); var client = new Rcon(c.MINECRAFT_SERVER_RCON_IP, c.MINECRAFT_SERVER_RCON_PORT, c.MINECRAFT_SERVER_RCON_PASSWORD); +var rconTimeout; client.on("auth", function() { console.log("[INFO] Authenticated with " + c.MINECRAFT_SERVER_RCON_IP + ":" + c.MINECRAFT_SERVER_RCON_PORT); @@ -21,10 +22,13 @@ client.on("auth", function() { }).on("end", function() { console.log("[INFO] Rcon closed!"); }).on("error", function() { - client.disconnect(); - setTimeout(function() { - client.connect(); - }, c.RCON_RECONNECT_DELAY * 1000); + if (typeof rconTimeout === 'undefined') { + client.disconnect(); + rconTimeout = setTimeout(function() { + client.connect(); + rconTimeout = undefined; + }, c.RCON_RECONNECT_DELAY * 1000); + } }); client.connect(); -- cgit 1.4.1