-
Notifications
You must be signed in to change notification settings - Fork 1
/
rcOREn.py
executable file
·51 lines (39 loc) · 1.59 KB
/
rcOREn.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
#!/usr/bin/env python3
import argparse
import logging
import re
import sys
from typing import List
import rcon
from config import SERVERS, RCON_PASS
_NAME = "rcOREn"
_LOGGER = logging.getLogger(_NAME)
_LOGGER.setLevel(logging.DEBUG)
def run(port: int, command: str, logger):
with rcon.Client('localhost', port, passwd=RCON_PASS) as client:
logger.info(f"Port '{port}': running '{command}'")
response = re.sub(r"""§[0-9a-flmno]""", "", client.run(command))
logger.info(f"Response:\n{response}")
def _run(rcon_ports: List[int], command: str):
for port in rcon_ports:
try:
run(port, command, _LOGGER)
except ConnectionRefusedError as e:
_LOGGER.error(e)
def main():
parser = argparse.ArgumentParser(_NAME)
parser.add_argument("-v", "--verbose", nargs="?", const=True)
required_args = parser.add_argument_group("required arguments")
required_args.add_argument(
"-s", "--servers", help="The server name to run command on.", nargs="+", choices=SERVERS,
required=True)
required_args.add_argument("-c", "--command", help=f"The command to run.", nargs="+", required=True)
args = parser.parse_args()
if args.verbose:
console_handler = logging.StreamHandler(sys.stdout)
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(logging.Formatter('[%(asctime)s] %(name)s - %(levelname)s: %(message)s'))
_LOGGER.addHandler(console_handler)
_run([SERVERS[server]['ports']['rcon'] for server in args.servers], " ".join(args.command))
if __name__ == "__main__":
main()