forked from Hay1tsme/artemis
mai: fix pre-dx
This commit is contained in:
parent
d024b2eeb8
commit
8c0ebbd21b
@ -117,16 +117,14 @@ class Mai2Servlet(BaseServlet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_allnet_info(self, game_code: str, game_ver: int, keychip: str) -> Tuple[str, str]:
|
def get_allnet_info(self, game_code: str, game_ver: int, keychip: str) -> Tuple[str, str]:
|
||||||
servlet_name = "" if game_code == Mai2Constants.GAME_CODE_DX else "MaimaiServlet/"
|
|
||||||
|
|
||||||
if not self.core_cfg.server.is_using_proxy and Utils.get_title_port(self.core_cfg) != 80:
|
if not self.core_cfg.server.is_using_proxy and Utils.get_title_port(self.core_cfg) != 80:
|
||||||
return (
|
return (
|
||||||
f"http://{self.core_cfg.title.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_ver}/{servlet_name}",
|
f"http://{self.core_cfg.title.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_ver}/",
|
||||||
f"{self.core_cfg.title.hostname}",
|
f"{self.core_cfg.title.hostname}",
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
f"http://{self.core_cfg.title.hostname}/{game_ver}/{servlet_name}",
|
f"http://{self.core_cfg.title.hostname}/{game_ver}/",
|
||||||
f"{self.core_cfg.title.hostname}",
|
f"{self.core_cfg.title.hostname}",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -155,7 +153,7 @@ class Mai2Servlet(BaseServlet):
|
|||||||
f"Failed to make movie upload directory at {self.game_cfg.uploads.movies_dir}"
|
f"Failed to make movie upload directory at {self.game_cfg.uploads.movies_dir}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_mai2(self, request: Request, game_code: str, matchers: Dict) -> bytes:
|
def handle_mai(self, request: Request, game_code: str, matchers: Dict) -> bytes:
|
||||||
endpoint = matchers['endpoint']
|
endpoint = matchers['endpoint']
|
||||||
version = int(matchers['version'])
|
version = int(matchers['version'])
|
||||||
if endpoint.lower() == "ping":
|
if endpoint.lower() == "ping":
|
||||||
@ -165,25 +163,6 @@ class Mai2Servlet(BaseServlet):
|
|||||||
internal_ver = 0
|
internal_ver = 0
|
||||||
client_ip = Utils.get_ip_addr(request)
|
client_ip = Utils.get_ip_addr(request)
|
||||||
|
|
||||||
if game_code == "SDEZ":
|
|
||||||
if version < 105: # 1.0
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX
|
|
||||||
elif version >= 105 and version < 110: # PLUS
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_PLUS
|
|
||||||
elif version >= 110 and version < 115: # Splash
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH
|
|
||||||
elif version >= 115 and version < 120: # Splash PLUS
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH_PLUS
|
|
||||||
elif version >= 120 and version < 125: # UNiVERSE
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE
|
|
||||||
elif version >= 125 and version < 130: # UNiVERSE PLUS
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE_PLUS
|
|
||||||
elif version >= 130 and version < 135: # FESTiVAL
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL
|
|
||||||
elif version >= 135: # FESTiVAL PLUS
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL_PLUS
|
|
||||||
|
|
||||||
else:
|
|
||||||
if version < 110: # 1.0
|
if version < 110: # 1.0
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI
|
internal_ver = Mai2Constants.VER_MAIMAI
|
||||||
elif version >= 110 and version < 120: # Plus
|
elif version >= 110 and version < 120: # Plus
|
||||||
@ -211,6 +190,69 @@ class Mai2Servlet(BaseServlet):
|
|||||||
elif version >= 197: # Finale
|
elif version >= 197: # Finale
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_FINALE
|
internal_ver = Mai2Constants.VER_MAIMAI_FINALE
|
||||||
|
|
||||||
|
try:
|
||||||
|
unzip = zlib.decompress(req_raw)
|
||||||
|
|
||||||
|
except zlib.error as e:
|
||||||
|
self.logger.error(
|
||||||
|
f"Failed to decompress v{version} {endpoint} request -> {e}"
|
||||||
|
)
|
||||||
|
return zlib.compress(b'{"stat": "0"}')
|
||||||
|
|
||||||
|
req_data = json.loads(unzip)
|
||||||
|
|
||||||
|
self.logger.info(f"v{version} {endpoint} request from {client_ip}")
|
||||||
|
self.logger.debug(req_data)
|
||||||
|
|
||||||
|
func_to_find = "handle_" + inflection.underscore(endpoint) + "_request"
|
||||||
|
handler_cls = self.versions[internal_ver](self.core_cfg, self.game_cfg)
|
||||||
|
|
||||||
|
if not hasattr(handler_cls, func_to_find):
|
||||||
|
self.logger.warning(f"Unhandled v{version} request {endpoint}")
|
||||||
|
resp = {"returnCode": 1}
|
||||||
|
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
handler = getattr(handler_cls, func_to_find)
|
||||||
|
resp = handler(req_data)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"Error handling v{version} method {endpoint} - {e}")
|
||||||
|
return zlib.compress(b'{"returnCode": "0"}')
|
||||||
|
|
||||||
|
if resp == None:
|
||||||
|
resp = {"returnCode": 1}
|
||||||
|
|
||||||
|
self.logger.debug(f"Response {resp}")
|
||||||
|
|
||||||
|
return zlib.compress(json.dumps(resp, ensure_ascii=False).encode("utf-8"))
|
||||||
|
|
||||||
|
def handle_mai2(self, request: Request, game_code: str, matchers: Dict) -> bytes:
|
||||||
|
endpoint = matchers['endpoint']
|
||||||
|
version = int(matchers['version'])
|
||||||
|
if endpoint.lower() == "ping":
|
||||||
|
return zlib.compress(b'{"returnCode": "1"}')
|
||||||
|
|
||||||
|
req_raw = request.content.getvalue()
|
||||||
|
internal_ver = 0
|
||||||
|
client_ip = Utils.get_ip_addr(request)
|
||||||
|
if version < 105: # 1.0
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX
|
||||||
|
elif version >= 105 and version < 110: # PLUS
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_PLUS
|
||||||
|
elif version >= 110 and version < 115: # Splash
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH
|
||||||
|
elif version >= 115 and version < 120: # Splash PLUS
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH_PLUS
|
||||||
|
elif version >= 120 and version < 125: # UNiVERSE
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE
|
||||||
|
elif version >= 125 and version < 130: # UNiVERSE PLUS
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE_PLUS
|
||||||
|
elif version >= 130 and version < 135: # FESTiVAL
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL
|
||||||
|
elif version >= 135: # FESTiVAL PLUS
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL_PLUS
|
||||||
|
|
||||||
if (
|
if (
|
||||||
request.getHeader("Mai-Encoding") is not None
|
request.getHeader("Mai-Encoding") is not None
|
||||||
or request.getHeader("X-Mai-Encoding") is not None
|
or request.getHeader("X-Mai-Encoding") is not None
|
||||||
|
Loading…
Reference in New Issue
Block a user