From dc4a8cd1475e575b62f828ca43b98755c1ae344a Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Mon, 31 Oct 2016 13:26:08 +0100 Subject: PyOCCtrl: Fix RegExps --- pycrctrl.py | 65 +++++++++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) (limited to 'pycrctrl.py') diff --git a/pycrctrl.py b/pycrctrl.py index 71d7292..23d9bbc 100644 --- a/pycrctrl.py +++ b/pycrctrl.py @@ -98,7 +98,6 @@ class PyCRCtrl: commandline = "/fullscreen /lobby:300 /config:config.txt /record /faircrew" path = QString() - crsmpath = QString() scenlist = QStringList() channel = "" @@ -107,6 +106,11 @@ class PyCRCtrl: __state = "Lobby" RegExps = { + "lobbyStartExp" : "((?:Los geht's!|Action go!)\s*)", + "startExp" : r"^Start!\s*$", + "joinExp" : r"^Client (.+) (?:verbunden|connected)\.\s*$", + "leaveExp" : "^Client (.+) (?:entfernt|removed)(.*)", + "shutdownExp" : r"^Internetspiel ausgewertet(.*)" } def __init__(self, **kwargs): @@ -119,11 +123,9 @@ class PyCRCtrl: self.channel = QString(kwargs["channel"]) self.loadScenarioList() self.queue = queue.Queue(5) - try: - self.crsmpath = QString(kwargs["crsmpath"]) - except KeyError: - self.crsmpath = self.path - #self.loadRegExps() + + def __ostream__(self, ostream): + return "PyCRCtrl: commandline: {}, channel: {}, scenario: {}".format(self.commandline, self.channel, (self.scenario if self.scenario != "" else "None")) def getState(self): return self.__state @@ -143,20 +145,6 @@ class PyCRCtrl: self.scenlist.strlist = Unpickler(fobj).load() return True - - def loadRegExps(self): - #if self.path == None: - # return False - # - #lines = list() - #search = ["lobbyStartExp", "startExp", "leaveExp", "joinExp"] - # - #with open(os.path.join(self.crsmpath, os.path.join("src", "crsm.cpp")), "rb") as fobj: - # for item in fobj.read().splitlines(): - # for i in search: - # if item.find(i) != -1: - # line.append(item) - pass def host(self, scenario=None) -> str: if scenario == None: @@ -222,7 +210,7 @@ class PyCRCtrl: try: output = self.clonk.stdout.readline() - if self.codec.toUnicode(output).find("Internetspiel ausgewertet") != -1: + if bool(re.match(self.RegExps["shutdownExp"], self.codec.toUnicode(output))): self.clonk.stdin.close() elif output == b"" and self.clonk.poll() is not None: if self.clonk: @@ -258,15 +246,15 @@ class PyCRCtrl: self.writeToServer(x[1]) del x - if bool(re.match("((?:Los geht's!|Action go!)\s*)", output)): # RegExp from CRSM ((c) DerTod) + if bool(re.match(self.RegExps["lobbyStartExp"], output)): self.state = "Lädt" - elif bool(re.match(r"^Start!\s*$", output)): + elif bool(re.match(self.RegExps["startExp"], output)): self.state = "Läuft" - try: - cout << output << endl - except: - pass + #try: + cout << output << endl + #except: + #pass # RegExps are from CRSM ((c) DerTod) if self.irc: @@ -275,8 +263,8 @@ class PyCRCtrl: bool(output.find(self.prefix) == -1): self.irc.reply("[Clonk]{}".format(output), to=self.channel) - elif bool(re.match(r"^Client (.+) (?:verbunden|connected)\.\s*$", output)) or \ - bool(re.match("^Client (.+) (?:entfernt|removed)(.*)", output)): + elif bool(re.match(self.RegExps["joinExp"], output)) or \ + bool(re.match(self.RegExps["leaveExp"], output)): self.irc.reply(output, to=self.channel) @@ -291,10 +279,10 @@ class PyCRCtrl: ## for line in tb.splitlines(): # self.writeToServer(line) - try: - cerr << line << endl - except: - pass + #try: + cerr << line << endl + #except: + # pass #else: # continue continue @@ -413,9 +401,18 @@ class PyCRCtrl: return self class PyOCCtrl(PyCRCtrl): + + RegExps = { + "lobbyStartExp" : "((?:Los geht's!|Action go!)\s*)", + "startExp" : r"^Spiel gestartet.", + "joinExp" : r"^Client (.+) (?:verbunden|connected)\.\s*$", + "leaveExp" : "^Client (.+) (?:entfernt|removed)(.*)", + "shutdownExp" : r"^Spiel ausgewertet(.*)" + } + engine = "openclonk-server" codec = QTextCodec.codecForName("UTF-8") - commandline = "--fullscreen --lobby=300 --faircrew --record" + commandline = "--fullscreen --lobby=300 --faircrew --record --config=config.txt" # # -- cgit v1.2.3-54-g00ecf