Merge branch 'develop' into diva_handler_classes

This commit is contained in:
Hay1tsme
2024-01-12 12:15:28 -05:00
195 changed files with 6255 additions and 5300 deletions

View File

@@ -7,4 +7,3 @@ index = DivaServlet
database = DivaData
reader = DivaReader
game_codes = [DivaConstants.GAME_CODE]
current_schema_version = 6

View File

@@ -1,8 +1,7 @@
from datetime import datetime
from typing import Any, List, Dict
import datetime
from typing import Dict
import logging
import json
import urllib
import urllib.parse
from threading import Thread
from core.config import CoreConfig
@@ -25,14 +24,13 @@ class DivaBase:
dt = datetime.now()
self.time_lut = parse.quote(dt.strftime("%Y-%m-%d %H:%M:%S:16.0"))
def handle_test_request(self, data: bytes) -> str:
pass
async def handle_test_request(self, data: Dict) -> Dict:
return ""
def handle_game_init_request(self, data: bytes) -> str:
req = GameInitRequest(data)
return None
async def handle_game_init_request(self, data: Dict) -> Dict:
return f""
def handle_attend_request(self, data: bytes) -> str:
async def handle_attend_request(self, data: bytes) -> str:
req = AttendRequest(data)
resp = AttendResponse(req.req_id)
@@ -54,7 +52,7 @@ class DivaBase:
return resp.make()
def handle_ping_request(self, data: bytes) -> str:
async def handle_ping_request(self, data: bytes) -> str:
encoded = "&"
params = {
"ping_b_msg": f"Welcome to {self.core_cfg.server.name} network!" if not self.game_config.server.banner_msg else self.game_config.server.banner_msg,
@@ -98,7 +96,7 @@ class DivaBase:
return encoded
def handle_pv_list_request(self, data: bytes) -> str:
async def handle_pv_list_request(self, data: Dict) -> Dict:
pvlist = ""
with open(r"titles/diva/data/PvList0.dat", encoding="utf-8") as shop:
lines = shop.readlines()
@@ -135,10 +133,10 @@ class DivaBase:
return response
def handle_shop_catalog_request(self, data: bytes) -> str:
async def handle_shop_catalog_request(self, data: Dict) -> Dict:
catalog = ""
shopList = self.data.static.get_enabled_shops(self.version)
shopList = await self.data.static.get_enabled_shops(self.version)
if not shopList:
with open(r"titles/diva/data/ShopCatalog.dat", encoding="utf-8") as shop:
lines = shop.readlines()
@@ -173,9 +171,9 @@ class DivaBase:
return response
def handle_buy_module_request(self, data: bytes) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
module = self.data.static.get_enabled_shop(self.version, int(data["mdl_id"]))
async def handle_buy_module_request(self, data: Dict) -> Dict:
profile = await self.data.profile.get_profile(data["pd_id"], self.version)
module = await self.data.static.get_enabled_shop(self.version, int(data["mdl_id"]))
# make sure module is available to purchase
if not module:
@@ -187,11 +185,11 @@ class DivaBase:
new_vcld_pts = profile["vcld_pts"] - int(data["mdl_price"])
self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"])
await self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
await self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"])
# generate the mdl_have string
mdl_have = self.data.module.get_modules_have_string(data["pd_id"], self.version)
mdl_have = await self.data.module.get_modules_have_string(data["pd_id"], self.version)
response = "&shp_rslt=1"
response += f"&mdl_id={data['mdl_id']}"
@@ -200,10 +198,10 @@ class DivaBase:
return response
def handle_cstmz_itm_ctlg_request(self, data: bytes) -> str:
async def handle_cstmz_itm_ctlg_request(self, data: Dict) -> Dict:
catalog = ""
itemList = self.data.static.get_enabled_items(self.version)
itemList = await self.data.static.get_enabled_items(self.version)
if not itemList:
with open(r"titles/diva/data/ItemCatalog.dat", encoding="utf-8") as item:
lines = item.readlines()
@@ -238,9 +236,9 @@ class DivaBase:
return response
def handle_buy_cstmz_itm_request(self, data: bytes) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
item = self.data.static.get_enabled_item(
async def handle_buy_cstmz_itm_request(self, data: Dict) -> Dict:
profile = await self.data.profile.get_profile(data["pd_id"], self.version)
item = await self.data.static.get_enabled_item(
self.version, int(data["cstmz_itm_id"])
)
@@ -255,14 +253,14 @@ class DivaBase:
new_vcld_pts = profile["vcld_pts"] - int(data["cstmz_itm_price"])
# save new Vocaloid Points balance
self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
await self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
self.data.customize.put_customize_item(
await self.data.customize.put_customize_item(
data["pd_id"], self.version, data["cstmz_itm_id"]
)
# generate the cstmz_itm_have string
cstmz_itm_have = self.data.customize.get_customize_items_have_string(
cstmz_itm_have = await self.data.customize.get_customize_items_have_string(
data["pd_id"], self.version
)
@@ -273,7 +271,7 @@ class DivaBase:
return response
def handle_festa_info_request(self, data: bytes) -> str:
async def handle_festa_info_request(self, data: Dict) -> Dict:
encoded = "&"
params = {
"fi_id": "1,2",
@@ -296,7 +294,7 @@ class DivaBase:
return encoded
def handle_contest_info_request(self, data: bytes) -> str:
async def handle_contest_info_request(self, data: Dict) -> Dict:
response = ""
response += f"&ci_lut={self.time_lut}"
@@ -304,10 +302,10 @@ class DivaBase:
return response
def handle_qst_inf_request(self, data: bytes) -> str:
async def handle_qst_inf_request(self, data: Dict) -> Dict:
quest = ""
questList = self.data.static.get_enabled_quests(self.version)
questList = await self.data.static.get_enabled_quests(self.version)
if not questList:
with open(r"titles/diva/data/QuestInfo.dat", encoding="utf-8") as shop:
lines = shop.readlines()
@@ -354,47 +352,47 @@ class DivaBase:
return response
def handle_nv_ranking_request(self, data: bytes) -> str:
pass
async def handle_nv_ranking_request(self, data: Dict) -> Dict:
return f""
def handle_ps_ranking_request(self, data: bytes) -> str:
pass
async def handle_ps_ranking_request(self, data: Dict) -> Dict:
return f""
def handle_ng_word_request(self, data: bytes) -> str:
pass
async def handle_ng_word_request(self, data: Dict) -> Dict:
return f""
def handle_rmt_wp_list_request(self, data: bytes) -> str:
pass
async def handle_rmt_wp_list_request(self, data: Dict) -> Dict:
return f""
def handle_pv_def_chr_list_request(self, data: bytes) -> str:
pass
async def handle_pv_def_chr_list_request(self, data: Dict) -> Dict:
return f""
def handle_pv_ng_mdl_list_request(self, data: bytes) -> str:
pass
async def handle_pv_ng_mdl_list_request(self, data: Dict) -> Dict:
return f""
def handle_cstmz_itm_ng_mdl_lst_request(self, data: bytes) -> str:
pass
async def handle_cstmz_itm_ng_mdl_lst_request(self, data: Dict) -> Dict:
return f""
def handle_banner_info_request(self, data: bytes) -> str:
pass
async def handle_banner_info_request(self, data: Dict) -> Dict:
return f""
def handle_banner_data_request(self, data: bytes) -> str:
pass
async def handle_banner_data_request(self, data: Dict) -> Dict:
return f""
def handle_cm_ply_info_request(self, data: bytes) -> str:
pass
async def handle_cm_ply_info_request(self, data: Dict) -> Dict:
return f""
def handle_pstd_h_ctrl_request(self, data: bytes) -> str:
pass
async def handle_pstd_h_ctrl_request(self, data: Dict) -> Dict:
return f""
def handle_pstd_item_ng_lst_request(self, data: bytes) -> str:
pass
async def handle_pstd_item_ng_lst_request(self, data: Dict) -> Dict:
return f""
def handle_pre_start_request(self, data: bytes) -> str:
async def handle_pre_start_request(self, data: bytes) -> str:
req = PreStartRequest(data)
resp = PreStartResponse(req.req_id, req.aime_id)
profile = self.data.profile.get_profile(req.aime_id, self.version)
profile_shop = self.data.item.get_shop(req.aime_id, self.version)
profile = await self.data.profile.get_profile(req.aime_id, self.version)
profile_shop = await self.data.item.get_shop(req.aime_id, self.version)
if profile is None:
return f"&ps_result=-3"
@@ -413,19 +411,19 @@ class DivaBase:
return resp.make()
def handle_registration_request(self, data: bytes) -> str:
async def handle_registration_request(self, data: bytes) -> str:
req = RegisterRequest(data)
pd_id = self.data.profile.create_profile(
pd_id = await self.data.profile.create_profile(
self.version, req.aime_id, req.player_name
)
if pd_id is None:
return "&cd_adm_result=-1"
return RegisterResponse(req.req_id, req.aime_id).make()
def handle_start_request(self, data: bytes) -> str:
async def handle_start_request(self, data: bytes) -> str:
req = StartRequest(data)
profile = self.data.profile.get_profile(req.pd_id, self.version)
profile_shop = self.data.item.get_shop(req.pd_id, self.version)
profile = await self.data.profile.get_profile(req.pd_id, self.version)
profile_shop = await self.data.item.get_shop(req.pd_id, self.version)
if profile is None:
return
@@ -442,13 +440,13 @@ class DivaBase:
# generate the mdl_have string if "unlock_all_modules" is disabled
if not self.game_config.mods.unlock_all_modules:
resp.mdl_have = self.data.module.get_modules_have_string(
resp.mdl_have = await self.data.module.get_modules_have_string(
req.pd_id, self.version
)
# generate the cstmz_itm_have string if "unlock_all_items" is disabled
if not self.game_config.mods.unlock_all_items:
resp.cstmz_itm_have = self.data.customize.get_customize_items_have_string(
resp.cstmz_itm_have = await self.data.customize.get_customize_items_have_string(
req.pd_id, self.version
)
@@ -476,7 +474,7 @@ class DivaBase:
}
# get clear status from user scores
pv_records = self.data.score.get_best_scores(req.pd_id)
pv_records = await self.data.score.get_best_scores(req.pd_id)
clear_status = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
if pv_records is not None:
@@ -523,12 +521,12 @@ class DivaBase:
return resp.make()
def handle_pd_unlock_request(self, data: bytes) -> str:
async def handle_pd_unlock_request(self, data: bytes) -> str:
pass
def handle_spend_credit_request(self, data: bytes) -> str:
async def handle_spend_credit_request(self, data: bytes) -> str:
req = SpendCreditRequest(data)
profile = self.data.profile.get_profile(req.pd_id, self.version)
profile = await self.data.profile.get_profile(req.pd_id, self.version)
if profile is None:
return
@@ -602,30 +600,30 @@ class DivaBase:
return pv_result
def task_generateScoreData(self, pd_id: int, difficulty: int, pd_by_pv_id: str, song: int):
async def task_generateScoreData(self, pd_id: int, difficulty: int, pd_by_pv_id: str, song: int):
if int(song) > 0:
# the request do not send a edition so just perform a query best score and ranking for each edition.
# 0=ORIGINAL, 1=EXTRA
pd_db_song_0 = self.data.score.get_best_user_score(
pd_db_song_0 = await self.data.score.get_best_user_score(
pd_id, int(song), difficulty, edition=0
)
pd_db_song_1 = self.data.score.get_best_user_score(
pd_db_song_1 = await self.data.score.get_best_user_score(
pd_id, int(song), difficulty, edition=1
)
pd_db_ranking_0, pd_db_ranking_1 = None, None
if pd_db_song_0:
pd_db_ranking_0 = self.data.score.get_global_ranking(
pd_db_ranking_0 = await self.data.score.get_global_ranking(
pd_id, int(song), difficulty, edition=0
)
if pd_db_song_1:
pd_db_ranking_1 = self.data.score.get_global_ranking(
pd_db_ranking_1 = await self.data.score.get_global_ranking(
pd_id, int(song), difficulty, edition=1
)
pd_db_customize = self.data.pv_customize.get_pv_customize(
pd_db_customize = await self.data.pv_customize.get_pv_customize(
pd_id, int(song)
)
@@ -643,7 +641,7 @@ class DivaBase:
pd_by_pv_id.append(urllib.parse.quote(f"{song}***"))
pd_by_pv_id.append(",")
def handle_get_pv_pd_request(self, data: Dict) -> Dict:
async def handle_get_pv_pd_request(self, data: Dict) -> Dict:
req = GetPvPdRequest(data)
pv = ""
@@ -651,7 +649,7 @@ class DivaBase:
pd_by_pv_id = []
for song in req.pd_pv_id_lst:
thread_ScoreData = Thread(target=self.task_generateScoreData(req.pd_id, req.difficulty, pd_by_pv_id, song))
thread_ScoreData = Thread(target=await self.task_generateScoreData(req.pd_id, req.difficulty, pd_by_pv_id, song))
threads.append(thread_ScoreData)
for x in threads:
@@ -672,13 +670,13 @@ class DivaBase:
return resp.make()
def handle_stage_start_request(self, data: bytes) -> str:
pass
async def handle_stage_start_request(self, data: Dict) -> Dict:
return f""
def handle_stage_result_request(self, data: bytes) -> str:
async def handle_stage_result_request(self, data: bytes) -> str:
req = StageResultRequest(data)
resp = StageResultResponse(req.cmd, req.req_id)
profile = self.data.profile.get_profile(req.pd_id, self.version)
profile = await self.data.profile.get_profile(req.pd_id, self.version)
pd_song_list = req.stg_ply_pv_id
pd_song_difficulty = req.stg_difficulty
@@ -696,14 +694,14 @@ class DivaBase:
for index, value in enumerate(pd_song_list):
if pd_song_list[index] > 0:
profile_pd_db_song = self.data.score.get_best_user_score(
profile_pd_db_song = await self.data.score.get_best_user_score(
req.pd_id,
pd_song_list[index],
pd_song_difficulty[index],
pd_song_edition[index],
)
if profile_pd_db_song is None:
self.data.score.put_best_score(
await self.data.score.put_best_score(
req.pd_id,
self.version,
pd_song_list[index],
@@ -720,7 +718,7 @@ class DivaBase:
pd_song_worst_cnt[index],
pd_song_max_combo[index],
)
self.data.score.put_playlog(
await self.data.score.put_playlog(
req.pd_id,
self.version,
pd_song_list[index],
@@ -738,7 +736,7 @@ class DivaBase:
pd_song_max_combo[index],
)
elif int(pd_song_max_score[index]) >= int(profile_pd_db_song["score"]):
self.data.score.put_best_score(
await self.data.score.put_best_score(
req.pd_id,
self.version,
pd_song_list[index],
@@ -755,7 +753,7 @@ class DivaBase:
pd_song_worst_cnt[index],
pd_song_max_combo[index],
)
self.data.score.put_playlog(
await self.data.score.put_playlog(
req.pd_id,
self.version,
pd_song_list[index],
@@ -773,7 +771,7 @@ class DivaBase:
pd_song_max_combo[index],
)
elif int(pd_song_max_score[index]) != int(profile_pd_db_song["score"]):
self.data.score.put_playlog(
await self.data.score.put_playlog(
req.pd_id,
self.version,
pd_song_list[index],
@@ -794,7 +792,7 @@ class DivaBase:
# Profile saving based on registration list
# Calculate new level
best_scores = self.data.score.get_best_scores(req.pd_id)
best_scores = await self.data.score.get_best_scores(data["pd_id"])
total_atn_pnt = 0
for best_score in best_scores:
@@ -822,7 +820,7 @@ class DivaBase:
response += f"&lv_pnt_old={int(profile['lv_pnt'])}"
# update the profile and commit changes to the db
self.data.profile.update_profile(
await self.data.profile.update_profile(
profile["user"],
lv_num=new_level,
lv_pnt=new_level_pnt,
@@ -870,17 +868,17 @@ class DivaBase:
return resp.make()
def handle_end_request(self, data: bytes) -> str:
async def handle_end_request(self, data: bytes) -> str:
req = EndRequest(data)
profile = self.data.profile.get_profile(req.pd_id, self.version)
profile = await self.data.profile.get_profile(req.pd_id, self.version)
self.data.profile.update_profile(
await self.data.profile.update_profile(
profile["user"], my_qst_id=req.my_qst_id, my_qst_sts=req.my_qst_sts
)
return None
def handle_shop_exit_request(self, data: bytes) -> str:
self.data.item.put_shop(
async def handle_shop_exit_request(self, data: bytes) -> str:
await self.data.item.put_shop(
data["pd_id"],
self.version,
data["mdl_eqp_cmn_ary"],
@@ -888,7 +886,7 @@ class DivaBase:
data["ms_itm_flg_cmn_ary"],
)
if int(data["use_pv_mdl_eqp"]) == 1:
self.data.pv_customize.put_pv_customize(
await self.data.pv_customize.put_pv_customize(
data["pd_id"],
self.version,
data["ply_pv_id"],
@@ -897,7 +895,7 @@ class DivaBase:
data["ms_itm_flg_pv_ary"],
)
else:
self.data.pv_customize.put_pv_customize(
await self.data.pv_customize.put_pv_customize(
data["pd_id"],
self.version,
data["ply_pv_id"],
@@ -909,8 +907,8 @@ class DivaBase:
response = "&shp_rslt=1"
return response
def handle_card_procedure_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["aime_id"], self.version)
async def handle_card_procedure_request(self, data: Dict) -> str:
profile = await self.data.profile.get_profile(data["aime_id"], self.version)
if profile is None:
return "&cd_adm_result=0"
@@ -929,8 +927,8 @@ class DivaBase:
return response
def handle_change_name_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
async def handle_change_name_request(self, data: Dict) -> str:
profile = await self.data.profile.get_profile(data["pd_id"], self.version)
# make sure user has enough Vocaloid Points
if profile["vcld_pts"] < int(data["chg_name_price"]):
@@ -938,7 +936,7 @@ class DivaBase:
# update the vocaloid points and player name
new_vcld_pts = profile["vcld_pts"] - int(data["chg_name_price"])
self.data.profile.update_profile(
await self.data.profile.update_profile(
profile["user"], player_name=data["player_name"], vcld_pts=new_vcld_pts
)
@@ -949,15 +947,15 @@ class DivaBase:
return response
def handle_change_passwd_request(self, data: Dict) -> str:
profile = self.data.profile.get_profile(data["pd_id"], self.version)
async def handle_change_passwd_request(self, data: Dict) -> str:
profile = await self.data.profile.get_profile(data["pd_id"], self.version)
# TODO: return correct error number instead of 0
if data["passwd"] != profile["passwd"]:
return "&cd_adm_result=0"
# set password to true and update the saved password
self.data.profile.update_profile(
await self.data.profile.update_profile(
profile["user"], passwd_stat=1, passwd=data["new_passwd"]
)

View File

@@ -1,4 +1,6 @@
from twisted.web.http import Request
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.routing import Route
import yaml
import logging, coloredlogs
from logging.handlers import TimedRotatingFileHandler
@@ -51,17 +53,16 @@ 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_routes(self) -> List[Route]:
return [
Route("/DivaServlet/", self.render_POST, methods=['POST'])
]
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}:{Utils.get_title_port(self.core_cfg)}/DivaServlet/", "")
return (f"http://{self.core_cfg.server.hostname}:{Utils.get_title_port(self.core_cfg)}/DivaServlet/", self.core_cfg.server.hostname)
return (f"http://{self.core_cfg.title.hostname}/DivaServlet/", "")
return (f"http://{self.core_cfg.server.hostname}/DivaServlet/", self.core_cfg.server.hostname)
@classmethod
def is_game_enabled(
@@ -82,6 +83,7 @@ class DivaServlet(BaseServlet):
req_raw = request.content.getvalue()
url_header = request.getAllHeaders()
# Ping Dispatch
if "THIS_STRING_SEPARATES" in str(url_header):
binary_request = req_raw.splitlines()
binary_cmd_decoded = binary_request[3].decode("utf-8")

View File

@@ -28,7 +28,7 @@ class DivaReader(BaseReader):
self.logger.error(f"Invalid project diva version {version}")
exit(1)
def read(self) -> None:
async def read(self) -> None:
pull_bin_ram = True
pull_bin_rom = True
pull_opt_rom = True
@@ -48,14 +48,14 @@ class DivaReader(BaseReader):
self.logger.warning("No option directory specified, skipping")
if pull_bin_ram:
self.read_ram(f"{self.bin_dir}/ram")
await self.read_ram(f"{self.bin_dir}/ram")
if pull_bin_rom:
self.read_rom(f"{self.bin_dir}/rom")
await self.read_rom(f"{self.bin_dir}/rom")
if pull_opt_rom:
for dir in opt_dirs:
self.read_rom(f"{dir}/rom")
await self.read_rom(f"{dir}/rom")
def read_ram(self, ram_root_dir: str) -> None:
async def read_ram(self, ram_root_dir: str) -> None:
self.logger.info(f"Read RAM from {ram_root_dir}")
if path.exists(f"{ram_root_dir}/databank"):
@@ -91,7 +91,7 @@ class DivaReader(BaseReader):
f"Added shop item {split[x+0]}"
)
self.data.static.put_shop(
await self.data.static.put_shop(
self.version,
split[x + 0],
split[x + 2],
@@ -109,7 +109,7 @@ class DivaReader(BaseReader):
for x in range(0, len(split), 7):
self.logger.info(f"Added item {split[x+0]}")
self.data.static.put_items(
await self.data.static.put_items(
self.version,
split[x + 0],
split[x + 2],
@@ -123,7 +123,7 @@ class DivaReader(BaseReader):
elif file.startswith("QuestInfo") and len(split) >= 9:
self.logger.info(f"Added quest {split[0]}")
self.data.static.put_quests(
await self.data.static.put_quests(
self.version,
split[0],
split[6],
@@ -141,7 +141,7 @@ class DivaReader(BaseReader):
else:
self.logger.warning(f"Databank folder not found in {ram_root_dir}, skipping")
def read_rom(self, rom_root_dir: str) -> None:
async def read_rom(self, rom_root_dir: str) -> None:
self.logger.info(f"Read ROM from {rom_root_dir}")
pv_list: Dict[str, Dict] = {}
@@ -199,7 +199,7 @@ class DivaReader(BaseReader):
diff = pv_data["difficulty"]["easy"]["0"]["level"].split("_")
self.logger.info(f"Added song {song_id} chart 0")
self.data.static.put_music(
await self.data.static.put_music(
self.version,
song_id,
0,
@@ -220,7 +220,7 @@ class DivaReader(BaseReader):
diff = pv_data["difficulty"]["normal"]["0"]["level"].split("_")
self.logger.info(f"Added song {song_id} chart 1")
self.data.static.put_music(
await self.data.static.put_music(
self.version,
song_id,
1,
@@ -238,7 +238,7 @@ class DivaReader(BaseReader):
diff = pv_data["difficulty"]["hard"]["0"]["level"].split("_")
self.logger.info(f"Added song {song_id} chart 2")
self.data.static.put_music(
await self.data.static.put_music(
self.version,
song_id,
2,
@@ -257,7 +257,7 @@ class DivaReader(BaseReader):
diff = pv_data["difficulty"]["extreme"]["0"]["level"].split("_")
self.logger.info(f"Added song {song_id} chart 3")
self.data.static.put_music(
await self.data.static.put_music(
self.version,
song_id,
3,
@@ -275,7 +275,7 @@ class DivaReader(BaseReader):
diff = pv_data["difficulty"]["extreme"]["1"]["level"].split("_")
self.logger.info(f"Added song {song_id} chart 4")
self.data.static.put_music(
await self.data.static.put_music(
self.version,
song_id,
4,

View File

@@ -25,10 +25,10 @@ customize = Table(
class DivaCustomizeItemData(BaseData):
def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None:
async def put_customize_item(self, aime_id: int, version: int, item_id: int) -> None:
sql = insert(customize).values(version=version, user=aime_id, item_id=item_id)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
self.logger.error(
f"{__name__} Failed to insert diva profile customize item! aime id: {aime_id} item: {item_id}"
@@ -36,7 +36,7 @@ class DivaCustomizeItemData(BaseData):
return None
return result.lastrowid
def get_customize_items(self, aime_id: int, version: int) -> Optional[List[Dict]]:
async def get_customize_items(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and an aime id, return all the customize items, not used directly
"""
@@ -44,12 +44,12 @@ class DivaCustomizeItemData(BaseData):
and_(customize.c.version == version, customize.c.user == aime_id)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_customize_items_have_string(self, aime_id: int, version: int) -> str:
async def get_customize_items_have_string(self, aime_id: int, version: int) -> str:
"""
Given a game version and an aime id, return the cstmz_itm_have hex string
required for diva directly

View File

@@ -26,7 +26,7 @@ shop = Table(
class DivaItemData(BaseData):
def put_shop(
async def put_shop(
self,
aime_id: int,
version: int,
@@ -48,7 +48,7 @@ class DivaItemData(BaseData):
ms_itm_flg_ary=ms_itm_flg_ary,
)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
self.logger.error(
f"{__name__} Failed to insert diva profile! aime id: {aime_id} array: {mdl_eqp_ary}"
@@ -56,13 +56,13 @@ class DivaItemData(BaseData):
return None
return result.lastrowid
def get_shop(self, aime_id: int, version: int) -> Optional[List[Dict]]:
async def get_shop(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and either a profile or aime id, return the profile
"""
sql = shop.select(and_(shop.c.version == version, shop.c.user == aime_id))
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()

View File

@@ -23,10 +23,10 @@ module = Table(
class DivaModuleData(BaseData):
def put_module(self, aime_id: int, version: int, module_id: int) -> None:
async def put_module(self, aime_id: int, version: int, module_id: int) -> None:
sql = insert(module).values(version=version, user=aime_id, module_id=module_id)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
self.logger.error(
f"{__name__} Failed to insert diva profile module! aime id: {aime_id} module: {module_id}"
@@ -34,18 +34,18 @@ class DivaModuleData(BaseData):
return None
return result.lastrowid
def get_modules(self, aime_id: int, version: int) -> Optional[List[Dict]]:
async def get_modules(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and an aime id, return all the modules, not used directly
"""
sql = module.select(and_(module.c.version == version, module.c.user == aime_id))
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_modules_have_string(self, aime_id: int, version: int) -> str:
async def get_modules_have_string(self, aime_id: int, version: int) -> str:
"""
Given a game version and an aime id, return the mdl_have hex string
required for diva directly

View File

@@ -70,7 +70,7 @@ profile = Table(
class DivaProfileData(BaseData):
def create_profile(
async def create_profile(
self, version: int, aime_id: int, player_name: str
) -> Optional[int]:
"""
@@ -82,7 +82,7 @@ class DivaProfileData(BaseData):
conflict = sql.on_duplicate_key_update(player_name=sql.inserted.player_name)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
self.logger.error(
f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}"
@@ -90,21 +90,21 @@ class DivaProfileData(BaseData):
return None
return result.lastrowid
def update_profile(self, aime_id: int, **profile_args) -> None:
async def update_profile(self, aime_id: int, **profile_args) -> None:
"""
Given an aime_id update the profile corresponding to the arguments
which are the diva_profile Columns
"""
sql = profile.update(profile.c.user == aime_id).values(**profile_args)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
self.logger.error(
f"update_profile: failed to update profile! profile: {aime_id}"
)
return None
def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]:
async def get_profile(self, aime_id: int, version: int) -> Optional[List[Dict]]:
"""
Given a game version and either a profile or aime id, return the profile
"""
@@ -112,7 +112,7 @@ class DivaProfileData(BaseData):
and_(profile.c.version == version, profile.c.user == aime_id)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()

View File

@@ -39,7 +39,7 @@ pv_customize = Table(
class DivaPvCustomizeData(BaseData):
def put_pv_customize(
async def put_pv_customize(
self,
aime_id: int,
version: int,
@@ -64,7 +64,7 @@ class DivaPvCustomizeData(BaseData):
ms_itm_flg_ary=ms_itm_flg_ary,
)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
self.logger.error(
f"{__name__} Failed to insert diva pv customize! aime id: {aime_id}"
@@ -72,7 +72,7 @@ class DivaPvCustomizeData(BaseData):
return None
return result.lastrowid
def get_pv_customize(self, aime_id: int, pv_id: int) -> Optional[List[Dict]]:
async def get_pv_customize(self, aime_id: int, pv_id: int) -> Optional[List[Dict]]:
"""
Given either a profile or aime id, return a Pv Customize row
"""
@@ -80,7 +80,7 @@ class DivaPvCustomizeData(BaseData):
and_(pv_customize.c.user == aime_id, pv_customize.c.pv_id == pv_id)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()

View File

@@ -57,7 +57,7 @@ playlog = Table(
class DivaScoreData(BaseData):
def put_best_score(
async def put_best_score(
self,
user_id: int,
game_version: int,
@@ -109,7 +109,7 @@ class DivaScoreData(BaseData):
max_combo=max_combo,
)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
self.logger.error(
f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}"
@@ -118,7 +118,7 @@ class DivaScoreData(BaseData):
return result.lastrowid
def put_playlog(
async def put_playlog(
self,
user_id: int,
game_version: int,
@@ -157,7 +157,7 @@ class DivaScoreData(BaseData):
max_combo=max_combo,
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
self.logger.error(
f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}"
@@ -166,7 +166,7 @@ class DivaScoreData(BaseData):
return result.lastrowid
def get_best_user_score(
async def get_best_user_score(
self, user_id: int, pv_id: int, difficulty: int, edition: int
) -> Optional[Row]:
sql = score.select(
@@ -178,12 +178,12 @@ class DivaScoreData(BaseData):
)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_top3_scores(
async def get_top3_scores(
self, pv_id: int, difficulty: int, edition: int
) -> Optional[List[Row]]:
sql = (
@@ -198,12 +198,12 @@ class DivaScoreData(BaseData):
.limit(3)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_global_ranking(
async def get_global_ranking(
self, user_id: int, pv_id: int, difficulty: int, edition: int
) -> Optional[List[Row]]:
# get the subquery max score of a user with pv_id, difficulty and
@@ -227,15 +227,15 @@ class DivaScoreData(BaseData):
score.c.edition == edition,
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_best_scores(self, user_id: int) -> Optional[List[Row]]:
async def get_best_scores(self, user_id: int) -> Optional[List[Row]]:
sql = score.select(score.c.user == user_id)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()

View File

@@ -83,7 +83,7 @@ items = Table(
class DivaStaticData(BaseData):
def put_quests(
async def put_quests(
self,
version: int,
questId: int,
@@ -111,22 +111,22 @@ class DivaStaticData(BaseData):
conflict = sql.on_duplicate_key_update(name=name)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
return None
return result.lastrowid
def get_enabled_quests(self, version: int) -> Optional[List[Row]]:
async def get_enabled_quests(self, version: int) -> Optional[List[Row]]:
sql = select(quests).where(
and_(quests.c.version == version, quests.c.quest_enable == True)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def put_shop(
async def put_shop(
self,
version: int,
shopId: int,
@@ -150,12 +150,12 @@ class DivaStaticData(BaseData):
conflict = sql.on_duplicate_key_update(name=name)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
return None
return result.lastrowid
def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]:
async def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]:
sql = select(shop).where(
and_(
shop.c.version == version,
@@ -164,22 +164,22 @@ class DivaStaticData(BaseData):
)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_enabled_shops(self, version: int) -> Optional[List[Row]]:
async def get_enabled_shops(self, version: int) -> Optional[List[Row]]:
sql = select(shop).where(
and_(shop.c.version == version, shop.c.enabled == True)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def put_items(
async def put_items(
self,
version: int,
itemId: int,
@@ -203,12 +203,12 @@ class DivaStaticData(BaseData):
conflict = sql.on_duplicate_key_update(name=name)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
return None
return result.lastrowid
def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]:
async def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]:
sql = select(items).where(
and_(
items.c.version == version,
@@ -217,22 +217,22 @@ class DivaStaticData(BaseData):
)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()
def get_enabled_items(self, version: int) -> Optional[List[Row]]:
async def get_enabled_items(self, version: int) -> Optional[List[Row]]:
sql = select(items).where(
and_(items.c.version == version, items.c.enabled == True)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def put_music(
async def put_music(
self,
version: int,
song: int,
@@ -271,12 +271,12 @@ class DivaStaticData(BaseData):
date=date,
)
result = self.execute(conflict)
result = await self.execute(conflict)
if result is None:
return None
return result.lastrowid
def get_music(
async def get_music(
self, version: int, song_id: Optional[int] = None
) -> Optional[List[Row]]:
if song_id is None:
@@ -289,12 +289,12 @@ class DivaStaticData(BaseData):
)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchall()
def get_music_chart(
async def get_music_chart(
self, version: int, song_id: int, chart_id: int
) -> Optional[List[Row]]:
sql = select(music).where(
@@ -305,7 +305,7 @@ class DivaStaticData(BaseData):
)
)
result = self.execute(sql)
result = await self.execute(sql)
if result is None:
return None
return result.fetchone()