From 6609732546f96cc6745a137ccfbebd519021c043 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Mon, 6 Mar 2023 16:06:17 +0100 Subject: [PATCH] cm: added get_allnet_info --- titles/cm/__init__.py | 8 +------- titles/cm/const.py | 2 ++ titles/cm/index.py | 22 ++++++++++++++++++++-- titles/ongeki/__init__.py | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/titles/cm/__init__.py b/titles/cm/__init__.py index 7c03605..ae4e9f0 100644 --- a/titles/cm/__init__.py +++ b/titles/cm/__init__.py @@ -5,12 +5,6 @@ from titles.cm.read import CardMakerReader index = CardMakerServlet reader = CardMakerReader -use_default_title = True -include_protocol = True -title_secure = False game_codes = [CardMakerConstants.GAME_CODE] -trailing_slash = True -use_default_host = False -host = "" -current_schema_version = 1 \ No newline at end of file +current_schema_version = 1 diff --git a/titles/cm/const.py b/titles/cm/const.py index 54cc009..3dec4fe 100644 --- a/titles/cm/const.py +++ b/titles/cm/const.py @@ -1,6 +1,8 @@ class CardMakerConstants(): GAME_CODE = "SDED" + CONFIG_NAME = "cardmaker.yaml" + VER_CARD_MAKER = 0 VER_CARD_MAKER_136 = 1 diff --git a/titles/cm/index.py b/titles/cm/index.py index 34fafb0..b2751b0 100644 --- a/titles/cm/index.py +++ b/titles/cm/index.py @@ -1,4 +1,3 @@ -from twisted.web.http import Request import json import inflection import yaml @@ -6,6 +5,10 @@ import string import logging import coloredlogs import zlib + +from os import path +from typing import Tuple +from twisted.web.http import Request from logging.handlers import TimedRotatingFileHandler from core.config import CoreConfig @@ -19,7 +22,8 @@ class CardMakerServlet(): def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None: self.core_cfg = core_cfg self.game_cfg = CardMakerConfig() - self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/cardmaker.yaml"))) + if path.exists(f"{cfg_dir}/{CardMakerConstants.CONFIG_NAME}"): + self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/{CardMakerConstants.CONFIG_NAME}"))) self.versions = [ CardMakerBase(core_cfg, self.game_cfg), @@ -44,6 +48,20 @@ class CardMakerServlet(): coloredlogs.install(level=self.game_cfg.server.loglevel, logger=self.logger, fmt=log_fmt_str) + @classmethod + def get_allnet_info(cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str) -> Tuple[bool, str, str]: + game_cfg = CardMakerConfig() + if path.exists(f"{cfg_dir}/{CardMakerConstants.CONFIG_NAME}"): + game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/{CardMakerConstants.CONFIG_NAME}"))) + + if not game_cfg.server.enable: + return (False, "", "") + + if core_cfg.server.is_develop: + return (True, f"http://{core_cfg.title.hostname}:{core_cfg.title.port}/{game_code}/$v/", "") + + return (True, f"http://{core_cfg.title.hostname}/{game_code}/$v/", "") + def render_POST(self, request: Request, version: int, url_path: str) -> bytes: req_raw = request.content.getvalue() url_split = url_path.split("/") diff --git a/titles/ongeki/__init__.py b/titles/ongeki/__init__.py index 8ca6862..26e107c 100644 --- a/titles/ongeki/__init__.py +++ b/titles/ongeki/__init__.py @@ -15,4 +15,4 @@ trailing_slash = True use_default_host = False host = "" -current_schema_version = 2 +current_schema_version = 2 \ No newline at end of file