From 592e6961e8c36e793fdbf189b7072ffa880df54e Mon Sep 17 00:00:00 2001 From: zaphkito Date: Sat, 14 Jun 2025 05:05:19 +0800 Subject: [PATCH] chu&mai2: add option to use https --- example_config/chuni.yaml | 1 + example_config/mai2.yaml | 1 + titles/chuni/config.py | 6 ++++++ titles/chuni/index.py | 22 +++++++++++++++++++--- titles/mai2/config.py | 6 ++++++ titles/mai2/index.py | 27 +++++++++++++++++++++------ 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/example_config/chuni.yaml b/example_config/chuni.yaml index a3781d6..e2ae746 100644 --- a/example_config/chuni.yaml +++ b/example_config/chuni.yaml @@ -2,6 +2,7 @@ server: enable: True loglevel: "info" news_msg: "" + use_https: False # for CRYSTAL PLUS and later or SUPERSTAR and later team: name: ARTEMiS # If this is set, all players that are not on a team will use this one by default. diff --git a/example_config/mai2.yaml b/example_config/mai2.yaml index f0d7754..52dd4be 100644 --- a/example_config/mai2.yaml +++ b/example_config/mai2.yaml @@ -1,6 +1,7 @@ server: enable: True loglevel: "info" + use_https: False # for DX and later deliver: enable: False diff --git a/titles/chuni/config.py b/titles/chuni/config.py index f0e15f3..95720bc 100644 --- a/titles/chuni/config.py +++ b/titles/chuni/config.py @@ -25,6 +25,12 @@ class ChuniServerConfig: return CoreConfig.get_config_field( self.__config, "chuni", "server", "news_msg", default="" ) + + @property + def use_https(self) -> bool: + return CoreConfig.get_config_field( + self.__config, "chuni", "server", "use_https", default=False + ) class ChuniTeamConfig: diff --git a/titles/chuni/index.py b/titles/chuni/index.py index 1392588..cc25289 100644 --- a/titles/chuni/index.py +++ b/titles/chuni/index.py @@ -190,10 +190,26 @@ class ChuniServlet(BaseServlet): return True 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: - return (f"http://{self.core_cfg.server.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_code}/{game_ver}/", self.core_cfg.server.hostname) + title_port_int = Utils.get_title_port(self.core_cfg) + title_port_ssl_int = Utils.get_title_port_ssl(self.core_cfg) - return (f"http://{self.core_cfg.server.hostname}/{game_code}/{game_ver}/", self.core_cfg.server.hostname) + if self.game_cfg.server.use_https and ( + (game_code == "SDBT" and game_ver >= 145) or # JP use TLS from CRYSTAL PLUS + game_code != "SDBT" # SDGS and SDHJ all version can use TLS + ): + proto = "https" + else: + proto = "http" + + if proto == "https": + t_port = f":{title_port_ssl_int}" if title_port_ssl_int != 443 else "" + else: + t_port = f":{title_port_int}" if title_port_int != 80 else "" + + return ( + f"{proto}://{self.core_cfg.server.hostname}{t_port}/{game_code}/{game_ver}/", + f"{self.core_cfg.server.hostname}", + ) def get_routes(self) -> List[Route]: return [ diff --git a/titles/mai2/config.py b/titles/mai2/config.py index efd3ba5..66c1c94 100644 --- a/titles/mai2/config.py +++ b/titles/mai2/config.py @@ -20,6 +20,12 @@ class Mai2ServerConfig: self.__config, "mai2", "server", "loglevel", default="info" ) ) + + @property + def use_https(self) -> bool: + return CoreConfig.get_config_field( + self.__config, "mai2", "server", "use_https", default=False + ) class Mai2DeliverConfig: def __init__(self, parent: "Mai2Config") -> None: diff --git a/titles/mai2/index.py b/titles/mai2/index.py index d59ce87..e9d78d9 100644 --- a/titles/mai2/index.py +++ b/titles/mai2/index.py @@ -157,14 +157,29 @@ class Mai2Servlet(BaseServlet): ] 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: - return ( - f"http://{self.core_cfg.server.hostname}:{Utils.get_title_port(self.core_cfg)}/{game_code}/{game_ver}/", - f"{self.core_cfg.server.hostname}", - ) + title_port_int = Utils.get_title_port(self.core_cfg) + title_port_ssl_int = Utils.get_title_port_ssl(self.core_cfg) + + if self.game_cfg.server.use_https: + if (game_code == "SDEZ" and game_ver >= 114) or (game_code == "SDGA" and game_ver >= 110): # SDEZ and SDGA use tls from Splash version + proto = "" # game will auto add https:// in uri with original code + elif game_code == "SDGB" and game_ver >= 130: # SDGB use tls from 1.30 + # game will check if uri start with "http:", if yes, set IsHttpConnection = true + # so we can return https://example.com or http://example.com, all will work + proto = "https://" + else: + # "maimai", SDEZ 1.00 ~ 1.13, SDGA 1.00 ~ 1.06 and SDGB 1.01, 1.20 use http:// + proto = "http://" + else: + proto = "http://" + + if proto == "" or proto == "https://": + t_port = f":{title_port_ssl_int}" if title_port_ssl_int != 443 else "" + else: + t_port = f":{title_port_int}" if title_port_int != 80 else "" return ( - f"http://{self.core_cfg.server.hostname}/{game_code}/{game_ver}/", + f"{proto}{self.core_cfg.server.hostname}{t_port}/{game_code}/{game_ver}/", f"{self.core_cfg.server.hostname}", )