summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--config.json1
-rw-r--r--index.js9
2 files changed, 10 insertions, 0 deletions
diff --git a/config.json b/config.json
index 48778d3..07e3895 100644
--- a/config.json
+++ b/config.json
@@ -9,5 +9,6 @@
     "WEBHOOK": "/minecraft/hook",
     "REGEX_MATCH_CHAT_MC": "\\[Server thread/INFO\\]: <(.*)> (.*)",
     "REGEX_IGNORED_CHAT": "packets too frequently",
+    "RCON_RECONNECT_DELAY": 10,
     "DEBUG": false
 }
\ No newline at end of file
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();