From b8fd0baee53f50af22de71400b4e493627cd5f5c Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Sat, 4 Mar 2023 21:34:35 -0500 Subject: [PATCH] wacca: move to get_allnet_info, add safety for loading config --- titles/wacca/index.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/titles/wacca/index.py b/titles/wacca/index.py index 37d3f9e..8b30dc6 100644 --- a/titles/wacca/index.py +++ b/titles/wacca/index.py @@ -3,10 +3,10 @@ import logging, coloredlogs from logging.handlers import TimedRotatingFileHandler import logging import json -from datetime import datetime from hashlib import md5 from twisted.web.http import Request -from typing import Dict +from typing import Dict, Tuple +from os import path from core.config import CoreConfig from titles.wacca.config import WaccaConfig @@ -24,7 +24,8 @@ class WaccaServlet(): def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None: self.core_cfg = core_cfg self.game_cfg = WaccaConfig() - self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/wacca.yaml"))) + if path.exists(f"{cfg_dir}/wacca.yaml"): + self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/wacca.yaml"))) self.versions = [ WaccaBase(core_cfg, self.game_cfg), @@ -51,6 +52,19 @@ class WaccaServlet(): self.logger.setLevel(self.game_cfg.server.loglevel) 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 = WaccaConfig() + game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/wacca.yaml"))) + + 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: def end(resp: Dict) -> bytes: hash = md5(json.dumps(resp, ensure_ascii=False).encode()).digest()