aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pycrctrl/pycrctrl.py75
1 files changed, 47 insertions, 28 deletions
diff --git a/pycrctrl/pycrctrl.py b/pycrctrl/pycrctrl.py
index 1076323..ab8db4b 100644
--- a/pycrctrl/pycrctrl.py
+++ b/pycrctrl/pycrctrl.py
@@ -31,13 +31,14 @@ import json
import base64
import supybot.log
import supybot.ircmsgs as ircmsgs
-import pycrctrl.plugins
+from . import plugins
from pickle import Pickler, Unpickler
from PyQt5.QtCore import *
from time import sleep
from platform import architecture
from io import BytesIO
+from copy import deepcopy
#iostream import
try:
@@ -260,13 +261,13 @@ class PyCRCtrl(object):
self.codec = QTextCodec.codecForName(self.config.get("encoding"))
self.queue = queue.Queue(5)
- if self.config.get("engine") == "openclonk-server":
+ if self.config["Clonk"]["Updater"]["enabled"]:
self.updater = Updater(self)
for dir in self.config["General"]["Directories"]["plugins"]:
for p in os.listdir(dir):
try:
- plugins.append(pycrctrl.plugins.loadPluginClass(pycrctrl.plugins.loadPlugin(p, dir)))
+ self.plugins.append(plugins.loadPluginClass(plugins.loadPlugin(p, dir)))
except Exception:
pass
@@ -318,17 +319,17 @@ class PyCRCtrl(object):
if self.path == None:
return False
- config = os.path.join(self.path, config)
+ conf = os.path.join(self.path, config)
print(config)
- if os.path.isdir(config):
+ if os.path.isdir(conf):
return False
- elif os.path.isfile(config):
- self.config = json.load(open(config),"r")
+ elif os.path.isfile(conf):
+ self.config = json.load(open(conf, "r"))
return True
- elif not os.path.exists(config):
+ elif not os.path.exists(conf):
c = {
"General" : {
"Directories" : {
@@ -343,11 +344,6 @@ class PyCRCtrl(object):
"commandlinePrefix" : "/",
"prefix" : "@",
- "Channels" : {
- "parent" : "",
- "ingame" : ""
- },
-
"RegExps" : {
"lobbyStartExp" : "",
"startExp" : "",
@@ -358,7 +354,11 @@ class PyCRCtrl(object):
"autohost" : False,
"IRC" : {
- "ingamechat" : True
+ "ingamechat" : True,
+ "Channels" : {
+ "parent" : "",
+ "ingame" : ""
+ }
},
"Rights" : {
@@ -368,6 +368,10 @@ class PyCRCtrl(object):
"Updater" : {
"enabled" : False,
+ "RegExps" : {
+ "autobuild" : "",
+ "snapshot" : ""
+ },
"Addresses" : {
"snapshotList" : "",
"snapshotDownload" : "",
@@ -378,9 +382,23 @@ class PyCRCtrl(object):
}
}
- json.dump(c, open(config, "w"))
+ json.dump(c, open(conf, "w"), indent=4)
return c
-
+
+ def setupConfig(self, config):
+ #commandline
+ sep = ":" if config["Clonk"]["commandlinePrefix"] == "/" else "="
+ config["Clonk"]["commandline"] = " ".join([
+ "{}{}".format(config["Clonk"]["commandlinePrefix"], sep.join(entry) if isinstance(entry, list) else entry) for entry in config["Clonk"]["commandline"]
+ ])
+
+ #regexps
+
+ config["Clonk"]["RegExps"] = {
+ i:re.compile(self.decodeRegExp(config["Clonk"]["RegExps"][i])) for i in config["Clonk"]["RegExps"]
+ }
+
+ self.ingamechat = config["Clonk"]["IRC"]["ingamechat"]
def decodeRegExp(self, regexp):
return self.codec.toUnicode(base64.b64decode(regexp))
@@ -433,9 +451,10 @@ class PyCRCtrl(object):
else:
self.scenario = random.choice(self.scenlist)
- self.capabilities = self._capa_old
+ self.capabilities = deepcopy(self._capa_old)
+ commandline =
self.clonk = subprocess.Popen(
- './{} {} "{}"'.format(self.config.get("engine"), self.config.get("commandline") + (" --" if self.config.get("engine") == "openclonk-server" else " /") + ("league" if self.scenario in self.league_scenlist() else "noleague"),self.scenario),
+ './{} {} "{}"'.format(self.config["Clonk"]["engine"], self.config["Clonk"]["commandline"] + self.config["Clonk"]["commandlinePrefix"] + ("league" if self.scenario in self.league_scenlist() else "noleague"),self.scenario),
0,
None,
subprocess.PIPE,
@@ -446,7 +465,7 @@ class PyCRCtrl(object):
)
self.state = "Lobby"
self.readServerOutput()
- if self.config.get("autohost") == False:
+ if self.config["Clonk"]["autohost"] == False:
self.thread_started = False
self.setTopic("Kein laufendes Spiel.")
break
@@ -462,7 +481,7 @@ class PyCRCtrl(object):
try:
output = self.clonk.stdout.readline()
- if bool(re.match(self.decodeRegExp(self.config.get("RegExps")["shutdownExp"]), self.codec.toUnicode(output))):
+ if self.config["Clonk"]["RegExps"]["shutdownExp"].match(self.codec.toUnicode(output)):
self.clonk.stdin.close()
elif output == b"" and self.clonk.poll() is not None:
if self.clonk:
@@ -479,7 +498,7 @@ class PyCRCtrl(object):
if output[0] == ">":
output = output[1:]
- part = re.match("<(.*)> ({})(.*)".format(self.config.get("prefix")), output)
+ part = re.match("<(.*)> ({})(.*)".format(self.config["Clonk"]["prefix"), output)
if part and part.group(0) != self.irc.nick:
cmd = part.group(3).split(" ", 1)
found = False
@@ -500,10 +519,10 @@ class PyCRCtrl(object):
if type(x) == tuple and x[1] != "":
self.writeToServer(x[1])
del x
- if bool(re.match(self.decodeRegExp(self.config.get("RegExps")["lobbyStartExp"]), output)):
+ if self.config["Clonk"]["RegExps"]["lobbyStartExp"].match(output):
self.state = "Lädt"
- elif bool(re.match(self.decodeRegExp(self.config.get("RegExps")["startExp"]), output)):
+ elif self.config["Clonk"]["RegExps"]["lobbyStartExp"].match(output):
self.state = "Läuft"
try:
cout << output << endl
@@ -512,11 +531,11 @@ class PyCRCtrl(object):
if self.irc and self.ingamechat == "aktiviert":
if output.find("<" + self.irc.nick + ">") == -1:
- if re.match(r"^<.*>", output) and output.find("[IRC]") == -1 and output.find(self.config.get("prefix")) == -1:
- self.irc.reply("[Clonk]{}".format(output), to=self.config.get("channels")["ingame"])
+ if re.match(r"^<.*>", output) and output.find("[IRC]") == -1 and output.find(self.config["Clonk"]["prefix"]) == -1:
+ self.irc.reply("[Clonk]{}".format(output), to=self.config["Clonk"]["IRC"]["channels"]["ingame"])
- elif re.match(self.decodeRegExp(self.config.get("RegExps")["joinExp"]), output) or re.match(self.decodeRegExp(self.config.get("RegExps")["leaveExp"]), output):
- self.irc.reply(output, to=self.config.get("channels")["ingame"])
+ elif self.config["Clonk"]["RegExps"]["joinExp"].match(output) or self.config["Clonk"]["RegExps"]["leaveExp"].match(output):
+ self.irc.reply(output, to=self.config["Clonk"]["IRC"]["channels"]["ingame"])
except KeyboardInterrupt:
@@ -533,7 +552,7 @@ class PyCRCtrl(object):
if not (self.irc and self.ingamechat == "aktiviert"):
return
for channel in msg.args[0].split(","):
- if channel == self.config.get("channels")["ingame"] and msg.nick != self.irc.nick:
+ if channel == self.config["Clonk"]["IRC]["channels"]["ingame"] and msg.nick != self.irc.nick:
self.writeToServer("[IRC]<{}> {}".format(msg.nick, msg.args[1]))