forked from Dniel97/artemis
idac: improved event loading, better logging, fixed round creation
This commit is contained in:
parent
d2175f5b0e
commit
a38904c743
@ -30,34 +30,37 @@ class IDACServlet(BaseServlet):
|
|||||||
yaml.safe_load(open(f"{cfg_dir}/{IDACConstants.CONFIG_NAME}"))
|
yaml.safe_load(open(f"{cfg_dir}/{IDACConstants.CONFIG_NAME}"))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.logger = logging.getLogger("idac")
|
||||||
|
|
||||||
|
if not hasattr(self.logger, "inited"):
|
||||||
|
log_fmt_str = "[%(asctime)s] IDAC | %(levelname)s | %(message)s"
|
||||||
|
log_fmt = logging.Formatter(log_fmt_str)
|
||||||
|
fileHandler = TimedRotatingFileHandler(
|
||||||
|
"{0}/{1}.log".format(self.core_cfg.server.log_dir, "idac"),
|
||||||
|
encoding="utf8",
|
||||||
|
when="d",
|
||||||
|
backupCount=10,
|
||||||
|
)
|
||||||
|
|
||||||
|
fileHandler.setFormatter(log_fmt)
|
||||||
|
|
||||||
|
consoleHandler = logging.StreamHandler()
|
||||||
|
consoleHandler.setFormatter(log_fmt)
|
||||||
|
|
||||||
|
self.logger.addHandler(fileHandler)
|
||||||
|
self.logger.addHandler(consoleHandler)
|
||||||
|
|
||||||
|
self.logger.setLevel(self.game_cfg.server.loglevel)
|
||||||
|
coloredlogs.install(
|
||||||
|
level=self.game_cfg.server.loglevel, logger=self.logger, fmt=log_fmt_str
|
||||||
|
)
|
||||||
|
self.logger.inited = True
|
||||||
|
|
||||||
self.versions = [
|
self.versions = [
|
||||||
IDACBase(core_cfg, self.game_cfg),
|
IDACBase(core_cfg, self.game_cfg),
|
||||||
IDACSeason2(core_cfg, self.game_cfg)
|
IDACSeason2(core_cfg, self.game_cfg)
|
||||||
]
|
]
|
||||||
|
|
||||||
self.logger = logging.getLogger("idac")
|
|
||||||
log_fmt_str = "[%(asctime)s] IDAC | %(levelname)s | %(message)s"
|
|
||||||
log_fmt = logging.Formatter(log_fmt_str)
|
|
||||||
fileHandler = TimedRotatingFileHandler(
|
|
||||||
"{0}/{1}.log".format(self.core_cfg.server.log_dir, "idac"),
|
|
||||||
encoding="utf8",
|
|
||||||
when="d",
|
|
||||||
backupCount=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
fileHandler.setFormatter(log_fmt)
|
|
||||||
|
|
||||||
consoleHandler = logging.StreamHandler()
|
|
||||||
consoleHandler.setFormatter(log_fmt)
|
|
||||||
|
|
||||||
self.logger.addHandler(fileHandler)
|
|
||||||
self.logger.addHandler(consoleHandler)
|
|
||||||
|
|
||||||
self.logger.setLevel(self.game_cfg.server.loglevel)
|
|
||||||
coloredlogs.install(
|
|
||||||
level=self.game_cfg.server.loglevel, logger=self.logger, fmt=log_fmt_str
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_game_enabled(cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str) -> bool:
|
def is_game_enabled(cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str) -> bool:
|
||||||
game_cfg = IDACConfig()
|
game_cfg = IDACConfig()
|
||||||
|
@ -143,6 +143,10 @@ class IDACReader(BaseReader):
|
|||||||
# check if the table has a version column
|
# check if the table has a version column
|
||||||
if "version" in table.c:
|
if "version" in table.c:
|
||||||
data["version"] = self.version
|
data["version"] = self.version
|
||||||
|
|
||||||
|
# remain compatible with old profile dumps
|
||||||
|
if "asset_version" in data:
|
||||||
|
data.pop("asset_version", None)
|
||||||
|
|
||||||
sql = insert(table).values(
|
sql = insert(table).values(
|
||||||
**data
|
**data
|
||||||
|
@ -123,7 +123,10 @@ class IDACOnlineRounds(BaseData):
|
|||||||
sql = select(round_details).where(round_details.c.round_id_in_json == round_id)
|
sql = select(round_details).where(round_details.c.round_id_in_json == round_id)
|
||||||
result = await self.execute(sql)
|
result = await self.execute(sql)
|
||||||
|
|
||||||
if result is None:
|
# check if the round already exists
|
||||||
|
existing_round = result.fetchone() if result else None
|
||||||
|
|
||||||
|
if existing_round is None:
|
||||||
tmp = {
|
tmp = {
|
||||||
"round_id_in_json": round_id,
|
"round_id_in_json": round_id,
|
||||||
"name": round_data["round_event_nm"],
|
"name": round_data["round_event_nm"],
|
||||||
@ -137,7 +140,6 @@ class IDACOnlineRounds(BaseData):
|
|||||||
|
|
||||||
return result.lastrowid
|
return result.lastrowid
|
||||||
|
|
||||||
rid = result.fetchone()
|
return existing_round["id"]
|
||||||
return rid["id"]
|
|
||||||
|
|
||||||
# TODO: get top five players of last round event for Boot/GetConfigData
|
# TODO: get top five players of last round event for Boot/GetConfigData
|
||||||
|
@ -29,48 +29,55 @@ class IDACSeason2(IDACBase):
|
|||||||
self.stamp_info = defaultdict(list)
|
self.stamp_info = defaultdict(list)
|
||||||
if self.game_config.stamp.enable:
|
if self.game_config.stamp.enable:
|
||||||
enabled_stamps = self.game_config.stamp.enabled_stamps
|
enabled_stamps = self.game_config.stamp.enabled_stamps
|
||||||
for game_ver in enabled_stamps.keys():
|
|
||||||
for stamp in enabled_stamps[game_ver][:3]:
|
|
||||||
if not os.path.exists(f"./titles/idac/data/stamp/{stamp}.json"):
|
|
||||||
self.logger.warning(
|
|
||||||
f"Stamp {stamp} is enabled but does not exist!"
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
with open(
|
if isinstance(enabled_stamps, Dict):
|
||||||
f"./titles/idac/data/stamp/{stamp}.json", encoding="UTF-8"
|
for game_ver in enabled_stamps.keys():
|
||||||
) as f:
|
for stamp in enabled_stamps[game_ver][:3]:
|
||||||
self.logger.debug(f"Loading stamp {stamp}")
|
if not os.path.exists(f"./titles/idac/data/stamp/{stamp}.json"):
|
||||||
self.stamp_info[game_ver].append(self._fix_dates(json.load(f)))
|
self.logger.warning(
|
||||||
|
f"Stamp {stamp} is enabled but does not exist!"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
|
with open(
|
||||||
|
f"./titles/idac/data/stamp/{stamp}.json", encoding="UTF-8"
|
||||||
|
) as f:
|
||||||
|
self.logger.debug(f"Loading stamp {stamp}")
|
||||||
|
self.stamp_info[game_ver].append(self._fix_dates(json.load(f)))
|
||||||
|
else:
|
||||||
|
self.logger.warning("Stamp configuration is invalid, please update your idac.yaml config!")
|
||||||
|
|
||||||
# load the user configured time trial (only one) for each game version
|
# load the user configured time trial (only one) for each game version
|
||||||
self.timetrial_event = {}
|
self.timetrial_event = {}
|
||||||
self.timetrial_event_id = {}
|
self.timetrial_event_id = {}
|
||||||
if self.game_config.timetrial.enable:
|
if self.game_config.timetrial.enable:
|
||||||
enabled_timetrial = self.game_config.timetrial.enabled_timetrial
|
enabled_timetrial = self.game_config.timetrial.enabled_timetrial
|
||||||
for game_ver in enabled_timetrial.keys():
|
if isinstance(enabled_timetrial, Dict):
|
||||||
timetrial = enabled_timetrial[game_ver]
|
for game_ver in enabled_timetrial.keys():
|
||||||
if timetrial is not None:
|
timetrial = enabled_timetrial[game_ver]
|
||||||
if not os.path.exists(
|
if timetrial is not None:
|
||||||
f"./titles/idac/data/timetrial/{timetrial}.json"
|
if not os.path.exists(
|
||||||
):
|
f"./titles/idac/data/timetrial/{timetrial}.json"
|
||||||
self.logger.warning(
|
):
|
||||||
f"Timetrial {timetrial} is enabled but does not exist!"
|
self.logger.warning(
|
||||||
)
|
f"Timetrial {timetrial} is enabled but does not exist!"
|
||||||
else:
|
|
||||||
self.logger.debug(f"Loading timetrial {timetrial}")
|
|
||||||
with open(
|
|
||||||
f"./titles/idac/data/timetrial/{timetrial}.json",
|
|
||||||
encoding="UTF-8",
|
|
||||||
) as f:
|
|
||||||
self.timetrial_event[game_ver] = self._fix_dates(
|
|
||||||
json.load(f)
|
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.logger.debug(f"Loading timetrial {timetrial}")
|
||||||
|
with open(
|
||||||
|
f"./titles/idac/data/timetrial/{timetrial}.json",
|
||||||
|
encoding="UTF-8",
|
||||||
|
) as f:
|
||||||
|
self.timetrial_event[game_ver] = self._fix_dates(
|
||||||
|
json.load(f)
|
||||||
|
)
|
||||||
|
|
||||||
# required for saving
|
# required for saving
|
||||||
self.timetrial_event_id[game_ver] = self.timetrial_event.get(
|
self.timetrial_event_id[game_ver] = self.timetrial_event.get(
|
||||||
game_ver
|
game_ver
|
||||||
).get("timetrial_event_id")
|
).get("timetrial_event_id")
|
||||||
|
else:
|
||||||
|
self.logger.warning("Timetrial configuration is invalid, please update your idac.yaml config!")
|
||||||
|
|
||||||
# load the user configured round event (only one)
|
# load the user configured round event (only one)
|
||||||
asyncio.create_task(self._load_round_event())
|
asyncio.create_task(self._load_round_event())
|
||||||
@ -345,7 +352,7 @@ class IDACSeason2(IDACBase):
|
|||||||
"last_round_event": self.last_round_event,
|
"last_round_event": self.last_round_event,
|
||||||
"last_round_event_ranking": self.last_round_event_ranking,
|
"last_round_event_ranking": self.last_round_event_ranking,
|
||||||
"round_event_exp": [],
|
"round_event_exp": [],
|
||||||
"stamp_info": self.stamp_info[ver_str],
|
"stamp_info": self.stamp_info.get(ver_str, []),
|
||||||
# 0 = use default data, 1+ = server version of timereleasedata response
|
# 0 = use default data, 1+ = server version of timereleasedata response
|
||||||
"timerelease_no": self.timerelease_no,
|
"timerelease_no": self.timerelease_no,
|
||||||
# 0 = use default data, 1+ = server version of gachadata response
|
# 0 = use default data, 1+ = server version of gachadata response
|
||||||
@ -513,7 +520,7 @@ class IDACSeason2(IDACBase):
|
|||||||
"theory_close_version": "9.99.99",
|
"theory_close_version": "9.99.99",
|
||||||
# unlocks the version specific special mode
|
# unlocks the version specific special mode
|
||||||
"special_mode_data": special_mode_data,
|
"special_mode_data": special_mode_data,
|
||||||
"timetrial_event_data": self.timetrial_event[ver_str],
|
"timetrial_event_data": self.timetrial_event.get(ver_str, {}),
|
||||||
"number_lottery_data": [
|
"number_lottery_data": [
|
||||||
{
|
{
|
||||||
"m_number_lottery_win_number_no": 10,
|
"m_number_lottery_win_number_no": 10,
|
||||||
@ -1325,14 +1332,15 @@ class IDACSeason2(IDACBase):
|
|||||||
|
|
||||||
# get the user's timetrial event data
|
# get the user's timetrial event data
|
||||||
timetrial_event_data = {}
|
timetrial_event_data = {}
|
||||||
timetrial = await self.data.item.get_timetrial_event(
|
if ver_str in self.timetrial_event_id:
|
||||||
user_id, self.timetrial_event_id[ver_str]
|
timetrial = await self.data.item.get_timetrial_event(
|
||||||
)
|
user_id, self.timetrial_event_id[ver_str]
|
||||||
if timetrial is not None:
|
)
|
||||||
timetrial_event_data = {
|
if timetrial is not None:
|
||||||
"timetrial_event_id": timetrial["timetrial_event_id"],
|
timetrial_event_data = {
|
||||||
"point": timetrial["point"],
|
"timetrial_event_id": timetrial["timetrial_event_id"],
|
||||||
}
|
"point": timetrial["point"],
|
||||||
|
}
|
||||||
|
|
||||||
# check if the battle gift event is active
|
# check if the battle gift event is active
|
||||||
if self.battle_gift_event:
|
if self.battle_gift_event:
|
||||||
@ -2075,9 +2083,17 @@ class IDACSeason2(IDACBase):
|
|||||||
ver_str = self._headers_to_version(headers)
|
ver_str = self._headers_to_version(headers)
|
||||||
|
|
||||||
# update the timetrial event points
|
# update the timetrial event points
|
||||||
await self.data.item.put_timetrial_event(
|
timetrial_event_data = {}
|
||||||
user_id, self.timetrial_event_id[ver_str], event_point
|
if ver_str in self.timetrial_event_id:
|
||||||
)
|
timetrial_event_id = self.timetrial_event_id[ver_str]
|
||||||
|
await self.data.item.put_timetrial_event(
|
||||||
|
user_id, timetrial_event_id, event_point
|
||||||
|
)
|
||||||
|
|
||||||
|
timetrial_event_data = {
|
||||||
|
"timetrial_event_id": timetrial_event_id,
|
||||||
|
"point": event_point,
|
||||||
|
}
|
||||||
|
|
||||||
# update the tips play count
|
# update the tips play count
|
||||||
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
tips = await self.data.profile.get_profile_tips(user_id, self.version)
|
||||||
@ -2087,8 +2103,6 @@ class IDACSeason2(IDACBase):
|
|||||||
{"timetrial_play_count": tips["timetrial_play_count"] + 1},
|
{"timetrial_play_count": tips["timetrial_play_count"] + 1},
|
||||||
)
|
)
|
||||||
|
|
||||||
ver_str = self._headers_to_version(headers)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"status_code": "0",
|
"status_code": "0",
|
||||||
"course_rank": course_rank,
|
"course_rank": course_rank,
|
||||||
@ -2096,10 +2110,7 @@ class IDACSeason2(IDACBase):
|
|||||||
"location_course_store_rank": course_rank,
|
"location_course_store_rank": course_rank,
|
||||||
"car_use_count": [],
|
"car_use_count": [],
|
||||||
"maker_use_count": [],
|
"maker_use_count": [],
|
||||||
"timetrial_event_data": {
|
"timetrial_event_data": timetrial_event_data,
|
||||||
"timetrial_event_id": self.timetrial_event_id[ver_str],
|
|
||||||
"point": event_point,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async def handle_user_updatestoryresult_request(self, data: Dict, headers: Dict):
|
async def handle_user_updatestoryresult_request(self, data: Dict, headers: Dict):
|
||||||
|
Loading…
Reference in New Issue
Block a user