aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-10-23 15:17:07 +0200
committerKarel Kočí <cynerd@email.cz>2016-10-23 15:18:15 +0200
commitd7b7cdf04c4a04eae1a44b53a8091fd1cda9d90f (patch)
tree557f1ecc47707e82e618f38a8a928e2517d760b1
parent2218dc3e6adaedeb53fd166f4fb8b6f5b3ede7bc (diff)
downloadmcserver-wrapper-d7b7cdf04c4a04eae1a44b53a8091fd1cda9d90f.tar.gz
mcserver-wrapper-d7b7cdf04c4a04eae1a44b53a8091fd1cda9d90f.tar.bz2
mcserver-wrapper-d7b7cdf04c4a04eae1a44b53a8091fd1cda9d90f.zip
Load mod file every time new message is going to be printed
-rw-r--r--README.md7
-rwxr-xr-xmcwrapper/__init__.py8
-rw-r--r--mcwrapper/mod.py19
-rwxr-xr-xsetup.py2
4 files changed, 10 insertions, 26 deletions
diff --git a/README.md b/README.md
index bcab451..ae2ada4 100644
--- a/README.md
+++ b/README.md
@@ -81,9 +81,4 @@ content don't have to be valid.
#### Message of the day
This prints to players various short messages in given interval. Message is from
-file passed as --mod-file and it's randomly selected line. This file is read on
-wrapper start, so if you edit it while it's running, no change will happen unless
-you send USR1 signal to mcwrapper server. You can use this simple script:
-```
-[ -f server.pid ] && kill -USR1 $(cat server.pid)
-```
+file passed as --mod-file and it's randomly selected line.
diff --git a/mcwrapper/__init__.py b/mcwrapper/__init__.py
index dec7194..18e73aa 100755
--- a/mcwrapper/__init__.py
+++ b/mcwrapper/__init__.py
@@ -35,12 +35,6 @@ __HELP_DESC__ = """
"""
-def reload():
- "Reloads input files. Currently applicable only on mod."
- if mcserver_mod is not None:
- mcserver_mod.load_mods()
-
-
def main():
"Main function"
global verbose_level
@@ -80,8 +74,6 @@ def main():
command.append('nogui')
alarm.init()
- signal.signal(signal.SIGUSR1, reload)
- signal.signal(signal.SIGUSR2, reload) # probably can be used for something else in future
global mcserver_wrapper
mcserver_wrapper = MCWrapper(command, pfile, sfile)
diff --git a/mcwrapper/mod.py b/mcwrapper/mod.py
index 3d3967c..73200f1 100644
--- a/mcwrapper/mod.py
+++ b/mcwrapper/mod.py
@@ -10,20 +10,17 @@ class MoD:
def __init__(self, mcwrapper, file, period=900):
self.mcwrapper = mcwrapper
self.file = file
- self.load_mods()
alarm.set("mod-time", period, self.__handler__, repeat=True)
- def load_mods(self):
- "Loads messages from self.file"
+ def __handler__(self):
+ lines = []
try:
with open(self.file, "r") as f:
- self.lines = f.readlines()
+ lines = f.readlines()
except OSError as e:
prints.warning("Loading of MoD file failed: " + str(e))
- self.lines = []
-
- def __handler__(self):
- if len(self.lines) > 0:
- i = random.randint(0, len(self.lines) - 1)
- self.mcwrapper.write_to_terminal("/say " + self.lines[i].rstrip()
- + "\n")
+ return
+ if len(lines) > 0:
+ i = random.randint(0, len(lines) - 1)
+ self.mcwrapper.write_to_terminal("/say " + lines[i].rstrip() +
+ "\n")
diff --git a/setup.py b/setup.py
index 217d01d..499bab5 100755
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@ except (IOError, ImportError):
setup(
name='mcserver-wrapper',
- version='0.4',
+ version='0.4.1',
description="Minecraft server wrapper",
long_description=long_description,
url="https://github.com/Cynerd/mcserver-wrapper",