diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/manager.js b/manager.js old mode 100644 new mode 100755 index 2846b29..732be61 --- a/manager.js +++ b/manager.js @@ -9,27 +9,38 @@ String.prototype.capitalize = function() { return this[0].toUpperCase() + this.substring(1); }; +//constantn'ts this is up here for scope reasons don't @ me +var StatusCycleCount = 0; +var OnlineServers = []; + +//constants var MAX_IDLE_MINUTES = 60; var CMD_PREFIX = '%'; +const DEFAULT_STATUS = `${CMD_PREFIX}help` +const STATUS_CYCLE = [ + "Servers running: " + OnlineServers.join(", "), + "%start to start a server!", + "servername.mc.jpdld.com!" +]; + class MinecraftServer extends EventEmitter { constructor (cwd, jar) { super(); this.cwd = cwd; - this.java = "java"; this.jvm_args = ["-Xmx4G"]; this.jar = jar; this.idleMinutes = 0; this.locked = false; - // paper 1.16.2 + // for 1.14.4 (paper) // also working on 1.15 this.listCommand = "minecraft:list"; - this.listEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are 0 of a max of \d{1,} players online:$/; - this.listNotEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are [1-9]\d{0,} of a max of \d{1,} players online:/; + this.listEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are 0 of a max \d{1,} players online:$/; + this.listNotEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are [1-9]\d{0,} of a max \d{1,} players online:/; } start() { this._log("Starting server".green); - this.process = child_process.spawn("nice", ["-n", "1", this.java].concat(this.jvm_args).concat(["-jar", this.jar]), {cwd: this.cwd}); + this.process = child_process.spawn("nice", ["-n", "1", "java"].concat(this.jvm_args).concat(["-jar", this.jar]), {cwd: this.cwd}); this.process.on("error", error => { this.process.emit("exit"); this._log(error.stack.red, true); @@ -120,11 +131,9 @@ servers.modded._testIfConsoleLineIndicatesNoPlayersOnline = function(line) { return line.endsWith("] [Server thread/INFO] [minecraft/DedicatedServer]: There are 0/20 players online:"); } servers.modded.listCommand = "list"; -servers.modded.java = "/usr/bin/java"; // java 8 servers.modded2._testIfConsoleLineIndicatesPlayersOnline = servers.modded._testIfConsoleLineIndicatesPlayersOnline; servers.modded2._testIfConsoleLineIndicatesNoPlayersOnline = servers.modded._testIfConsoleLineIndicatesNoPlayersOnline; servers.modded2.listCommand = servers.modded.listCommand; -servers.modded2.java = "/usr/bin/java"; servers.multiverse.listEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are 0\/\d{1,} players online:$/; servers.multiverse.listNotEmptyRegex = /^\[\d\d:\d\d:\d\d INFO\]: There are [1-9]\d{0,}\/\d{1,} players online:$/; @@ -142,12 +151,14 @@ function commandHandler(input, priviledged) { if (!server) return `Unknown server ${serverName}` if (server.process) return `${serverName.capitalize()} server is already running.`; server.start(); + OnlineServers.push(serverName.capitalize()); return `Starting ${serverName} server.`; } else if (cmd == "stop") { if (!priviledged) return unauthorized; if (!server) return `Unknown server ${serverName}` if (!server.process) return `${serverName.capitalize()} server is not running.`; server.stop(); + OnlineServers.splice(serverName.capitalize()); return `Stopping ${serverName} server.`; } else if (cmd == "input") { if (!priviledged) return unauthorized; @@ -194,10 +205,15 @@ if (process.env.DISCORD_TOKEN) { var dClient = new Discord.Client(); dClient.login(process.env.DISCORD_TOKEN); dClient.on("error", error => console.error(colors.red("Discord client error: " + error.message))); - function setStatus() { - dClient.user.setActivity(`${CMD_PREFIX}help`); + function setStatus(status) { + dClient.user.setActivity(status); } - setInterval(setStatus, 1000*60*30); + //setInterval(setStatus, 1000*60*30); + setInterval(() => { + StatusCycleCount++; + if (StatusCycleCount >= STATUS_CYCLE.length) count = 0; + setStatus(`${DEFAULT_STATUS} | ${STATUS_CYCLE[StatusCycleCount]}`); + }, 3500); dClient.on("ready", () => { console.log("Discord client is ready.".green); setStatus(); diff --git a/package-lock.json b/package-lock.json old mode 100644 new mode 100755 index 69fdd18..c6e884a --- a/package-lock.json +++ b/package-lock.json @@ -50,9 +50,9 @@ "integrity": "sha512-kcoMoKTPYnoeS50tzoqjPY3Uv9axeuuFAZY9M/9zFnhoVvRfxz9K29IMPD7jGmt2c8SW7i3gT9WqDl2+nV7p4A==" }, "ws": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", - "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", + "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", "requires": { "async-limiter": "~1.0.0" } diff --git a/package.json b/package.json old mode 100644 new mode 100755