forked from Dniel97/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,51 +163,95 @@ 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 < 110: # 1.0
|
||||||
if version < 105: # 1.0
|
internal_ver = Mai2Constants.VER_MAIMAI
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX
|
elif version >= 110 and version < 120: # Plus
|
||||||
elif version >= 105 and version < 110: # PLUS
|
internal_ver = Mai2Constants.VER_MAIMAI_PLUS
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_PLUS
|
elif version >= 120 and version < 130: # Green
|
||||||
elif version >= 110 and version < 115: # Splash
|
internal_ver = Mai2Constants.VER_MAIMAI_GREEN
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH
|
elif version >= 130 and version < 140: # Green Plus
|
||||||
elif version >= 115 and version < 120: # Splash PLUS
|
internal_ver = Mai2Constants.VER_MAIMAI_GREEN_PLUS
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_SPLASH_PLUS
|
elif version >= 140 and version < 150: # Orange
|
||||||
elif version >= 120 and version < 125: # UNiVERSE
|
internal_ver = Mai2Constants.VER_MAIMAI_ORANGE
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE
|
elif version >= 150 and version < 160: # Orange Plus
|
||||||
elif version >= 125 and version < 130: # UNiVERSE PLUS
|
internal_ver = Mai2Constants.VER_MAIMAI_ORANGE_PLUS
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_UNIVERSE_PLUS
|
elif version >= 160 and version < 170: # Pink
|
||||||
elif version >= 130 and version < 135: # FESTiVAL
|
internal_ver = Mai2Constants.VER_MAIMAI_PINK
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL
|
elif version >= 170 and version < 180: # Pink Plus
|
||||||
elif version >= 135: # FESTiVAL PLUS
|
internal_ver = Mai2Constants.VER_MAIMAI_PINK_PLUS
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_DX_FESTIVAL_PLUS
|
elif version >= 180 and version < 185: # Murasaki
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_MURASAKI
|
||||||
|
elif version >= 185 and version < 190: # Murasaki Plus
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_MURASAKI_PLUS
|
||||||
|
elif version >= 190 and version < 195: # Milk
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_MILK
|
||||||
|
elif version >= 195 and version < 197: # Milk Plus
|
||||||
|
internal_ver = Mai2Constants.VER_MAIMAI_MILK_PLUS
|
||||||
|
elif version >= 197: # 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:
|
else:
|
||||||
if version < 110: # 1.0
|
try:
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI
|
handler = getattr(handler_cls, func_to_find)
|
||||||
elif version >= 110 and version < 120: # Plus
|
resp = handler(req_data)
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_PLUS
|
|
||||||
elif version >= 120 and version < 130: # Green
|
except Exception as e:
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_GREEN
|
self.logger.error(f"Error handling v{version} method {endpoint} - {e}")
|
||||||
elif version >= 130 and version < 140: # Green Plus
|
return zlib.compress(b'{"returnCode": "0"}')
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_GREEN_PLUS
|
|
||||||
elif version >= 140 and version < 150: # Orange
|
if resp == None:
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_ORANGE
|
resp = {"returnCode": 1}
|
||||||
elif version >= 150 and version < 160: # Orange Plus
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_ORANGE_PLUS
|
self.logger.debug(f"Response {resp}")
|
||||||
elif version >= 160 and version < 170: # Pink
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_PINK
|
return zlib.compress(json.dumps(resp, ensure_ascii=False).encode("utf-8"))
|
||||||
elif version >= 170 and version < 180: # Pink Plus
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_PINK_PLUS
|
def handle_mai2(self, request: Request, game_code: str, matchers: Dict) -> bytes:
|
||||||
elif version >= 180 and version < 185: # Murasaki
|
endpoint = matchers['endpoint']
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_MURASAKI
|
version = int(matchers['version'])
|
||||||
elif version >= 185 and version < 190: # Murasaki Plus
|
if endpoint.lower() == "ping":
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_MURASAKI_PLUS
|
return zlib.compress(b'{"returnCode": "1"}')
|
||||||
elif version >= 190 and version < 195: # Milk
|
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_MILK
|
req_raw = request.content.getvalue()
|
||||||
elif version >= 195 and version < 197: # Milk Plus
|
internal_ver = 0
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_MILK_PLUS
|
client_ip = Utils.get_ip_addr(request)
|
||||||
elif version >= 197: # Finale
|
if version < 105: # 1.0
|
||||||
internal_ver = Mai2Constants.VER_MAIMAI_FINALE
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user