This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyeamu.py
219 lines (177 loc) · 5.77 KB
/
pyeamu.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from urllib.parse import urlparse, urlunparse, urlencode
import uvicorn
import ujson as json
from os import name, path
from typing import Optional
from fastapi import FastAPI, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from starlette.responses import RedirectResponse
import config
import modules
import utils.card as conv
from core_common import core_process_request, core_prepare_response, E
import socket
def urlpathjoin(parts, sep="/"):
return sep + sep.join([x.lstrip(sep) for x in parts])
loopback = "127.0.0.1"
server_addresses = []
for host in ("localhost", config.ip, socket.gethostname()):
server_addresses.append(f"{host}:{config.port}")
server_services_urls = []
for server_address in server_addresses:
server_services_urls.append(
urlunparse(("http", server_address, config.services_prefix, None, None, None))
)
settings = {}
for s in (
"ip",
"port",
"services_prefix",
"verbose_log",
"arcade",
"paseli",
"maintenance_mode",
):
settings[s] = getattr(config, s)
app = FastAPI()
for router in modules.routers:
app.include_router(router)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
if path.exists("webui"):
webui = True
with open(path.join("webui", "monkey.json"), "w") as f:
json.dump(settings, f, indent=2, escape_forward_slashes=False)
app.mount("/webui", StaticFiles(directory="webui", html=True), name="webui")
else:
webui = False
@app.get("/webui")
async def redirect_to_config():
return RedirectResponse(url="/config")
# Enable ANSI escape sequences
if name == "nt":
import ctypes
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
if __name__ == "__main__":
print(
"""
█▄ ▄█ █▀█ █▄ █ █▄▀ ▀██ ▀▄▀
█ ▀ █ █▄█ █ ▀█ █ █ ▄▄█ █
██▄ █ █ ▄▀▀ ▄█ █▄ █ ▀██ ▀█▀
█▄█ ▀▄█ ▄██ █ █ ▀█ ▄▄█ █▄▄
"""
)
print()
print("\033[1mGame Config\033[0m:")
for server_services_url in server_services_urls:
print(f"<services>\033[92m{server_services_url}\033[0m</services>")
print("<!-- url_slash \033[92m0\033[0m or \033[92m1\033[0m -->")
print()
print("\033[1mWeb Interface\033[0m:")
if webui:
for server_address in server_addresses:
print(f"http://{server_address}/webui/")
else:
print("/webui missing")
print("download it here: https://github.com/drmext/BounceTrippy/releases")
print()
print("\033[1mSource Repository\033[0m:")
print("https://github.com/drmext/MonkeyBusiness")
print()
uvicorn.run("pyeamu:app", host="0.0.0.0", port=config.port, reload=True)
@app.post(urlpathjoin([config.services_prefix]))
@app.post(urlpathjoin([config.services_prefix, "/{gameinfo}/services/get"]))
async def services_get(
request: Request,
model: Optional[str] = None,
f: Optional[str] = None,
module: Optional[str] = None,
method: Optional[str] = None,
):
request_info = await core_process_request(request)
request_address = f"{urlparse(str(request.url)).netloc}:{config.port}"
services = {}
for service in modules.routers:
model_blacklist = services.get("model_blacklist", [])
model_whitelist = services.get("model_whitelist", [])
if request_info["model"] in model_blacklist:
continue
if model_whitelist and request_info["model"] not in model_whitelist:
continue
if (
service.tags
and service.tags[0].startswith("api_")
or service.tags[0] == "slashless_forwarder"
):
continue
k = (service.tags[0] if service.tags else service.prefix).strip("/")
if f == "services.get" or module == "services" and method == "get":
# url_slash 0
pre = "/fwdr"
else:
# url_slash 1
pre = service.prefix
if k not in services:
services[k] = urlunparse(("http", request_address, pre, None, None, None))
keepalive_params = {
"pa": loopback,
"ia": loopback,
"ga": loopback,
"ma": loopback,
"t1": 2,
"t2": 10,
}
services["keepalive"] = urlunparse(
(
"http",
loopback,
"/keepalive",
None,
urlencode(keepalive_params),
None,
)
)
services["ntp"] = urlunparse(("ntp", "pool.ntp.org", "/", None, None, None))
response = E.response(
E.services(
expire=10800,
mode="operation",
product_domain=1,
*[E.item(name=k, url=services[k]) for k in services],
)
)
response_body, response_headers = await core_prepare_response(request, response)
return Response(content=response_body, headers=response_headers)
@app.get("/")
async def redirect_to_webui():
return RedirectResponse(url="/webui")
@app.get("/config")
async def get_config():
return settings
@app.get("/conv/{card}")
async def card_conv(card: str):
card = card.upper()
lookalike = {
"I": "1",
"O": "0",
"Q": "0",
"V": "U",
}
for k, v in lookalike.items():
card = card.replace(k, v)
if card.startswith("E004") or card.startswith("012E"):
card = "".join([c for c in card if c in "0123456789ABCDEF"])
uid = card
kid = conv.to_konami_id(card)
else:
card = "".join([c for c in card if c in conv.valid_characters])
uid = conv.to_uid(card)
kid = card
return {"uid": uid, "konami_id": kid}