Update core.py
Browse files
core.py
CHANGED
|
@@ -22,7 +22,7 @@ bot = None
|
|
| 22 |
|
| 23 |
result_file = None
|
| 24 |
|
| 25 |
-
host = "
|
| 26 |
path = "/"
|
| 27 |
|
| 28 |
CHANGCI = '41'
|
|
@@ -64,26 +64,30 @@ class WebSocketClient:
|
|
| 64 |
|
| 65 |
def login(self, account):
|
| 66 |
self.last_account = account
|
| 67 |
-
|
| 68 |
-
#
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 71 |
|
| 72 |
context = ssl.create_default_context()
|
| 73 |
-
|
|
|
|
| 74 |
wrapped_socket.connect((host, 443))
|
| 75 |
|
| 76 |
key = base64.b64encode(hashlib.sha1(str(id(wrapped_socket)).encode()).digest()[:16])
|
| 77 |
|
|
|
|
| 78 |
request = (
|
| 79 |
f"GET {path} HTTP/1.1\r\n"
|
| 80 |
-
f"Host: b-ww.mjv.jp
|
| 81 |
f"Upgrade: websocket\r\n"
|
| 82 |
f"Connection: Upgrade\r\n"
|
| 83 |
f"Sec-WebSocket-Key: {key.decode()}\r\n"
|
| 84 |
f"Sec-WebSocket-Version: 13\r\n"
|
| 85 |
f"Origin: https://tenhou.net\r\n"
|
| 86 |
-
f"User-Agent:
|
| 87 |
"\r\n"
|
| 88 |
)
|
| 89 |
wrapped_socket.send(request.encode())
|
|
@@ -98,6 +102,16 @@ class WebSocketClient:
|
|
| 98 |
self.send('{"tag":"HELO","name":"' + str(account) + '","sx":"F"}')
|
| 99 |
return wrapped_socket
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def send(self, data):
|
| 102 |
if not self.sock:
|
| 103 |
raise Exception("Socket not connected")
|
|
|
|
| 22 |
|
| 23 |
result_file = None
|
| 24 |
|
| 25 |
+
host = "proxy.warfarinarknights.workers.dev"
|
| 26 |
path = "/"
|
| 27 |
|
| 28 |
CHANGCI = '41'
|
|
|
|
| 64 |
|
| 65 |
def login(self, account):
|
| 66 |
self.last_account = account
|
| 67 |
+
|
| 68 |
+
# 删掉这两行代理相关的代码:
|
| 69 |
+
# socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 4156) # Does not work
|
| 70 |
+
# socket.socket = socks.socksocket
|
| 71 |
+
|
| 72 |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
| 73 |
|
| 74 |
context = ssl.create_default_context()
|
| 75 |
+
# 这里的 server_hostname 必须是你的 CF Worker 域名,否则 SSL 证书校验会失败
|
| 76 |
+
wrapped_socket = context.wrap_socket(sock, server_hostname=host)
|
| 77 |
wrapped_socket.connect((host, 443))
|
| 78 |
|
| 79 |
key = base64.b64encode(hashlib.sha1(str(id(wrapped_socket)).encode()).digest()[:16])
|
| 80 |
|
| 81 |
+
# 注意这里:Host 请求头必须改成你的 CF Worker 域名
|
| 82 |
request = (
|
| 83 |
f"GET {path} HTTP/1.1\r\n"
|
| 84 |
+
f"Host: {host}\r\n" # <--- 从 b-ww.mjv.jp 改成 {host}
|
| 85 |
f"Upgrade: websocket\r\n"
|
| 86 |
f"Connection: Upgrade\r\n"
|
| 87 |
f"Sec-WebSocket-Key: {key.decode()}\r\n"
|
| 88 |
f"Sec-WebSocket-Version: 13\r\n"
|
| 89 |
f"Origin: https://tenhou.net\r\n"
|
| 90 |
+
f"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0\r\n"
|
| 91 |
"\r\n"
|
| 92 |
)
|
| 93 |
wrapped_socket.send(request.encode())
|
|
|
|
| 102 |
self.send('{"tag":"HELO","name":"' + str(account) + '","sx":"F"}')
|
| 103 |
return wrapped_socket
|
| 104 |
|
| 105 |
+
response = wrapped_socket.recv(4096).decode()
|
| 106 |
+
if "101 Switching Protocols" not in response:
|
| 107 |
+
print(response)
|
| 108 |
+
raise Exception("Log in failed:", response)
|
| 109 |
+
|
| 110 |
+
self.sock = wrapped_socket
|
| 111 |
+
print(f'\033[33m尝试登录账号:{account}\033[0m')
|
| 112 |
+
self.send('{"tag":"HELO","name":"' + str(account) + '","sx":"F"}')
|
| 113 |
+
return wrapped_socket
|
| 114 |
+
|
| 115 |
def send(self, data):
|
| 116 |
if not self.sock:
|
| 117 |
raise Exception("Socket not connected")
|