2023-03-03 23:46:29 +01:00
|
|
|
from datetime import date, datetime, timedelta
|
|
|
|
from typing import Any, Dict, List
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
from enum import Enum
|
|
|
|
|
2023-10-16 15:20:00 +02:00
|
|
|
import pytz
|
2023-03-03 23:46:29 +01:00
|
|
|
from core.config import CoreConfig
|
2023-11-09 03:17:48 +01:00
|
|
|
from core.utils import Utils
|
2023-03-03 23:46:29 +01:00
|
|
|
from core.data.cache import cached
|
|
|
|
from titles.cm.const import CardMakerConstants
|
|
|
|
from titles.cm.config import CardMakerConfig
|
|
|
|
|
|
|
|
|
2023-03-09 17:38:58 +01:00
|
|
|
class CardMakerBase:
|
2023-03-03 23:46:29 +01:00
|
|
|
def __init__(self, core_cfg: CoreConfig, game_cfg: CardMakerConfig) -> None:
|
|
|
|
self.core_cfg = core_cfg
|
|
|
|
self.game_cfg = game_cfg
|
|
|
|
self.date_time_format = "%Y-%m-%d %H:%M:%S"
|
2023-03-09 17:38:58 +01:00
|
|
|
self.date_time_format_ext = (
|
|
|
|
"%Y-%m-%d %H:%M:%S.%f" # needs to be lopped off at [:-5]
|
|
|
|
)
|
2023-03-03 23:46:29 +01:00
|
|
|
self.date_time_format_short = "%Y-%m-%d"
|
|
|
|
self.logger = logging.getLogger("cardmaker")
|
|
|
|
self.game = CardMakerConstants.GAME_CODE
|
|
|
|
self.version = CardMakerConstants.VER_CARD_MAKER
|
|
|
|
|
2023-05-30 12:14:18 +02:00
|
|
|
@staticmethod
|
|
|
|
def _parse_int_ver(version: str) -> str:
|
|
|
|
return version.replace(".", "")[:3]
|
|
|
|
|
2024-01-09 09:07:04 +01:00
|
|
|
async def handle_get_game_connect_api_request(self, data: Dict) -> Dict:
|
2023-11-09 03:17:48 +01:00
|
|
|
if not self.core_cfg.server.is_using_proxy and Utils.get_title_port(self.core_cfg) != 80:
|
2024-01-09 09:07:04 +01:00
|
|
|
uri = f"http://{self.core_cfg.server.hostname}:{Utils.get_title_port(self.core_cfg)}"
|
2023-03-09 16:35:58 +01:00
|
|
|
else:
|
2024-01-09 09:07:04 +01:00
|
|
|
uri = f"http://{self.core_cfg.server.hostname}"
|
2023-03-03 23:46:29 +01:00
|
|
|
|
2023-05-30 12:14:18 +02:00
|
|
|
# grab the dict with all games version numbers from user config
|
|
|
|
games_ver = self.game_cfg.version.version(self.version)
|
|
|
|
|
2023-03-03 23:46:29 +01:00
|
|
|
return {
|
|
|
|
"length": 3,
|
|
|
|
"gameConnectList": [
|
2023-05-30 12:14:18 +02:00
|
|
|
# CHUNITHM
|
|
|
|
{
|
|
|
|
"modelKind": 0,
|
|
|
|
"type": 1,
|
2023-12-13 07:37:30 +01:00
|
|
|
"titleUri": f"{uri}/SDHD/{self._parse_int_ver(games_ver['chuni'])}/ChuniServlet/",
|
2023-05-30 12:14:18 +02:00
|
|
|
},
|
|
|
|
# maimai DX
|
|
|
|
{
|
|
|
|
"modelKind": 1,
|
|
|
|
"type": 1,
|
2023-11-09 03:17:48 +01:00
|
|
|
"titleUri": f"{uri}/{self._parse_int_ver(games_ver['maimai'])}/Maimai2Servlet/",
|
2023-05-30 12:14:18 +02:00
|
|
|
},
|
|
|
|
# ONGEKI
|
|
|
|
{
|
|
|
|
"modelKind": 2,
|
|
|
|
"type": 1,
|
|
|
|
"titleUri": f"{uri}/SDDT/{self._parse_int_ver(games_ver['ongeki'])}/",
|
|
|
|
},
|
2023-03-09 17:38:58 +01:00
|
|
|
],
|
2023-03-03 23:46:29 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 09:07:04 +01:00
|
|
|
async def handle_get_game_setting_api_request(self, data: Dict) -> Dict:
|
2023-10-16 15:20:00 +02:00
|
|
|
# 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 == "":
|
|
|
|
reboot_start = datetime.strftime(
|
|
|
|
datetime.utcnow() + timedelta(hours=6), self.date_time_format
|
|
|
|
)
|
|
|
|
reboot_end = datetime.strftime(
|
|
|
|
datetime.utcnow() + timedelta(hours=7), self.date_time_format
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
# get current datetime in JST
|
|
|
|
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")
|
|
|
|
|
|
|
|
# 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'))
|
|
|
|
reboot_end_time = reboot_end_time.replace(year=current_jst.year, month=current_jst.month, day=current_jst.day, tzinfo=pytz.timezone('Asia/Tokyo'))
|
|
|
|
|
|
|
|
# create strings for use in gameSetting
|
|
|
|
reboot_start = reboot_start_time.strftime(self.date_time_format)
|
|
|
|
reboot_end = reboot_end_time.strftime(self.date_time_format)
|
2023-03-03 23:46:29 +01:00
|
|
|
|
2023-05-30 12:14:18 +02:00
|
|
|
# grab the dict with all games version numbers from user config
|
|
|
|
games_ver = self.game_cfg.version.version(self.version)
|
|
|
|
|
2023-03-03 23:46:29 +01:00
|
|
|
return {
|
|
|
|
"gameSetting": {
|
|
|
|
"dataVersion": "1.30.00",
|
2023-05-30 12:14:18 +02:00
|
|
|
"ongekiCmVersion": games_ver["ongeki"],
|
|
|
|
"chuniCmVersion": games_ver["chuni"],
|
|
|
|
"maimaiCmVersion": games_ver["maimai"],
|
2023-03-03 23:46:29 +01:00
|
|
|
"requestInterval": 10,
|
|
|
|
"rebootStartTime": reboot_start,
|
|
|
|
"rebootEndTime": reboot_end,
|
|
|
|
"maxCountCharacter": 100,
|
|
|
|
"maxCountItem": 100,
|
|
|
|
"maxCountCard": 100,
|
|
|
|
"watermark": False,
|
|
|
|
"isMaintenance": False,
|
2023-03-09 17:38:58 +01:00
|
|
|
"isBackgroundDistribute": False,
|
2023-03-03 23:46:29 +01:00
|
|
|
},
|
|
|
|
"isDumpUpload": False,
|
2023-03-09 17:38:58 +01:00
|
|
|
"isAou": False,
|
2023-03-03 23:46:29 +01:00
|
|
|
}
|
|
|
|
|
2024-01-09 09:07:04 +01:00
|
|
|
async def handle_get_client_bookkeeping_api_request(self, data: Dict) -> Dict:
|
2023-03-09 17:38:58 +01:00
|
|
|
return {"placeId": data["placeId"], "length": 0, "clientBookkeepingList": []}
|
2023-03-03 23:46:29 +01:00
|
|
|
|
2024-01-09 09:07:04 +01:00
|
|
|
async def handle_upsert_client_setting_api_request(self, data: Dict) -> Dict:
|
2023-03-03 23:46:29 +01:00
|
|
|
return {"returnCode": 1, "apiName": "UpsertClientSettingApi"}
|
|
|
|
|
2024-01-09 09:07:04 +01:00
|
|
|
async def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict:
|
2023-03-03 23:46:29 +01:00
|
|
|
return {"returnCode": 1, "apiName": "UpsertClientBookkeepingApi"}
|