This repository has been archived by the owner on Aug 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
proxy.py
107 lines (81 loc) · 2.96 KB
/
proxy.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import threading
import pickle
import sys
from multiprocessing import Process
from Logger import Logger
from client import *
from PluginManager import *
from gui import GUI
DEBUG_LENGTH = 10
DEBUG = True
class Proxy:
def __init__(self, pm: PluginManager, client: Client):
self.localHostAddr = "127.0.0.1"
self.localHostPort = 2050 # look up 843 and flash
self.managerSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.pluginManager = pm
self.client = client
self.active = False
self.serverMonitorThread = None
"""
the purpose of this function is to allow client -> proxy then server -> proxy reconnects.
it's in a thread to "monitor" when our client requires a new socket to the proxy
in a sense, it is the server socket.
"""
def ServerMonitor(self):
self.managerSocket.bind((self.localHostAddr, self.localHostPort))
self.managerSocket.listen(3)
# always listening for client connect
while True:
self.client.gameSocket, addr = self.managerSocket.accept()
def Start(self):
self.active = True
# start up server socket
self.serverMonitorThread = threading.Thread(target = self.ServerMonitor, daemon = True)
self.serverMonitorThread.start()
self.Connect()
def Connect(self):
# connect sockets first
self.client.ConnectRemote(self.client.remoteHostAddr, self.client.remoteHostPort)
self.client.connected = True
# listen for packets
while True:
self.client.Listen()
"""
def Restart(self):
self.client.Disconnect()
self.client.ResetCipher()
threading.Thread(target = self.Connect, daemon = False).start()
"""
def main():
print("[Initializer]: Loading plugins...")
plugins = PluginManager()
if not plugins.initialize():
print("Shutting down.")
return
print("[Initializer]: Deserializing objects...")
with open("bin/BulletDictionary.pkl", "rb") as f:
bulletDictionary = pickle.load(f)
print("[Initializer]: Deserialized {} enemies.".format(len(set([x[0] for x in bulletDictionary.keys()]))))
print("[Initializer]: Deserialized {} bullets.".format(len(bulletDictionary)))
with open("bin/NameDictionary.pkl", "rb") as f:
nameDictionary = pickle.load(f)
with open("bin/TileDictionary.pkl", "rb") as f:
tileDictionary = pickle.load(f)
print("[Initializer]: Deserialized {} tiles.".format(len(tileDictionary)))
with open("bin/AoeDictionary.pkl", "rb") as f:
aoeDictionary = pickle.load(f)
print("[Initializer]: Deserialized {} AOEs.".format(sum({y: len(aoeDictionary[y]) for y in aoeDictionary}.values())))
print("[Initializer]: Starting proxy...")
client = Client(plugins, bulletDictionary, nameDictionary, tileDictionary, aoeDictionary)
proxy = Proxy(plugins, client)
threading.Thread(target = proxy.Start, daemon = True).start()
print("[Initializer]: Proxy started!")
print("[Initializer]: Starting GUI...")
gui = GUI(plugins, client, proxy)
print("[Initializer]: GUI started!")
logger = Logger()
logFile = logger.openLogFile()
gui.start()
if __name__ == "__main__":
main()