This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClientController.py
102 lines (88 loc) · 3.42 KB
/
ClientController.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
import os
import subprocess
import time
import socket
import logging
import psutil
import win32gui
import win32con
import time
from UDPProxy import UDPProxy
def IsPortInUse( port : int ) -> bool:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(0.1)
portInUseResult = s.connect_ex(('127.0.0.1', port)) == 0
return portInUseResult
class ClientController:
"""
Used for controlling servers which we host off patched clients instead of normal RCCService
"""
ExecutablePath = None
Port = None
Process = None
AttachedUDPProxy = None
JoinScriptUrl = None
StartTimeout = 40
def __init__(self, ExecutablePath : str, JoinscriptUrl : str = "", ExpectedPort : int = 53640, StartTimeout : int = 40):
if IsPortInUse(ExpectedPort):
raise Exception(f"Port {str(ExpectedPort)} is already in use")
self.ExecutablePath = ExecutablePath
self.Port = ExpectedPort
self.JoinScriptUrl = JoinscriptUrl
self.StartTimeout = StartTimeout
self.Start( timeout = StartTimeout )
def BindUDPProxy( self, proxyObj : UDPProxy ):
if self.AttachedUDPProxy is not None:
raise Exception("UDPProxy is already attached")
if proxyObj is None:
raise Exception("proxyObj is None")
self.AttachedUDPProxy = proxyObj
def Start(self, timeout : int = 40):
"""
Starts the client
"""
if self.Process is not None:
raise Exception("Process is already started")
if self.JoinScriptUrl is None:
raise Exception("JoinScriptUrl is None")
startupInfo = subprocess.STARTUPINFO()
startupInfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupInfo.wShowWindow = subprocess.SW_HIDE
self.Process = subprocess.Popen([self.ExecutablePath, "-t", "None", "-j", self.JoinScriptUrl, "-a", "http://www.syntax.eco/Login/Negotiate.ashx"], stdout = subprocess.PIPE, stderr = subprocess.PIPE, startupinfo = startupInfo)
time.sleep(7.5) # Client usually takes about 7.5 seconds to start up
startTime = time.time()
while True:
if time.time() - startTime > timeout:
raise Exception("Client failed to start in time")
if self.Process.poll() is not None:
raise Exception("Client process died")
try:
def EnumWindowsCallback( hwnd, lParam ):
if win32gui.GetWindowText(hwnd) == "ROBLOX":
win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
lParam.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(EnumWindowsCallback, hwnds)
if len(hwnds) > 0:
break
except:
pass
time.sleep(0.1)
logging.info(f"Started client on port {str(self.Port)}")
def Kill(self):
"""
Kills the client
"""
if self.Process is None:
raise Exception("Process has not started")
self.Process.kill()
self.Process = None
if self.AttachedUDPProxy is not None:
self.AttachedUDPProxy.StopUDPProxy()
self.AttachedUDPProxy = None
def KillRCC(self):
return self.Kill()
def __del__(self):
if self.Process is not None:
self.Kill()