Added reboot time support

This commit is contained in:
EmmyHeart 2023-10-16 13:21:07 +00:00
parent 8d289ca066
commit 9cff321857
1 changed files with 31 additions and 5 deletions

View File

@ -5,6 +5,7 @@ from base64 import b64decode
from os import path, stat, remove from os import path, stat, remove
from PIL import ImageFile from PIL import ImageFile
import pytz
from core.config import CoreConfig from core.config import CoreConfig
from titles.mai2.const import Mai2Constants from titles.mai2.const import Mai2Constants
from titles.mai2.config import Mai2Config from titles.mai2.config import Mai2Config
@ -21,22 +22,47 @@ class Mai2Base:
self.can_deliver = False self.can_deliver = False
self.can_usbdl = False self.can_usbdl = False
self.old_server = "" self.old_server = ""
if self.core_config.server.is_develop and self.core_config.title.port > 0: 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/" self.old_server = f"http://{self.core_config.title.hostname}:{self.core_config.title.port}/SDEY/197/"
else: else:
self.old_server = f"http://{self.core_config.title.hostname}/SDEY/197/" self.old_server = f"http://{self.core_config.title.hostname}/SDEY/197/"
def handle_get_game_setting_api_request(self, data: Dict): def handle_get_game_setting_api_request(self, data: Dict):
return { # 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)
return {
"isDevelop": False, "isDevelop": False,
"isAouAccession": False, "isAouAccession": False,
"gameSetting": { "gameSetting": {
"isMaintenance": False, "isMaintenance": False,
"requestInterval": 1800, "requestInterval": 1800,
"rebootStartTime": "2020-01-01 07:00:00.0", "rebootStartTime": reboot_start,
"rebootEndTime": "2020-01-01 07:59:59.0", "rebootEndTime": reboot_end,
"movieUploadLimit": 100, "movieUploadLimit": 100,
"movieStatus": 1, "movieStatus": 1,
"movieServerUri": self.old_server + "api/movie" if self.game_config.uploads.movies else "movie", "movieServerUri": self.old_server + "api/movie" if self.game_config.uploads.movies else "movie",