From 1b3e43b9181508162d3ff6d1701042f301931a64 Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Mon, 8 Jan 2024 18:30:03 -0500 Subject: [PATCH] chuni: Imrpove `GetGameSetting` request handling for different versions --- changelog.md | 1 + titles/chuni/new.py | 15 ++++++++++++--- titles/chuni/newplus.py | 24 +----------------------- titles/chuni/sun.py | 18 ------------------ titles/chuni/sunplus.py | 18 ------------------ 5 files changed, 14 insertions(+), 62 deletions(-) diff --git a/changelog.md b/changelog.md index 1e6c207..914dd5c 100644 --- a/changelog.md +++ b/changelog.md @@ -22,6 +22,7 @@ Documenting updates to ARTEMiS, to be updated every time the master branch is pu + Add support for Sun+ [#78](https://gitea.tendokyu.moe/Hay1tsme/artemis/pulls/78) (Thanks EmmyHeart!) + Add `matching` section to `chuni.yaml` + Change `udpHolePunchUri` and `reflectorUri` to be STUN and TURN servers ++ Imrpove `GetGameSetting` request handling for different versions ### maimai DX + Fix user charges failing to save diff --git a/titles/chuni/new.py b/titles/chuni/new.py index 86a7b08..15bef13 100644 --- a/titles/chuni/new.py +++ b/titles/chuni/new.py @@ -11,7 +11,6 @@ from titles.chuni.database import ChuniData from titles.chuni.base import ChuniBase from titles.chuni.config import ChuniConfig - class ChuniNew(ChuniBase): ITEM_TYPE = {"character": 20, "story": 21, "card": 22} @@ -23,6 +22,16 @@ class ChuniNew(ChuniBase): self.logger = logging.getLogger("chuni") self.game = ChuniConstants.GAME_CODE self.version = ChuniConstants.VER_CHUNITHM_NEW + + def _interal_ver_to_intver(self) -> str: + if self.version == ChuniConstants.VER_CHUNITHM_NEW: + return "200" + if self.version == ChuniConstants.VER_CHUNITHM_NEW_PLUS: + return "205" + if self.version == ChuniConstants.VER_CHUNITHM_SUN: + return "210" + if self.version == ChuniConstants.VER_CHUNITHM_SUN_PLUS: + return "215" def handle_get_game_setting_api_request(self, data: Dict) -> Dict: # use UTC time and convert it to JST time by adding +9 @@ -73,8 +82,8 @@ class ChuniNew(ChuniBase): "matchErrorLimit": self.game_cfg.matching.match_error_limit, "romVersion": self.game_cfg.version.version(self.version)["rom"], "dataVersion": self.game_cfg.version.version(self.version)["data"], - "matchingUri": f"http://{self.core_cfg.title.hostname}:{t_port}/SDHD/200/ChuniServlet/" if self.game_cfg.matching.enable else "", - "matchingUriX": f"http://{self.core_cfg.title.hostname}:{t_port}/SDHD/200/ChuniServlet/" if self.game_cfg.matching.enable else "", + "matchingUri": f"http://{self.core_cfg.title.hostname}:{t_port}/SDHD/{self._interal_ver_to_intver()}/ChuniServlet/" if self.game_cfg.matching.enable else "", + "matchingUriX": f"http://{self.core_cfg.title.hostname}:{t_port}/SDHD/{self._interal_ver_to_intver()}/ChuniServlet/" if self.game_cfg.matching.enable else "", # might be really important for online battle to connect the cabs via UDP port 50201 # Hay1tsme 01/08/2023: Pretty sure this is a stun and turn server respectivly... "udpHolePunchUri": self.game_cfg.matching.stun_uri if self.game_cfg.matching.enable else "", diff --git a/titles/chuni/newplus.py b/titles/chuni/newplus.py index 749173c..fa642d3 100644 --- a/titles/chuni/newplus.py +++ b/titles/chuni/newplus.py @@ -1,38 +1,16 @@ from typing import Dict, Any +from core.utils import Utils from core.config import CoreConfig from titles.chuni.new import ChuniNew from titles.chuni.const import ChuniConstants from titles.chuni.config import ChuniConfig - class ChuniNewPlus(ChuniNew): def __init__(self, core_cfg: CoreConfig, game_cfg: ChuniConfig) -> None: super().__init__(core_cfg, game_cfg) self.version = ChuniConstants.VER_CHUNITHM_NEW_PLUS - def handle_get_game_setting_api_request(self, data: Dict) -> Dict: - ret = super().handle_get_game_setting_api_request(data) - ret["gameSetting"]["romVersion"] = self.game_cfg.version.version(self.version)[ - "rom" - ] - ret["gameSetting"]["dataVersion"] = self.game_cfg.version.version(self.version)[ - "data" - ] - ret["gameSetting"][ - "matchingUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/" - ret["gameSetting"][ - "matchingUriX" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/" - ret["gameSetting"][ - "udpHolePunchUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/" - ret["gameSetting"][ - "reflectorUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/205/ChuniServlet/" - return ret - def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict: user_data = super().handle_cm_get_user_preview_api_request(data) diff --git a/titles/chuni/sun.py b/titles/chuni/sun.py index 9a82a65..bfefd97 100644 --- a/titles/chuni/sun.py +++ b/titles/chuni/sun.py @@ -11,24 +11,6 @@ class ChuniSun(ChuniNewPlus): super().__init__(core_cfg, game_cfg) self.version = ChuniConstants.VER_CHUNITHM_SUN - def handle_get_game_setting_api_request(self, data: Dict) -> Dict: - ret = super().handle_get_game_setting_api_request(data) - ret["gameSetting"]["romVersion"] = self.game_cfg.version.version(self.version)["rom"] - ret["gameSetting"]["dataVersion"] = self.game_cfg.version.version(self.version)["data"] - ret["gameSetting"][ - "matchingUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/210/ChuniServlet/" - ret["gameSetting"][ - "matchingUriX" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/210/ChuniServlet/" - ret["gameSetting"][ - "udpHolePunchUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/210/ChuniServlet/" - ret["gameSetting"][ - "reflectorUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/210/ChuniServlet/" - return ret - def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict: user_data = super().handle_cm_get_user_preview_api_request(data) diff --git a/titles/chuni/sunplus.py b/titles/chuni/sunplus.py index 66a7f3b..fc86314 100644 --- a/titles/chuni/sunplus.py +++ b/titles/chuni/sunplus.py @@ -11,24 +11,6 @@ class ChuniSunPlus(ChuniSun): super().__init__(core_cfg, game_cfg) self.version = ChuniConstants.VER_CHUNITHM_SUN_PLUS - def handle_get_game_setting_api_request(self, data: Dict) -> Dict: - ret = super().handle_get_game_setting_api_request(data) - ret["gameSetting"]["romVersion"] = self.game_cfg.version.version(self.version)["rom"] - ret["gameSetting"]["dataVersion"] = self.game_cfg.version.version(self.version)["data"] - ret["gameSetting"][ - "matchingUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/215/ChuniServlet/" - ret["gameSetting"][ - "matchingUriX" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/215/ChuniServlet/" - ret["gameSetting"][ - "udpHolePunchUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/215/ChuniServlet/" - ret["gameSetting"][ - "reflectorUri" - ] = f"http://{self.core_cfg.title.hostname}:{self.core_cfg.title.port}/SDHD/215/ChuniServlet/" - return ret - def handle_cm_get_user_preview_api_request(self, data: Dict) -> Dict: user_data = super().handle_cm_get_user_preview_api_request(data)