aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-11-14 13:50:24 +0100
committerKarel Kočí <cynerd@email.cz>2015-11-14 13:50:24 +0100
commit426b999aa8b129e66a0f5b5b3aceee371b40fe65 (patch)
tree6142291d78ec12e15349021d2f273e89c4ffc838
parent9e2636ae5da397ea69d521f2b2036cee3e428754 (diff)
downloadmcserver-wrapper-426b999aa8b129e66a0f5b5b3aceee371b40fe65.tar.gz
mcserver-wrapper-426b999aa8b129e66a0f5b5b3aceee371b40fe65.tar.bz2
mcserver-wrapper-426b999aa8b129e66a0f5b5b3aceee371b40fe65.zip
Remove actions from mcwrapper
Actions that would be send to server are useless when as same fast is possible write to file pipe. This way is code more clear and allows more expansions to the future. Also is consistent with planed Man in the middle server.
-rw-r--r--README.md24
-rwxr-xr-xmcwrapper123
-rw-r--r--todo.md1
3 files changed, 47 insertions, 101 deletions
diff --git a/README.md b/README.md
index 38bbe09..a5041c1 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
MINECRAFT-WRAPPER
=================
-
-Python server wrapper for extracting informations about server status and list of online players.
+Python server wrapper for extracting informations about server status and list of
+online players.
Requires:
-----------------
@@ -12,7 +12,7 @@ Requires:
Usage
-----------------
```
-mcwrapper [arguments...] ACTION ...
+mcwrapper [arguments...] IDENTIFIER
This script is executing Minecraft server and reads its output. From output is
extracted server status and list of online players.
@@ -24,20 +24,10 @@ mcwrapper [arguments...] ACTION ...
-q, --quiet
Decrease verbose level of output.
- Common action arguments
- IDENTIFIER
- Identifier for new server instance. This allows multiple server
- instances running with this wrapper.
- Identifier is word without spaces and preferably without special
- characters.
-
- ACTION and it's arguments
- start INDETIFIER
- Start server under "IDENTIFIER"
- stop IDENTIFIER
- Sends stop command to server under "IDENTIFIER"
- say IDENTIFIER {message...}
- Sends message to server chat
+ IDENTIFIER
+ Identifier for new server. This allows multiple servers running with this
+ wrapper. Identifier is word without spaces and preferably without special
+ characters.
```
How it works
diff --git a/mcwrapper b/mcwrapper
index dd6faee..dab5502 100755
--- a/mcwrapper
+++ b/mcwrapper
@@ -203,7 +203,7 @@ def __signal_term__(_signo, _stack_frame):
__server_send_stop__()
def print_help():
- print('mcwrapper [arguments...] ACTION ...')
+ print('mcwrapper [arguments...] IDENTIFIER')
print(' This script is executing Minecraft server and reads its output. From output is')
print(' extracted server status and list of online players.')
print('')
@@ -214,34 +214,15 @@ def print_help():
print(' Increase verbose level of output.')
print(' -q, --quiet')
print(' Decrease verbose level of output.')
- print('')
- print(' Common action arguments')
- print(' IDENTIFIER')
- print(' Identifier for new server instance. This allows multiple server')
- print(' instances running with this wrapper.')
- print(' Identifier is word without spaces and preferably without special')
- print(' characters.')
- print('')
- print(' ACTION and it\'s arguments')
- print(' start INDETIFIER')
- print(' Start server under "IDENTIFIER"')
- print(' stop IDENTIFIER')
- print(' Sends stop command to server under "IDENTIFIER"')
- print(' say IDENTIFIER {message...}')
- print(' Sends message to server chat')
+ print(' IDENTIFIER')
+ print(' Identifier for new server. This allows multiple servers running with this')
+ print(' wrapper. Identifier is word without spaces and preferably without special')
+ print(' characters.')
sys.exit()
if __name__ == '__main__':
- action = None
message = []
for arg in sys.argv[1:]:
- if (action == 'start' or action == 'stop' or action == 'say') \
- and conf.identifier == None:
- conf.identifier = arg
- continue
- if action == 'say':
- message.append(arg)
- continue
if arg[0] == '-':
if len(arg) > 2 and arg[1] == '-':
if arg == '--help':
@@ -262,68 +243,42 @@ if __name__ == '__main__':
else:
sys.exit("Unknown short argument " + l)
continue
- if action == None:
- if arg.lower() == 'start':
- action = 'start'
- continue
- if arg.lower() == 'stop':
- action = 'stop'
- continue
- if arg.lower() == 'say':
- action = 'say'
- continue
+ if conf.identifier == None:
+ conf.identifier = arg
+ continue
sys.exit("Unknown argument: " + arg)
# Parsing args ends
# Expand configuration for specified identifier
- if action == 'start' or action == 'stop' or action == 'say':
- if not conf.identifier:
- print('Missing server identifier argument!')
- print('')
- print_help()
- try:
- conf.server[conf.identifier]
- vars(conf).update(conf.server[conf.identifier])
- except KeyError:
- if conf.verbose_level >= -1:
- sys.exit('Error: No configuration associated with identifier: ' + conf.identifier)
- # Set configurations for server
- try:
- conf.directory
- except AttributeError:
- sys.exit('Missing "directory" config')
- try:
- conf.command
- except AttributeError:
- sys.exit('Missing server start command!')
- try:
- conf.status
- except AttributeError:
- conf.status = '/dev/shm/mcwrapper-' + conf.identifier
- # Set inputPipe
- global inputPipe
- inputPipe = conf.status + '/input_pipe'
-
- if action == 'start':
- signal.signal(signal.SIGTERM, __signal_term__)
- signal.signal(signal.SIGINT, __signal_term__)
- mcexec()
- elif action == 'stop':
- if not os.path.exists(inputPipe):
- sys.exit("Such server is not running")
- with open(inputPipe, 'w') as f:
- f.write("/stop\n")
- f.flush()
- while os.path.exists(inputPipe): # Block until server stops
- pass
- elif action == 'say':
- if not os.path.exists(inputPipe):
- sys.exit("Such server is not running")
- with open(inputPipe, 'w') as f:
- msg = ' '.join(message)
- msg = re.sub('^','say ', msg)
- print(msg)
- f.write(msg + '\n')
- f.flush()
- else:
+ if not conf.identifier:
+ print('Missing server identifier argument!')
+ print('')
print_help()
+ try:
+ conf.server[conf.identifier]
+ vars(conf).update(conf.server[conf.identifier])
+ except KeyError:
+ if conf.verbose_level >= -1:
+ sys.exit('Error: No configuration associated with identifier: ' + conf.identifier)
+ else:
+ sys.exit();
+ # Set configurations for server
+ try:
+ conf.directory
+ except AttributeError:
+ sys.exit('Missing "directory" config for server ' + conf.identifier)
+ try:
+ conf.command
+ except AttributeError:
+ sys.exit('Missing server start command for server ' + conf.identifier)
+ try:
+ conf.status
+ except AttributeError:
+ conf.status = '/dev/shm/mcwrapper-' + conf.identifier
+ # Set inputPipe
+ global inputPipe
+ inputPipe = conf.status + '/input_pipe'
+
+ signal.signal(signal.SIGTERM, __signal_term__)
+ signal.signal(signal.SIGINT, __signal_term__)
+ mcexec()
diff --git a/todo.md b/todo.md
index 670c4ff..ad78d7f 100644
--- a/todo.md
+++ b/todo.md
@@ -1 +1,2 @@
* Say command should accept text from stdin
+ * Add automatic server shutdown after elapsed time without any player