forked from indepth666/py3rcon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
py3rcon.py
executable file
·77 lines (60 loc) · 2.45 KB
/
py3rcon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python -B
import os, signal, sys, argparse, threading, json, logging, tempfile, time
import lib
from lib.rconprotocol import Rcon
pid = str(os.getpid())
_DESC = 'Python Rcon CLI for Arma servers'
_VER = '0.2.1'
parser = argparse.ArgumentParser(description=_DESC)
parser.add_argument('configfile', help='configuration file in JSON')
parser.add_argument('-g', '--gui', action='store_true', help='open the GUI - no other events are enabled')
args = parser.parse_args()
GUI = args.gui
if not os.path.isfile(args.configfile):
print('')
print(' -- Configuration not found: "{}" --\n').format(args.configfile)
exit(1)
with open(args.configfile) as json_config:
config = json.load(json_config)
print("py3rcon version: %s - running on %s\n" % (_VER, os.name))
# Logging tool configuration
print('Logging to: {}'.format(config['logfile']))
FORMAT = '%(asctime)-15s %(levelname)s %(message)s'
logging.basicConfig(filename=config['logfile'], level=config['loglevel'], format=FORMAT)
pidfile = '{}/py3rcon.{}.run'.format(tempfile.gettempdir(),config['server']['port'])
if not(GUI):
if os.path.isfile(pidfile):
_tmp = 'pyrcon is already running for %s:%s' % (config['server']['host'], config['server']['port'])
print(_tmp)
logging.info(_tmp)
exit()
open(pidfile, 'w').write(pid)
try:
##
# Initialize the rconprotocol class
##
rcon = Rcon(config['server']['host'], config['server']['rcon_password'], config['server']['port'])
if not(GUI):
# Load the rconrestart module and setup from configuration
rcon.loadmodule('rconrestart', 'RconRestart', config['restart'])
# Load the rconmessage module and setup from configuration
rcon.loadmodule('rconmessage', 'RconMessage', config['repeatMessage'])
# Load the rcon admin commands module
if 'commands' in config: rcon.loadmodule('rconcommand', 'RconCommand', config['commands'])
if 'whitelist' in config:
rcon.loadmodule('rconwhitelist', 'RconWhitelist', config['whitelist'], GUI)
if 'url' in config:
rcon.loadmodule('rconapiwhitelist', 'RconApiWhitelist', config)
if GUI:
rcon.loadmodule('rcongui', 'RconGUI', config)
# connect to server (async)
rcon.connectAsync()
print("Press CTRL + C to Exit")
while rcon.isExit == False:
time.sleep(1)
except (KeyboardInterrupt, SystemExit):
rcon.Abort()
except:
raise
finally:
if not(GUI): os.unlink(pidfile)