1
0
forked from Hay1tsme/artemis

mai2: added upsert returns, fixed event reader, thanks @One3

Thanks to @One3 for helping with the events
This commit is contained in:
Dniel97 2023-04-11 17:57:21 +02:00
parent f63dd07937
commit 28c06335b6
Signed by untrusted user: Dniel97
GPG Key ID: 6180B3C768FB2E08
4 changed files with 77 additions and 12 deletions

View File

@ -98,16 +98,16 @@ class Mai2Base:
return {"length": len(charge_list), "gameChargeList": charge_list} return {"length": len(charge_list), "gameChargeList": charge_list}
def handle_upsert_client_setting_api_request(self, data: Dict) -> Dict: def handle_upsert_client_setting_api_request(self, data: Dict) -> Dict:
pass return {"returnCode": 1, "apiName": "UpsertClientSettingApi"}
def handle_upsert_client_upload_api_request(self, data: Dict) -> Dict: def handle_upsert_client_upload_api_request(self, data: Dict) -> Dict:
pass return {"returnCode": 1, "apiName": "UpsertClientUploadApi"}
def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict: def handle_upsert_client_bookkeeping_api_request(self, data: Dict) -> Dict:
pass return {"returnCode": 1, "apiName": "UpsertClientBookkeepingApi"}
def handle_upsert_client_testmode_api_request(self, data: Dict) -> Dict: def handle_upsert_client_testmode_api_request(self, data: Dict) -> Dict:
pass return {"returnCode": 1, "apiName": "UpsertClientTestmodeApi"}
def handle_get_user_preview_api_request(self, data: Dict) -> Dict: def handle_get_user_preview_api_request(self, data: Dict) -> Dict:
p = self.data.profile.get_profile_detail(data["userId"], self.version) p = self.data.profile.get_profile_detail(data["userId"], self.version)
@ -172,6 +172,8 @@ class Mai2Base:
self.data.score.put_playlog(user_id, playlog) self.data.score.put_playlog(user_id, playlog)
return {"returnCode": 1, "apiName": "UploadUserPlaylogApi"}
def handle_upsert_user_chargelog_api_request(self, data: Dict) -> Dict: def handle_upsert_user_chargelog_api_request(self, data: Dict) -> Dict:
user_id = data["userId"] user_id = data["userId"]
charge = data["userCharge"] charge = data["userCharge"]
@ -186,6 +188,8 @@ class Mai2Base:
datetime.strptime(charge["validDate"], Mai2Constants.DATE_TIME_FORMAT), datetime.strptime(charge["validDate"], Mai2Constants.DATE_TIME_FORMAT),
) )
return {"returnCode": 1, "apiName": "UpsertUserChargelogApi"}
def handle_upsert_user_all_api_request(self, data: Dict) -> Dict: def handle_upsert_user_all_api_request(self, data: Dict) -> Dict:
user_id = data["userId"] user_id = data["userId"]
upsert = data["upsertUserAll"] upsert = data["upsertUserAll"]
@ -300,8 +304,10 @@ class Mai2Base:
) )
self.data.item.put_friend_season_ranking(user_id, fsr) self.data.item.put_friend_season_ranking(user_id, fsr)
return {"returnCode": 1, "apiName": "UpsertUserAllApi"}
def handle_user_logout_api_request(self, data: Dict) -> Dict: def handle_user_logout_api_request(self, data: Dict) -> Dict:
pass return {"returnCode": 1}
def handle_get_user_data_api_request(self, data: Dict) -> Dict: def handle_get_user_data_api_request(self, data: Dict) -> Dict:
profile = self.data.profile.get_profile_detail(data["userId"], self.version) profile = self.data.profile.get_profile_detail(data["userId"], self.version)

View File

@ -29,7 +29,7 @@ class Mai2Reader(BaseReader):
f"Start importer for {Mai2Constants.game_ver_to_string(version)}" f"Start importer for {Mai2Constants.game_ver_to_string(version)}"
) )
except IndexError: except IndexError:
self.logger.error(f"Invalid maidx version {version}") self.logger.error(f"Invalid maimai DX version {version}")
exit(1) exit(1)
def read(self) -> None: def read(self) -> None:
@ -43,6 +43,7 @@ class Mai2Reader(BaseReader):
for dir in data_dirs: for dir in data_dirs:
self.logger.info(f"Read from {dir}") self.logger.info(f"Read from {dir}")
self.get_events(f"{dir}/event") self.get_events(f"{dir}/event")
self.disable_events(f"{dir}/information", f"{dir}/scoreRanking")
self.read_music(f"{dir}/music") self.read_music(f"{dir}/music")
self.read_tickets(f"{dir}/ticket") self.read_tickets(f"{dir}/ticket")
@ -64,6 +65,64 @@ class Mai2Reader(BaseReader):
) )
self.logger.info(f"Added event {id}...") self.logger.info(f"Added event {id}...")
def disable_events(
self, base_information_dir: str, base_score_ranking_dir: str
) -> None:
self.logger.info(f"Reading disabled events from {base_information_dir}...")
for root, dirs, files in os.walk(base_information_dir):
for dir in dirs:
if os.path.exists(f"{root}/{dir}/Information.xml"):
with open(f"{root}/{dir}/Information.xml", encoding="utf-8") as f:
troot = ET.fromstring(f.read())
event_id = int(troot.find("name").find("id").text)
self.data.static.toggle_game_event(
self.version, event_id, toggle=False
)
self.logger.info(f"Disabled event {event_id}...")
for root, dirs, files in os.walk(base_score_ranking_dir):
for dir in dirs:
if os.path.exists(f"{root}/{dir}/ScoreRanking.xml"):
with open(f"{root}/{dir}/ScoreRanking.xml", encoding="utf-8") as f:
troot = ET.fromstring(f.read())
event_id = int(troot.find("eventName").find("id").text)
self.data.static.toggle_game_event(
self.version, event_id, toggle=False
)
self.logger.info(f"Disabled event {event_id}...")
# manually disable events wich are known to be problematic
for event_id in [
1,
10,
220311,
220312,
220313,
220314,
220315,
220316,
220317,
220318,
20121821,
21121651,
22091511,
22091512,
22091513,
22091514,
22091515,
22091516,
22091517,
22091518,
22091519,
]:
self.data.static.toggle_game_event(self.version, event_id, toggle=False)
self.logger.info(f"Disabled event {event_id}...")
def read_music(self, base_dir: str) -> None: def read_music(self, base_dir: str) -> None:
self.logger.info(f"Reading music from {base_dir}...") self.logger.info(f"Reading music from {base_dir}...")

View File

@ -246,16 +246,16 @@ class Mai2ItemData(BaseData):
) -> None: ) -> None:
sql = insert(login_bonus).values( sql = insert(login_bonus).values(
user=user_id, user=user_id,
bonus_id=bonus_id, bonusId=bonus_id,
point=point, point=point,
is_current=is_current, isCurrent=is_current,
is_complete=is_complete, isComplete=is_complete,
) )
conflict = sql.on_duplicate_key_update( conflict = sql.on_duplicate_key_update(
point=point, point=point,
is_current=is_current, isCurrent=is_current,
is_complete=is_complete, isComplete=is_complete,
) )
result = self.execute(conflict) result = self.execute(conflict)

View File

@ -113,7 +113,7 @@ class Mai2StaticData(BaseData):
self, version: int, event_id: int, toggle: bool self, version: int, event_id: int, toggle: bool
) -> Optional[List]: ) -> Optional[List]:
sql = event.update( sql = event.update(
and_(event.c.version == version, event.c.event_id == event_id) and_(event.c.version == version, event.c.eventId == event_id)
).values(enabled=int(toggle)) ).values(enabled=int(toggle))
result = self.execute(sql) result = self.execute(sql)