update mai2
This commit is contained in:
@ -37,8 +37,8 @@ class BaseServlet:
|
||||
is the matching string, and offset 2 is a dict containing rules for the matcher.
|
||||
"""
|
||||
return (
|
||||
[("render_GET", "/{game}/{version}/{endpoint:.*?}", {'game': R'S...'})],
|
||||
[("render_POST", "/{game}/{version}/{endpoint:.*?}", {'game': R'S...'})]
|
||||
[("render_GET", "/{game}/{version}/{endpoint}", {'game': R'S...'})],
|
||||
[("render_POST", "/{game}/{version}/{endpoint}", {'game': R'S...'})]
|
||||
)
|
||||
|
||||
def setup(self) -> None:
|
||||
@ -57,7 +57,7 @@ class BaseServlet:
|
||||
Returns:
|
||||
Tuple[str, str]: A tuple where offset 0 is the allnet uri field, and offset 1 is the allnet host field
|
||||
"""
|
||||
if not self.core_cfg.server.is_using_proxy:
|
||||
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_code}/{game_ver}/", "")
|
||||
|
||||
return (f"http://{self.core_cfg.title.hostname}/{game_code}/{game_ver}/", "")
|
||||
|
@ -5,8 +5,11 @@ import logging
|
||||
import importlib
|
||||
from os import walk
|
||||
|
||||
from .config import CoreConfig
|
||||
|
||||
class Utils:
|
||||
real_title_port = None
|
||||
real_title_port_ssl = None
|
||||
@classmethod
|
||||
def get_all_titles(cls) -> Dict[str, ModuleType]:
|
||||
ret: Dict[str, Any] = {}
|
||||
@ -33,3 +36,27 @@ class Utils:
|
||||
if b"x-forwarded-for" in req.getAllHeaders()
|
||||
else req.getClientAddress().host
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_title_port(cls, cfg: CoreConfig):
|
||||
if cls.real_title_port is not None: return cls.real_title_port
|
||||
|
||||
if cfg.title.port == 0:
|
||||
cls.real_title_port = cfg.allnet.port
|
||||
|
||||
else:
|
||||
cls.real_title_port = cfg.title.port
|
||||
|
||||
return cls.real_title_port
|
||||
|
||||
@classmethod
|
||||
def get_title_port_ssl(cls, cfg: CoreConfig):
|
||||
if cls.real_title_port_ssl is not None: return cls.real_title_port_ssl
|
||||
|
||||
if cfg.title.port_ssl == 0:
|
||||
cls.real_title_port_ssl = cfg.allnet.port
|
||||
|
||||
else:
|
||||
cls.real_title_port_ssl = cfg.title.port_ssl
|
||||
|
||||
return cls.real_title_port_ssl
|
||||
|
@ -7,10 +7,11 @@ import json
|
||||
import urllib.parse
|
||||
import base64
|
||||
from os import path
|
||||
from typing import Tuple, Dict
|
||||
from typing import Tuple, Dict, List
|
||||
|
||||
from core.config import CoreConfig
|
||||
from core.title import BaseServlet
|
||||
from core.utils import Utils
|
||||
from .config import DivaConfig
|
||||
from .const import DivaConstants
|
||||
from .base import DivaBase
|
||||
@ -50,6 +51,18 @@ class DivaServlet(BaseServlet):
|
||||
level=self.game_cfg.server.loglevel, logger=self.logger, fmt=log_fmt_str
|
||||
)
|
||||
|
||||
def get_endpoint_matchers(self) -> Tuple[List[Tuple[str, str, Dict]], List[Tuple[str, str, Dict]]]:
|
||||
return (
|
||||
[],
|
||||
[("render_POST", "/DivaServlet/", {})]
|
||||
)
|
||||
|
||||
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}/DivaServlet/", "")
|
||||
|
||||
return (f"http://{self.core_cfg.title.hostname}/DivaServlet/", "")
|
||||
|
||||
@classmethod
|
||||
def is_game_enabled(
|
||||
cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str
|
||||
|
@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, List
|
||||
import logging
|
||||
from base64 import b64decode
|
||||
@ -7,9 +7,10 @@ from PIL import ImageFile
|
||||
|
||||
import pytz
|
||||
from core.config import CoreConfig
|
||||
from titles.mai2.const import Mai2Constants
|
||||
from titles.mai2.config import Mai2Config
|
||||
from titles.mai2.database import Mai2Data
|
||||
from core.utils import Utils
|
||||
from .const import Mai2Constants
|
||||
from .config import Mai2Config
|
||||
from .database import Mai2Data
|
||||
|
||||
|
||||
class Mai2Base:
|
||||
@ -22,16 +23,17 @@ class Mai2Base:
|
||||
self.can_deliver = False
|
||||
self.can_usbdl = False
|
||||
self.old_server = ""
|
||||
self.date_time_format = "%Y-%m-%d %H:%M:%S"
|
||||
|
||||
if self.core_config.server.is_develop and self.core_config.title.port > 0:
|
||||
self.old_server = f"http://{self.core_config.title.hostname}:{self.core_config.title.port}/SDEY/197/"
|
||||
if not self.core_config.server.is_using_proxy and Utils.get_title_port(self.core_cfg) != 80:
|
||||
self.old_server = f"http://{self.core_config.title.hostname}:{Utils.get_title_port(cfg)}/197/MaimaiServlet/"
|
||||
|
||||
else:
|
||||
self.old_server = f"http://{self.core_config.title.hostname}/SDEY/197/"
|
||||
self.old_server = f"http://{self.core_config.title.hostname}/197/MaimaiServlet/"
|
||||
|
||||
def handle_get_game_setting_api_request(self, data: Dict):
|
||||
# if reboot start/end time is not defined use the default behavior of being a few hours ago
|
||||
if self.core_cfg.title.reboot_start_time == "" or self.core_cfg.title.reboot_end_time == "":
|
||||
if self.core_config.title.reboot_start_time == "" or self.core_config.title.reboot_end_time == "":
|
||||
reboot_start = datetime.strftime(
|
||||
datetime.utcnow() + timedelta(hours=6), self.date_time_format
|
||||
)
|
||||
@ -43,8 +45,8 @@ class Mai2Base:
|
||||
current_jst = datetime.now(pytz.timezone('Asia/Tokyo')).date()
|
||||
|
||||
# parse config start/end times into datetime
|
||||
reboot_start_time = datetime.strptime(self.core_cfg.title.reboot_start_time, "%H:%M")
|
||||
reboot_end_time = datetime.strptime(self.core_cfg.title.reboot_end_time, "%H:%M")
|
||||
reboot_start_time = datetime.strptime(self.core_config.title.reboot_start_time, "%H:%M")
|
||||
reboot_end_time = datetime.strptime(self.core_config.title.reboot_end_time, "%H:%M")
|
||||
|
||||
# offset datetimes with current date/time
|
||||
reboot_start_time = reboot_start_time.replace(year=current_jst.year, month=current_jst.month, day=current_jst.day, tzinfo=pytz.timezone('Asia/Tokyo'))
|
||||
|
@ -8,28 +8,29 @@ import logging, coloredlogs
|
||||
import zlib
|
||||
from logging.handlers import TimedRotatingFileHandler
|
||||
from os import path, mkdir
|
||||
from typing import Tuple
|
||||
from typing import Tuple, List, Dict
|
||||
|
||||
from core.config import CoreConfig
|
||||
from core.utils import Utils
|
||||
from titles.mai2.config import Mai2Config
|
||||
from titles.mai2.const import Mai2Constants
|
||||
from titles.mai2.base import Mai2Base
|
||||
from titles.mai2.finale import Mai2Finale
|
||||
from titles.mai2.dx import Mai2DX
|
||||
from titles.mai2.dxplus import Mai2DXPlus
|
||||
from titles.mai2.splash import Mai2Splash
|
||||
from titles.mai2.splashplus import Mai2SplashPlus
|
||||
from titles.mai2.universe import Mai2Universe
|
||||
from titles.mai2.universeplus import Mai2UniversePlus
|
||||
from titles.mai2.festival import Mai2Festival
|
||||
from titles.mai2.festivalplus import Mai2FestivalPlus
|
||||
from core.title import BaseServlet
|
||||
from .config import Mai2Config
|
||||
from .const import Mai2Constants
|
||||
from .base import Mai2Base
|
||||
from .finale import Mai2Finale
|
||||
from .dx import Mai2DX
|
||||
from .dxplus import Mai2DXPlus
|
||||
from .splash import Mai2Splash
|
||||
from .splashplus import Mai2SplashPlus
|
||||
from .universe import Mai2Universe
|
||||
from .universeplus import Mai2UniversePlus
|
||||
from .festival import Mai2Festival
|
||||
from .festivalplus import Mai2FestivalPlus
|
||||
|
||||
|
||||
class Mai2Servlet:
|
||||
class Mai2Servlet(BaseServlet):
|
||||
def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None:
|
||||
self.core_cfg = core_cfg
|
||||
self.game_cfg = Mai2Config()
|
||||
super().__init__
|
||||
self.game_cfg = Mai2Config(core_cfg, cfg_dir)
|
||||
if path.exists(f"{cfg_dir}/{Mai2Constants.CONFIG_NAME}"):
|
||||
self.game_cfg.update(
|
||||
yaml.safe_load(open(f"{cfg_dir}/{Mai2Constants.CONFIG_NAME}"))
|
||||
@ -85,9 +86,9 @@ class Mai2Servlet:
|
||||
self.logger.initted = True
|
||||
|
||||
@classmethod
|
||||
def get_allnet_info(
|
||||
def is_game_enabled(
|
||||
cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str
|
||||
) -> Tuple[bool, str, str]:
|
||||
) -> bool:
|
||||
game_cfg = Mai2Config()
|
||||
|
||||
if path.exists(f"{cfg_dir}/{Mai2Constants.CONFIG_NAME}"):
|
||||
@ -96,19 +97,35 @@ class Mai2Servlet:
|
||||
)
|
||||
|
||||
if not game_cfg.server.enable:
|
||||
return (False, "", "")
|
||||
return False
|
||||
|
||||
if core_cfg.server.is_develop:
|
||||
def get_endpoint_matchers(self) -> Tuple[List[Tuple[str, str, Dict]], List[Tuple[str, str, Dict]]]:
|
||||
return (
|
||||
True,
|
||||
f"http://{core_cfg.title.hostname}:{core_cfg.title.port}/{game_code}/$v/",
|
||||
f"{core_cfg.title.hostname}",
|
||||
[
|
||||
("handle_movie", "/{version}/MaimaiServlet/api/movie/{endpoint:..?}", {}),
|
||||
("handle_old_srv", "/{version}/MaimaiServlet/old/{endpoint:..?}", {}),
|
||||
("handle_usbdl", "/{version}/MaimaiServlet/usbdl/{endpoint:..?}", {}),
|
||||
("handle_deliver", "/{version}/MaimaiServlet/deliver/{endpoint:..?}", {}),
|
||||
],
|
||||
[
|
||||
("handle_movie", "/{version}/MaimaiServlet/api/movie/{endpoint:..?}", {}),
|
||||
("handle_mai", "/{version}/MaimaiServlet/{endpoint}", {}),
|
||||
("handle_mai2", "/{version}/Maimai2Servlet/{endpoint}", {}),
|
||||
]
|
||||
)
|
||||
|
||||
def get_allnet_info(self, game_code: str, game_ver: int, keychip: str) -> Tuple[str, str]:
|
||||
servlet_name = "Maimai2Servlet" if game_code == Mai2Constants.GAME_CODE_DX else "MaimaiServlet"
|
||||
|
||||
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}:{Utils.get_title_port(self.core_cfg)}/{game_ver}/{servlet_name}/",
|
||||
f"{self.core_cfg.title.hostname}",
|
||||
)
|
||||
|
||||
return (
|
||||
True,
|
||||
f"http://{core_cfg.title.hostname}/{game_code}/$v/",
|
||||
f"{core_cfg.title.hostname}",
|
||||
f"http://{self.core_cfg.title.hostname}/{game_code}/{game_ver}/{servlet_name}/",
|
||||
f"{self.core_cfg.title.hostname}",
|
||||
)
|
||||
|
||||
def setup(self):
|
||||
|
Reference in New Issue
Block a user