Added Sun Plus support, and Int workaround

Int versions of Chunithm use nearly the same endpoints, just with C3Exp at the end. We can treat them the same as the regular versions of the game for now by simply removing the C3Exp portion of the endpoints and running our current logic. Note that later we should treat Int and JP as separate versions
This commit is contained in:
EmmyHeart 2023-12-13 06:01:31 +00:00
parent 32362dbe1e
commit 15204f8d8a

View File

@ -31,6 +31,7 @@ from .paradise import ChuniParadise
from .new import ChuniNew from .new import ChuniNew
from .newplus import ChuniNewPlus from .newplus import ChuniNewPlus
from .sun import ChuniSun from .sun import ChuniSun
from .sunplus import ChuniSunPlus
class ChuniServlet(BaseServlet): class ChuniServlet(BaseServlet):
@ -58,6 +59,7 @@ class ChuniServlet(BaseServlet):
ChuniNew, ChuniNew,
ChuniNewPlus, ChuniNewPlus,
ChuniSun, ChuniSun,
ChuniSunPlus,
] ]
self.logger = logging.getLogger("chuni") self.logger = logging.getLogger("chuni")
@ -120,8 +122,8 @@ class ChuniServlet(BaseServlet):
return ( return (
[], [],
[ [
("render_POST", "/{version}/ChuniServlet/{endpoint}", {}), ("render_POST", "/{game}/{version}/ChuniServlet/{endpoint}", {}),
("render_POST", "/{version}/ChuniServlet/MatchingServer/{endpoint}", {}) ("render_POST", "/{game}/{version}/ChuniServlet/MatchingServer/{endpoint}", {})
] ]
) )
@ -142,50 +144,66 @@ class ChuniServlet(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]:
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 (f"http://{self.core_cfg.title.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_ver}/", self.core_cfg.title.hostname) return (f"http://{self.core_cfg.title.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_code}/{game_ver}/", self.core_cfg.title.hostname)
return (f"http://{self.core_cfg.title.hostname}/{game_ver}/", self.core_cfg.title.hostname) return (f"http://{self.core_cfg.title.hostname}/{game_code}/{game_ver}/", self.core_cfg.title.hostname)
def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes: def render_POST(self, request: Request, game_code: str, matchers: Dict) -> bytes:
endpoint = matchers['endpoint'] endpoint = matchers['endpoint']
version = int(matchers['version']) version = int(matchers['version'])
game_code = matchers['game']
if endpoint.lower() == "ping": if endpoint.lower() == "ping":
return zlib.compress(b'{"returnCode": "1"}') return zlib.compress(b'{"returnCode": "1"}')
req_raw = request.content.getvalue() req_raw = request.content.getvalue()
encrtped = False encrtped = False
internal_ver = 0 internal_ver = 0
client_ip = Utils.get_ip_addr(request) client_ip = Utils.get_ip_addr(request)
if version < 105: # 1.0 if game_code == "SDHD" or game_code == "SDBT": # JP
internal_ver = ChuniConstants.VER_CHUNITHM if version < 105: # 1.0
elif version >= 105 and version < 110: # PLUS internal_ver = ChuniConstants.VER_CHUNITHM
internal_ver = ChuniConstants.VER_CHUNITHM_PLUS elif version >= 105 and version < 110: # PLUS
elif version >= 110 and version < 115: # AIR internal_ver = ChuniConstants.VER_CHUNITHM_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_AIR elif version >= 110 and version < 115: # AIR
elif version >= 115 and version < 120: # AIR PLUS internal_ver = ChuniConstants.VER_CHUNITHM_AIR
internal_ver = ChuniConstants.VER_CHUNITHM_AIR_PLUS elif version >= 115 and version < 120: # AIR PLUS
elif version >= 120 and version < 125: # STAR internal_ver = ChuniConstants.VER_CHUNITHM_AIR_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_STAR elif version >= 120 and version < 125: # STAR
elif version >= 125 and version < 130: # STAR PLUS internal_ver = ChuniConstants.VER_CHUNITHM_STAR
internal_ver = ChuniConstants.VER_CHUNITHM_STAR_PLUS elif version >= 125 and version < 130: # STAR PLUS
elif version >= 130 and version < 135: # AMAZON internal_ver = ChuniConstants.VER_CHUNITHM_STAR_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_AMAZON elif version >= 130 and version < 135: # AMAZON
elif version >= 135 and version < 140: # AMAZON PLUS internal_ver = ChuniConstants.VER_CHUNITHM_AMAZON
internal_ver = ChuniConstants.VER_CHUNITHM_AMAZON_PLUS elif version >= 135 and version < 140: # AMAZON PLUS
elif version >= 140 and version < 145: # CRYSTAL internal_ver = ChuniConstants.VER_CHUNITHM_AMAZON_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_CRYSTAL elif version >= 140 and version < 145: # CRYSTAL
elif version >= 145 and version < 150: # CRYSTAL PLUS internal_ver = ChuniConstants.VER_CHUNITHM_CRYSTAL
internal_ver = ChuniConstants.VER_CHUNITHM_CRYSTAL_PLUS elif version >= 145 and version < 150: # CRYSTAL PLUS
elif version >= 150 and version < 200: # PARADISE internal_ver = ChuniConstants.VER_CHUNITHM_CRYSTAL_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_PARADISE elif version >= 150 and version < 200: # PARADISE
elif version >= 200 and version < 205: # NEW!! internal_ver = ChuniConstants.VER_CHUNITHM_PARADISE
internal_ver = ChuniConstants.VER_CHUNITHM_NEW elif version >= 200 and version < 205: # NEW!!
elif version >= 205 and version < 210: # NEW PLUS!! internal_ver = ChuniConstants.VER_CHUNITHM_NEW
internal_ver = ChuniConstants.VER_CHUNITHM_NEW_PLUS elif version >= 205 and version < 210: # NEW PLUS!!
elif version >= 210: # SUN internal_ver = ChuniConstants.VER_CHUNITHM_NEW_PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_SUN elif version >= 210 and version < 215: # SUN
internal_ver = ChuniConstants.VER_CHUNITHM_SUN
elif version >= 215: # SUN
internal_ver = ChuniConstants.VER_CHUNITHM_SUN_PLUS
elif game_code == "SDGS": # Int
if version < 110: # SUPERSTAR
internal_ver = ChuniConstants.PARADISE
elif version >= 110 and version < 115: # NEW
internal_ver = ChuniConstants.VER_CHUNITHM_NEW
elif version >= 115 and version < 120: # NEW PLUS!!
internal_ver = ChuniConstants.VER_CHUNITHM_NEW_PLUS
elif version >= 120 and version < 125: # SUN
internal_ver = ChuniConstants.VER_CHUNITHM_SUN
elif version >= 125: # SUN PLUS
internal_ver = ChuniConstants.VER_CHUNITHM_SUN_PLUS
if all(c in string.hexdigits for c in endpoint) and len(endpoint) == 32: if all(c in string.hexdigits for c in endpoint) and len(endpoint) == 32:
# If we get a 32 character long hex string, it's a hash and we're # If we get a 32 character long hex string, it's a hash and we're
@ -250,6 +268,7 @@ class ChuniServlet(BaseServlet):
self.logger.info(f"v{version} {endpoint} request from {client_ip}") self.logger.info(f"v{version} {endpoint} request from {client_ip}")
self.logger.debug(req_data) self.logger.debug(req_data)
endpoint = endpoint.replace("C3Exp", "") if game_code == "SDGS" else endpoint
func_to_find = "handle_" + inflection.underscore(endpoint) + "_request" func_to_find = "handle_" + inflection.underscore(endpoint) + "_request"
handler_cls = self.versions[internal_ver](self.core_cfg, self.game_cfg) handler_cls = self.versions[internal_ver](self.core_cfg, self.game_cfg)