summary refs log tree commit diff homepage
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js9
1 files changed, 9 insertions, 0 deletions
diff --git a/index.js b/index.js
index 2d60b12..435ac15 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);
@@ -20,6 +21,14 @@ client.on("auth", function() {
     }
 }).on("end", function() {
     console.log("[INFO] Rcon closed!");
+}).on("error", function() {
+    if (typeof rconTimeout === 'undefined') {
+        client.disconnect();
+        rconTimeout = setTimeout(function() {
+            client.connect();
+            rconTimeout = undefined;
+        }, c.RCON_RECONNECT_DELAY * 1000);
+    }
 });
 
 client.connect();