aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pycrctrl.pyp33
1 files changed, 20 insertions, 13 deletions
diff --git a/pycrctrl.pyp b/pycrctrl.pyp
index 3ee429b..e0c393b 100644
--- a/pycrctrl.pyp
+++ b/pycrctrl.pyp
@@ -25,6 +25,7 @@ import traceback
import os
import PyQt5
import re
+import signal
import supybot.ircmsgs as ircmsgs
from pickle import Unpickler
@@ -82,7 +83,7 @@ class CmdResult(IntEnum):
RightsFail = 2
RuntimeError = 3
-class PyCRCtrl:
+class PyCRCtrl(object):
"""Server control"""
clonk = None
@@ -99,9 +100,11 @@ class PyCRCtrl:
path = QString()
scenlist = QStringList()
+ league_scenlist = QStringList()
- channel = ""
+ channels = {}
topic = "Kein laufendes Spiel."
+ league = True
__state = "Lobby"
@@ -120,12 +123,13 @@ class PyCRCtrl:
self.autohost = bool(kwargs["autohost"])
self.irc = kwargs["irc"]
self.path = QString(kwargs["path"])
- self.channel = QString(kwargs["channel"])
+ self.channels["ingame"] = QString(kwargs["ingamechannel"])
+ self.channels["parent"] = QString(kwargs["channel"])
self.loadScenarioList()
self.queue = queue.Queue(5)
def __ostream__(self, ostream):
- return "PyCRCtrl: commandline: {}, channel: {}, scenario: {}".format(self.commandline, self.channel, (self.scenario if self.scenario != "" else "None"))
+ return "PyCRCtrl: commandline: {}, channel: {}, scenario: {}".format(self.commandline, self.channels["ingame"], (self.scenario if self.scenario != "" else "None"))
def getState(self):
return self.__state
@@ -137,13 +141,16 @@ class PyCRCtrl:
state = property(getState, setState)
- def loadScenarioList(self):
+ def loadScenarioList(self) -> bool:
if self.path == None:
return False
with open(os.path.join(self.path,"scenlist"), "rb") as fobj:
self.scenlist.strlist = Unpickler(fobj).load()
+ with open(os.path.join(self.path, "scenlist.league"), "rb") as fobj:
+ self.league_scenlist.strlist = Unpickler(fobj).load()
+
return True
def host(self, scenario=None) -> str:
@@ -183,7 +190,7 @@ class PyCRCtrl:
else:
self.scenario = self.scenlist[randint(0,len(self.scenlist))-1]
self.clonk = subprocess.Popen(
- './{} {} "{}"'.format(self.engine, self.commandline,self.scenario),
+ './{} {} "{}"'.format(self.engine, self.commandline + (" --" if type(self).__name__ == "PyOCCtrl" else " /") + ("league" if self.scenario in self.league_scenlist() else "noleague"),self.scenario),
0,
None,
subprocess.PIPE,
@@ -225,8 +232,7 @@ class PyCRCtrl:
if output[0] == ">":
output = output[1:]
-
- if output.find(self.prefix) != -1:
+ if output.find(self.prefix) != -1 and output.find("<{}>".format(self.irc.nick)) == -1:
part = output[output.find(self.prefix)+len(self.prefix):].split(" ",1)
found = False
x = None
@@ -245,7 +251,6 @@ class PyCRCtrl:
if type(x) == tuple and x[1] != "":
self.writeToServer(x[1])
del x
-
if bool(re.match(self.RegExps["lobbyStartExp"], output)):
self.state = "Lädt"
@@ -261,11 +266,11 @@ class PyCRCtrl:
if output.find("<" + self.irc.nick + ">") == -1:
if bool(re.match(r"^<.*>", output) and output.find("[IRC]") == -1) and \
bool(output.find(self.prefix) == -1):
- self.irc.reply("[Clonk]{}".format(output), to=self.channel)
+ self.irc.reply("[Clonk]{}".format(output), to=self.channels["ingame"])
elif bool(re.match(self.RegExps["joinExp"], output)) or \
bool(re.match(self.RegExps["leaveExp"], output)):
- self.irc.reply(output, to=self.channel)
+ self.irc.reply(output, to=self.channels["ingame"])
except KeyboardInterrupt:
@@ -294,7 +299,7 @@ class PyCRCtrl:
if not self.irc:
return
for channel in msg.args[0].split(","):
- if channel == self.channel and msg.nick != self.irc.nick:
+ if channel == self.channels["ingame"] and msg.nick != self.irc.nick:
self.writeToServer("[IRC]<{}> {}".format(msg.nick, msg.args[1]))
@@ -327,7 +332,7 @@ class PyCRCtrl:
else:
self.topic = text
- return bool(self.irc.sendMsg(ircmsgs.topic(self.channel, text)))
+ return bool(self.irc.sendMsg(ircmsgs.topic(self.channels["ingame"], text)))
def start(self, time=None):
self.stopped = False
@@ -400,6 +405,8 @@ class PyCRCtrl:
def addCommand(self, function, text):
self.commands[text.split(" ")[0]] = function
return self
+
+
class PyOCCtrl(PyCRCtrl):