From 5af8d89ac7d1e35f014ccd8e40c3d345b7de501a Mon Sep 17 00:00:00 2001
From: drmext <71258889+drmext@users.noreply.github.com>
Date: Sat, 7 Oct 2023 12:06:24 +0000
Subject: [PATCH] Maintenance
---
modules/__init__.py | 61 ++++++++++++++------------------------
modules/core/apsmanager.py | 15 ++++++++++
modules/core/cardmng.py | 6 +---
modules/core/dlstatus.py | 25 ++++++++++++++++
modules/core/eacoin.py | 10 +++++++
modules/core/ins.py | 25 ++++++++++++++++
modules/core/package.py | 17 +++++++----
modules/core/package2.py | 15 ++++++++++
modules/core/pcbevent.py | 6 +---
modules/core/pcbtracker.py | 4 +++
pyeamu.py | 28 +++++++----------
start.bat | 14 ++++++---
start.sh | 17 ++++++-----
13 files changed, 161 insertions(+), 82 deletions(-)
create mode 100644 modules/core/apsmanager.py
create mode 100644 modules/core/dlstatus.py
create mode 100644 modules/core/ins.py
create mode 100644 modules/core/package2.py
diff --git a/modules/__init__.py b/modules/__init__.py
index d0dbeab..1146fb1 100644
--- a/modules/__init__.py
+++ b/modules/__init__.py
@@ -26,23 +26,8 @@ for module_path in [
router = APIRouter(tags=["slashless_forwarder"])
-@router.post("/core_fwdr")
-async def forward_core(
- request: Request,
- f: Optional[str] = None,
- module: Optional[str] = None,
- method: Optional[str] = None,
-):
- if f != None:
- module, method = f.split(".")
-
- find_response = globals()[f"{module}_{method}"]
-
- return await find_response(request)
-
-
@router.post("/fwdr")
-async def forward_game(
+async def forward_slashless(
request: Request,
model: Optional[str] = None,
f: Optional[str] = None,
@@ -52,30 +37,30 @@ async def forward_game(
if f != None:
module, method = f.split(".")
- game_code = model.split(":")[0]
-
- # TODO: check for more edge cases
try:
- if game_code == "MDX" and module == "eventlog" or module == "eventlog_2":
- find_response = globals()[f"ddr_{module}_{method}"]
- elif game_code == "REC":
- find_response = globals()[f"drs_{module}_{method}"]
- elif game_code == "KFC" and module == "eventlog":
- find_response = globals()[f"sdvx_{module}_{method}"]
- elif game_code == "M32":
- if module == "lobby":
- find_response = globals()[f"gitadora_{module}_{method}"]
- else:
- gd_module = module.split("_")
- find_response = globals()[f"gitadora_{gd_module[-1]}_{method}"]
- return await find_response(gd_module[0], request)
- else:
- find_response = globals()[f"{module}_{method}".lower()]
+ find_response = globals()[f"{module}_{method}".lower()]
+ return await find_response(request)
except KeyError:
- print("Try URL Slash 1 (On) if this game is supported.")
- return Response(status_code=404)
-
- return await find_response(request)
+ try:
+ game_code = model.split(":")[0]
+ # TODO: check for more edge cases
+ if game_code == "MDX" and module == "eventlog" or module == "eventlog_2":
+ find_response = globals()[f"ddr_{module}_{method}"]
+ elif game_code == "REC":
+ find_response = globals()[f"drs_{module}_{method}"]
+ elif game_code == "KFC" and module == "eventlog":
+ find_response = globals()[f"sdvx_{module}_{method}"]
+ elif game_code == "M32":
+ if module == "lobby":
+ find_response = globals()[f"gitadora_{module}_{method}"]
+ else:
+ gd_module = module.split("_")
+ find_response = globals()[f"gitadora_{gd_module[-1]}_{method}"]
+ return await find_response(gd_module[0], request)
+ return await find_response(request)
+ except (KeyError, UnboundLocalError):
+ print("Try URL Slash 1 (On) if this game is supported.")
+ return Response(status_code=404)
routers.append(router)
diff --git a/modules/core/apsmanager.py b/modules/core/apsmanager.py
new file mode 100644
index 0000000..812bd7a
--- /dev/null
+++ b/modules/core/apsmanager.py
@@ -0,0 +1,15 @@
+from fastapi import APIRouter, Request, Response
+
+from core_common import core_process_request, core_prepare_response, E
+
+router = APIRouter(prefix="/core", tags=["apsmanager"])
+
+
+@router.post("/{gameinfo}/apsmanager/getstat")
+async def apsmanager_getstat(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.apsmanager(expire=600))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/cardmng.py b/modules/core/cardmng.py
index 23533d1..cc2322a 100644
--- a/modules/core/cardmng.py
+++ b/modules/core/cardmng.py
@@ -76,11 +76,7 @@ async def cardmng_authpass(request: Request):
async def cardmng_bindmodel(request: Request):
request_info = await core_process_request(request)
- response = E.response(
- E.bindmodel(
- dataid=1,
- )
- )
+ response = E.response(E.bindmodel(dataid=1))
response_body, response_headers = await core_prepare_response(request, response)
return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/dlstatus.py b/modules/core/dlstatus.py
new file mode 100644
index 0000000..db92a4c
--- /dev/null
+++ b/modules/core/dlstatus.py
@@ -0,0 +1,25 @@
+from fastapi import APIRouter, Request, Response
+
+from core_common import core_process_request, core_prepare_response, E
+
+router = APIRouter(prefix="/core", tags=["dlstatus"])
+
+
+@router.post("/{gameinfo}/dlstatus/done")
+async def dlstatus_done(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.dlstatus(status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
+
+
+@router.post("/{gameinfo}/dlstatus/progress")
+async def dlstatus_progress(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.dlstatus(status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/eacoin.py b/modules/core/eacoin.py
index 260cfdc..030cc59 100644
--- a/modules/core/eacoin.py
+++ b/modules/core/eacoin.py
@@ -27,6 +27,16 @@ async def eacoin_checkin(request: Request):
return Response(content=response_body, headers=response_headers)
+@router.post("/{gameinfo}/eacoin/checkout")
+async def eacoin_checkout(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.eacoin())
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
+
+
@router.post("/{gameinfo}/eacoin/consume")
async def eacoin_consume(request: Request):
request_info = await core_process_request(request)
diff --git a/modules/core/ins.py b/modules/core/ins.py
new file mode 100644
index 0000000..697233d
--- /dev/null
+++ b/modules/core/ins.py
@@ -0,0 +1,25 @@
+from fastapi import APIRouter, Request, Response
+
+from core_common import core_process_request, core_prepare_response, E
+
+router = APIRouter(prefix="/core", tags=["ins"])
+
+
+@router.post("/{gameinfo}/ins/netlog")
+async def ins_netlog(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.netlog(status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
+
+
+@router.post("/{gameinfo}/ins/send")
+async def ins_send(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.netlog(status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/package.py b/modules/core/package.py
index 6801d9b..c24be9d 100644
--- a/modules/core/package.py
+++ b/modules/core/package.py
@@ -9,12 +9,17 @@ router = APIRouter(prefix="/core", tags=["package"])
async def package_list(request: Request):
request_info = await core_process_request(request)
- response = E.response(
- E.package(
- expire=600,
- status=0,
- )
- )
+ response = E.response(E.package(expire=1200, status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
+
+
+@router.post("/{gameinfo}/package/intend")
+async def package_intend(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.package(status=0))
response_body, response_headers = await core_prepare_response(request, response)
return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/package2.py b/modules/core/package2.py
new file mode 100644
index 0000000..4ba8054
--- /dev/null
+++ b/modules/core/package2.py
@@ -0,0 +1,15 @@
+from fastapi import APIRouter, Request, Response
+
+from core_common import core_process_request, core_prepare_response, E
+
+router = APIRouter(prefix="/core", tags=["package2"])
+
+
+@router.post("/{gameinfo}/package2/list")
+async def package2_list(request: Request):
+ request_info = await core_process_request(request)
+
+ response = E.response(E.package2(expire=1200, status=0))
+
+ response_body, response_headers = await core_prepare_response(request, response)
+ return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/pcbevent.py b/modules/core/pcbevent.py
index 029bfd7..3d47caf 100644
--- a/modules/core/pcbevent.py
+++ b/modules/core/pcbevent.py
@@ -9,11 +9,7 @@ router = APIRouter(prefix="/core", tags=["pcbevent"])
async def pcbevent_put(request: Request):
request_info = await core_process_request(request)
- response = E.response(
- E.pcbevent(
- expire=600,
- )
- )
+ response = E.response(E.pcbevent(expire=600))
response_body, response_headers = await core_prepare_response(request, response)
return Response(content=response_body, headers=response_headers)
diff --git a/modules/core/pcbtracker.py b/modules/core/pcbtracker.py
index 478037d..51f8cf9 100644
--- a/modules/core/pcbtracker.py
+++ b/modules/core/pcbtracker.py
@@ -1,5 +1,7 @@
import config
+from time import time
+
from fastapi import APIRouter, Request, Response
from core_common import core_process_request, core_prepare_response, E
@@ -13,10 +15,12 @@ async def pcbtracker_alive(request: Request):
response = E.response(
E.pcbtracker(
+ status=0,
expire=1200,
ecenable=not config.maintenance_mode,
eclimit=0,
limit=0,
+ time=int(time()),
)
)
diff --git a/pyeamu.py b/pyeamu.py
index 3ca308b..e47a1e1 100644
--- a/pyeamu.py
+++ b/pyeamu.py
@@ -97,14 +97,15 @@ if __name__ == "__main__":
for server_services_url in server_services_urls:
print(f"\033[92m{server_services_url}\033[0m")
print("")
- # print('\033[92m0\033[0m')
- # print('\033[92m1\033[0m')
print()
+ print("\033[1mWeb Interface\033[0m:")
if webui:
- print("\033[1mWeb Interface\033[0m:")
for server_address in server_addresses:
print(f"http://{server_address}/webui/")
- print()
+ 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()
@@ -145,20 +146,13 @@ async def services_get(
k = (service.tags[0] if service.tags else service.prefix).strip("/")
if f == "services.get" or module == "services" and method == "get":
- if service.prefix == "/core":
- non_slash_prefix = "/core_fwdr"
- else:
- non_slash_prefix = "/fwdr"
- if k not in services:
- services[k] = urlunparse(
- ("http", request_address, non_slash_prefix, None, None, None)
- )
- # url_slash
+ # url_slash 0
+ pre = "/fwdr"
else:
- if k not in services:
- services[k] = urlunparse(
- ("http", request_address, service.prefix, None, None, None)
- )
+ # 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,
diff --git a/start.bat b/start.bat
index 1ac2f6f..49e233c 100644
--- a/start.bat
+++ b/start.bat
@@ -1,32 +1,38 @@
@echo off
+TITLE MB
+
cd /d %~dp0
-if exist .venv\Lib\site-packages\ujson*.pyd (
+if exist .venv\Scripts\activate.bat (
(
REM goto :make_venv_portable
:start_server
- .venv\Scripts\activate.bat && python pyeamu.py
+ .venv\Scripts\activate.bat
+ python pyeamu.py
)
) else (
(
:create_venv
python -m venv .venv
.venv\Scripts\activate.bat
- pip install -U -r requirements.txt
+ python -m pip install -U -r requirements.txt
python pyeamu.py
)
)
echo:
echo Install python with "Add python.exe to PATH" checked
-echo https://www.python.org/ftp/python/3.11.4/python-3.11.4-amd64.exe
+echo https://www.python.org/downloads/
+echo:
+echo Note: Choose the previous version if latest is 3.xx.0
echo:
pause
goto :eof
+REM breaks when special characters are in path
:make_venv_portable
set pyvenv="%~dp0.venv\pyvenv.cfg"
set pyvenvtemp="%~dp0.venv\pyvenv.tmp"
diff --git a/start.sh b/start.sh
index 17dd396..b15c591 100644
--- a/start.sh
+++ b/start.sh
@@ -1,18 +1,21 @@
#!/bin/bash
-if ! command -v python3.11 &> /dev/null
+ver="3.11"
+py="python$ver"
+
+if ! command -v $py &> /dev/null
then
- echo "python3.11 not found"
+ echo "$py not found"
exit
fi
-if [ -e .venv/lib/python3.11/site-packages/ujson*.so ]
+if [ -d .venv/ ]
then
source .venv/bin/activate
- python pyeamu.py
+ $py pyeamu.py
else
- python3.11 -m venv .venv
+ $py -m venv .venv
source .venv/bin/activate
- pip install -U -r requirements.txt
- python pyeamu.py
+ $py -m pip install -U -r requirements.txt
+ $py pyeamu.py
fi