aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-09-15 09:52:25 +0200
committerKarel Kočí <cynerd@email.cz>2015-11-07 11:45:16 +0100
commit9a999c599dad8375d66531bd20c9e4ea0b642845 (patch)
tree7015a15d0176f9d590fc53e31a840a2b85ae0650
parente4b0c7f50efbe0c42aa933cb58a86a44367c1140 (diff)
downloadmcserver-wrapper-9a999c599dad8375d66531bd20c9e4ea0b642845.tar.gz
mcserver-wrapper-9a999c599dad8375d66531bd20c9e4ea0b642845.tar.bz2
mcserver-wrapper-9a999c599dad8375d66531bd20c9e4ea0b642845.zip
Implement new module printconf
-rw-r--r--mcwrapper.conf14
-rw-r--r--modules/printconf.py51
-rwxr-xr-xservert73
3 files changed, 138 insertions, 0 deletions
diff --git a/mcwrapper.conf b/mcwrapper.conf
new file mode 100644
index 0000000..a07b594
--- /dev/null
+++ b/mcwrapper.conf
@@ -0,0 +1,14 @@
+# This is exaple configuration for mcwrapper
+# Use Python3 syntax to specify configuration.
+# For full list of configuration options refer to documentation.
+
+modules = {'say', 'argmodules', 'list-modules', 'printconf'}
+identifier = 'srv'
+
+server = dict()
+server["srv"] = {
+ "command": "cd srv && java -jar mcs.jar nogui",
+ "modules": {'status', 'players'},
+ "folder": '/dev/shm/mcwrapper-srv',
+ "logOutput": False,
+ }
diff --git a/modules/printconf.py b/modules/printconf.py
new file mode 100644
index 0000000..708c421
--- /dev/null
+++ b/modules/printconf.py
@@ -0,0 +1,51 @@
+import os
+import sys
+import re
+import utils
+from utils import conf
+
+services = (
+ utils.Service.argument,
+ utils.Service.action,
+ )
+
+__conf_file__ = False
+
+def argument(args):
+ global __conf_file__
+ if args[0] == '--file':
+ __conf_file__ = True
+ return 1
+
+def argument_short(l, args):
+ return 0
+
+def argument_exec():
+ conf.argument_conffile = __conf_file__
+
+def argument_help():
+ if conf.action == 'config':
+ print(' --file')
+ print(' Print only used configuration file.')
+
+def action(args):
+ if conf.action == None and args[0].lower() == 'config':
+ conf.action = 'config'
+ conf.action_module = sys.modules[__name__]
+ return 1
+ return 0
+
+def action_exec():
+ if conf.argument_conffile:
+ try:
+ print(conf.__file__)
+ except AttributeError:
+ print('Default configuration used. No file associated.')
+ else:
+ print('TODO')
+
+def action_help():
+ pass
+
+def action_full_help():
+ pass
diff --git a/servert b/servert
new file mode 100755
index 0000000..3213373
--- /dev/null
+++ b/servert
@@ -0,0 +1,73 @@
+#!/usr/bin/env python3
+import os
+import sys
+import socket
+from threading import Thread
+import importlib.machinery as imp
+
+class conf:
+ modulesFolder = 'modules'
+ localip = '127.0.0.1'
+ localport = 25565
+ remoteip = '192.168.1.145'
+ remoteport = 25566
+
+# Load modules utils
+utils = imp.SourceFileLoader("utils",
+ conf.modulesFolder + '/utils.py').load_module()
+
+__players__ = set()
+
+class Packet:
+ def __init__(self, sizeoffset, bsize, data):
+ #print(sizeoffset)
+ #print(bsize)
+ pass
+
+class Player:
+ class Connection(Thread):
+ def __init__(self, source, target, player, direction):
+ Thread.__init__(self, name="PlayerConnection" + str(direction))
+ self.source = source
+ self.target = target
+ self.player = player
+ def run(self):
+ while True:
+ i = 0
+ packet_size = 0
+ nextbt = True
+ data = self.source.recv(1)
+ if not data: break
+ while nextbt:
+ bt = data[i]
+ nextbt = bool(bt & (1 << 7))
+ bt = bt & ~(1 << 7)
+ packet_size = packet_size | (bt << (i * 7))
+ if nextbt:
+ data += self.source.recv(1)
+ i += 1
+ data += self.source.recv(packet_size)
+ Packet(i, packet_size, data)
+ self.target.send(data)
+ def __init__(self, conn, addr):
+ self.conn = conn
+ self.addr = addr
+ self.s = socket.socket()
+ self.s.connect((conf.remoteip, conf.remoteport))
+ self.t_left = Player.Connection(conn, self.s, self, 1)
+ self.t_right = Player.Connection(self.s, conn, self, 2)
+ self.t_left.start()
+ self.t_right.start()
+
+def fakeserver():
+ s = socket.socket()
+ s.bind((conf.localip, conf.localport))
+ s.listen(2)
+ #while True:
+ conn, addr = s.accept()
+ __players__.add(Player(conn, addr))
+
+#################################################################################
+
+if __name__ == '__main__':
+ fakeserver()