aboutsummaryrefslogtreecommitdiff
path: root/modules/say.py
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-08-15 14:50:43 +0200
committerKarel Kočí <cynerd@email.cz>2015-09-03 12:56:29 +0200
commite4b0c7f50efbe0c42aa933cb58a86a44367c1140 (patch)
treef6d0a55e04f21ebf0be9a411a31ee8bb6be69628 /modules/say.py
parent8eb78a9a915cc2fb08905935bb1d26c1a808d4c2 (diff)
downloadmcserver-wrapper-e4b0c7f50efbe0c42aa933cb58a86a44367c1140.tar.gz
mcserver-wrapper-e4b0c7f50efbe0c42aa933cb58a86a44367c1140.tar.bz2
mcserver-wrapper-e4b0c7f50efbe0c42aa933cb58a86a44367c1140.zip
Implemented module version of mcwrapper
mcwrapper functionality split to modules. This is basic implementation of modules handling. Two module types are recognized. For server and commands for mcwrapper cli interface. This way can be implemented different command and server features simply without modifying main script. Interface between main script and modules is defined using service lists. Service list informs main script what function should be called in module. More detailed description should be written to README.md file. Or even separated file describing module interface. In this commit are implemented five different modules. Players and status are server modules. They are used only if mcwrapper is running instance of Minecraft server. Modules say and list-modules are implementing mcwrapper actions. And last module argmodules is implementing mcwrapper argument. For modules usage also added utils.py. This contains shared usable code that is used even by main mcwrapper script.
Diffstat (limited to 'modules/say.py')
-rw-r--r--modules/say.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/modules/say.py b/modules/say.py
new file mode 100644
index 0000000..64810e0
--- /dev/null
+++ b/modules/say.py
@@ -0,0 +1,49 @@
+import sys
+import re
+import utils
+from utils import conf
+
+services = (
+ utils.Service.action,
+ )
+
+def action(args):
+ if conf.action == None:
+ if args[0].lower() != 'say':
+ return False
+ conf.action = 'say'
+ conf.action_module = sys.modules[__name__]
+ conf.sayMessage = []
+ for arg in args[1:]:
+ if conf.identifier == None:
+ conf.identifier = arg
+ else:
+ conf.sayMessage.append(arg)
+ return len(args)
+ else:
+ return 0
+
+def action_exec():
+ if not conf.sayMessage or not conf.identifier:
+ action_full_help()
+ return
+ if not utils.isServerRunning():
+ sys.exit("Server is not running or wrong identifier.")
+ with open(sconf.inputPipe, 'w') as f:
+ f.write("/say " + ' '.join(map(str, sconf.saymessage)) + '\n')
+ f.flush()
+
+def action_help():
+ print(' say')
+ print(' Sends message to Minecraft server chat.')
+
+def action_full_help():
+ print('mcwrapper [arguments...] say IDENTIFIER {message...}')
+ print(' Sends message to Minecraft server chat.')
+ print('')
+ print(' arguments')
+ utils.printArgumentsHelp()
+ print(' IDENTIFIER')
+ print(' Identifier of running server instance.')
+ print(' message')
+ print(' Message to be send to Minecraft server chat.')