From 5278d1e6c132e78b7a16f2a1772b9ea6e57df819 Mon Sep 17 00:00:00 2001 From: Kevin Trocolli Date: Fri, 20 Oct 2023 01:42:41 -0400 Subject: [PATCH] chuni: fix matchers --- titles/chuni/index.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/titles/chuni/index.py b/titles/chuni/index.py index 8f0df38..b736427 100644 --- a/titles/chuni/index.py +++ b/titles/chuni/index.py @@ -11,7 +11,7 @@ from Crypto.Util.Padding import pad from Crypto.Protocol.KDF import PBKDF2 from Crypto.Hash import SHA1 from os import path -from typing import Tuple, Dict +from typing import Tuple, Dict, List from core import CoreConfig, Utils from core.title import BaseServlet @@ -116,6 +116,22 @@ class ChuniServlet(BaseServlet): f"Hashed v{version} method {method_fixed} with {bytes.fromhex(keys[2])} to get {hash.hex()}" ) + def get_endpoint_matchers(self) -> Tuple[List[Tuple[str, str, Dict]], List[Tuple[str, str, Dict]]]: + """Called during boot to get all matcher endpoints this title servlet handles + + Returns: + Tuple[List[Tuple[str, str, Dict]], List[Tuple[str, str, Dict]]]: A 2-length tuple where offset 0 is GET and offset 1 is POST, + containing a list of 3-length tuples where offset 0 is the name of the function in the handler that should be called, offset 1 + is the matching string, and offset 2 is a dict containing rules for the matcher. + """ + return ( + [], + [ + ("render_POST", "/{version}/ChuniServlet/{endpoint}", {}), + ("render_POST", "/{version}/ChuniServlet/{endpoint}", {}) + ] + ) + @classmethod def is_game_enabled( cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str @@ -130,7 +146,12 @@ class ChuniServlet(BaseServlet): return False 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.title.hostname}:{self.core_cfg.title.port}/{game_ver}/", "") + return (f"http://{self.core_cfg.title.hostname}/{game_ver}/", "") def render_POST(self, request: Request, game_code: int, matchers: Dict) -> bytes: url_path = matchers['endpoint'] @@ -140,10 +161,8 @@ class ChuniServlet(BaseServlet): return zlib.compress(b'{"returnCode": "1"}') req_raw = request.content.getvalue() - url_split = url_path.split("/") encrtped = False internal_ver = 0 - endpoint = url_split[len(url_split) - 1] client_ip = Utils.get_ip_addr(request) if version < 105: # 1.0