diff options
author | secret_online <me+github@secretonline.co> | 2016-01-24 09:26:07 +1300 |
---|---|---|
committer | secret_online <me+github@secretonline.co> | 2016-01-24 09:26:07 +1300 |
commit | 6a7fa0baba003a3c3ccbaf51bffc9ebe5064b172 (patch) | |
tree | 46e0a9af403b19820af7a6be99263315aa1b9650 | |
parent | Add config option for RCON delay (diff) | |
download | shulker-6a7fa0baba003a3c3ccbaf51bffc9ebe5064b172.tar.gz shulker-6a7fa0baba003a3c3ccbaf51bffc9ebe5064b172.zip |
Only have one RCON reconnect at the same time
Diffstat (limited to '')
-rw-r--r-- | index.js | 12 |
1 files changed, 8 insertions, 4 deletions
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(); |