forked from Maxi35/pyrelay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientManager.py
More file actions
71 lines (58 loc) · 2.64 KB
/
ClientManager.py
File metadata and controls
71 lines (58 loc) · 2.64 KB
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
import random
import threading
from Client.Client import Client
from PluginManager import callHooks
class ClientManager:
def __init__(self):
self.clients = []
self.updateServers = False
def addClient(self, accInfo):
if "guid" in accInfo.keys() and "password" in accInfo.keys():
if not "secret" in accInfo.keys():
accInfo["secret"] = ""
if accInfo["guid"] == "" or (accInfo["password"] == "" and accInfo["secret"] == ""):
print("Empty email or password, skipping account")
return False
if not "alias" in accInfo.keys():
accInfo["alias"] = accInfo["guid"]
if "proxy" in accInfo.keys():
if not "username" in accInfo["proxy"].keys():
accInfo["proxy"]["username"] = ""
if not "password" in accInfo["proxy"].keys():
accInfo["proxy"]["password"] = ""
client = Client()
client.getToken(accInfo, self.updateServers)
import Constants.Servers as Servers
if not "server" in accInfo.keys():
accInfo["server"] = random.choice(list(Servers.nameToIp.keys()))
print("Server not in account info using server", accInfo["server"], "instead")
if not accInfo["server"] in list(Servers.nameToIp.keys()):
old = accInfo["server"]
accInfo["server"] = random.choice(list(Servers.nameToIp.keys()))
print("Invalid server", old, "using server", accInfo["server"], "instead")
client.setup(accInfo)
client.clientManager = self
client.hookAllPackets(self.onPacket)
self.clients.append(client)
return True
def removeClient(self, guid):
new_clients = []
for client in self.clients:
if client.guid == guid:
client.disconnect()
else:
new_clients.append(client)
self.clients = new_clients
def reconnectIfNeeded(self):
if any(client.active for client in self.clients):
for client in self.clients:
if client.isReady and client.active and not client.isConnected():
client.connect()
else:
return True
def onPacket(self, client, packet):
callHooks(client, packet)
def stop(self):
print("Disconnecting clients...")
for client in self.clients:
client.disconnect()