-
Notifications
You must be signed in to change notification settings - Fork 14
/
pyrelay.py
48 lines (38 loc) · 1.16 KB
/
pyrelay.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
from ClientManager import ClientManager
from PluginManager import loadPlugins
import json
import time
import threading
import argparse
VERSION_PATH = "Resources/version.txt"
EQUIP_PATH = "Resources/equip.xml"
parser = argparse.ArgumentParser(description="pyrelay")
parser.add_argument("-s", "--servers", action="store_true", help="Update the server ips")
args = parser.parse_args()
accounts = []
try:
with open("Accounts.json", "r", encoding="utf-8") as file:
accounts = json.load(file)
except IOError:
print("Missing Accounts.json file")
exit(1)
loadPlugins()
clientMan = ClientManager()
if args.servers:
clientMan.updateServers = True
account_threads = []
for account in accounts:
thread = threading.Thread(target=clientMan.addClient, args=(account,))
thread.daemon = True
thread.start()
account_threads.append(thread)
for thread in account_threads:
thread.join()
try:
while 1:
if clientMan.reconnectIfNeeded():
print("No clients are active - exiting")
break
time.sleep(0.5)
except (KeyboardInterrupt, SystemExit):
clientMan.stop()