From d1c80c1bac9d1430fd7d1d688cc7d74ffb26b4da Mon Sep 17 00:00:00 2001 From: Daid Date: Tue, 18 Feb 2020 19:23:17 +0000 Subject: [PATCH] Few fixes --- discordBot/config.py.template | 3 +++ discordBot/game.py | 18 ++++++++++++++++-- discordBot/main.py | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/discordBot/config.py.template b/discordBot/config.py.template index 7fc1a22101..65e2d0f558 100644 --- a/discordBot/config.py.template +++ b/discordBot/config.py.template @@ -7,3 +7,6 @@ admin = '' # Bot control role role = 'GameServerAdmin' + +# Game server password +server_password = None diff --git a/discordBot/game.py b/discordBot/game.py index 6b9033d7b6..8d42cbb237 100644 --- a/discordBot/game.py +++ b/discordBot/game.py @@ -1,10 +1,19 @@ import subprocess import requests import config +import os +import time _process = None +def getScenarios(): + result = [] + for filename in sorted(filter(lambda f: f.startswith("scenario_") and f.endswith(".lua"), os.listdir("../scripts/"))): + result.append(filename) + return result + + def start(scenario, variation): global _process if _process is not None: @@ -12,10 +21,15 @@ def start(scenario, variation): command = ["./EmptyEpsilon"] command += ["httpserver=8080"] command += ["headless=%s" % (scenario), "variation=%s" % (variation)] - command += ["headless_password=ee"] + if config.server_password is not None: + command += ["headless_password=%s" % (config.server_password)] command += ["headless_internet=1"] command += ["startpaused=1"] _process = subprocess.Popen(command, cwd="..") + time.sleep(2.0) + if _process.poll() is not None: + _process = None + return False return True def pause(): @@ -24,7 +38,7 @@ def pause(): return False return _lua("pauseGame()") == b'' -def unPause(): +def unpause(): global _process if _process is None: return False diff --git a/discordBot/main.py b/discordBot/main.py index a456ade75b..ef0e776161 100644 --- a/discordBot/main.py +++ b/discordBot/main.py @@ -52,7 +52,7 @@ async def onCommand(self, channel, command, args): else: await channel.send('Failed to pause the game') elif command == "unpause": - if game.pause(): + if game.unpause(): await channel.send('Unpaused the game') else: await channel.send('Failed to unpause the game')