forked from Hay1tsme/artemis
let black do it's magic
This commit is contained in:
@ -7,4 +7,4 @@ index = DivaServlet
|
||||
database = DivaData
|
||||
reader = DivaReader
|
||||
game_codes = [DivaConstants.GAME_CODE]
|
||||
current_schema_version = 1
|
||||
current_schema_version = 1
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import datetime
|
||||
from typing import Any, List, Dict
|
||||
import logging
|
||||
import logging
|
||||
import json
|
||||
import urllib
|
||||
|
||||
@ -9,34 +9,35 @@ from titles.diva.config import DivaConfig
|
||||
from titles.diva.const import DivaConstants
|
||||
from titles.diva.database import DivaData
|
||||
|
||||
class DivaBase():
|
||||
|
||||
class DivaBase:
|
||||
def __init__(self, cfg: CoreConfig, game_cfg: DivaConfig) -> None:
|
||||
self.core_cfg = cfg # Config file
|
||||
self.core_cfg = cfg # Config file
|
||||
self.game_config = game_cfg
|
||||
self.data = DivaData(cfg) # Database
|
||||
self.data = DivaData(cfg) # Database
|
||||
self.date_time_format = "%Y-%m-%d %H:%M:%S"
|
||||
self.logger = logging.getLogger("diva")
|
||||
self.game = DivaConstants.GAME_CODE
|
||||
self.version = DivaConstants.VER_PROJECT_DIVA_ARCADE_FUTURE_TONE
|
||||
|
||||
dt = datetime.datetime.now()
|
||||
self.time_lut=urllib.parse.quote(dt.strftime("%Y-%m-%d %H:%M:%S:16.0"))
|
||||
|
||||
self.time_lut = urllib.parse.quote(dt.strftime("%Y-%m-%d %H:%M:%S:16.0"))
|
||||
|
||||
def handle_test_request(self, data: Dict) -> Dict:
|
||||
return ""
|
||||
|
||||
def handle_game_init_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
return f""
|
||||
|
||||
def handle_attend_request(self, data: Dict) -> Dict:
|
||||
encoded = "&"
|
||||
params = {
|
||||
'atnd_prm1': '0,1,1,0,0,0,1,0,100,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1',
|
||||
'atnd_prm2': '30,10,100,4,1,50,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1',
|
||||
'atnd_prm3': '100,0,1,1,1,1,1,1,1,1,2,3,4,1,1,1,3,4,5,1,1,1,4,5,6,1,1,1,5,6,7,4,4,4,9,10,14,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,10,30,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0',
|
||||
'atnd_lut': f'{self.time_lut}',
|
||||
"atnd_prm1": "0,1,1,0,0,0,1,0,100,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
|
||||
"atnd_prm2": "30,10,100,4,1,50,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1",
|
||||
"atnd_prm3": "100,0,1,1,1,1,1,1,1,1,2,3,4,1,1,1,3,4,5,1,1,1,4,5,6,1,1,1,5,6,7,4,4,4,9,10,14,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,5,10,10,25,20,50,30,90,10,30,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0",
|
||||
"atnd_lut": f"{self.time_lut}",
|
||||
}
|
||||
|
||||
|
||||
encoded += urllib.parse.urlencode(params)
|
||||
encoded = encoded.replace("%2C", ",")
|
||||
|
||||
@ -45,42 +46,42 @@ class DivaBase():
|
||||
def handle_ping_request(self, data: Dict) -> Dict:
|
||||
encoded = "&"
|
||||
params = {
|
||||
'ping_b_msg': f'Welcome to {self.core_cfg.server.name} network!',
|
||||
'ping_m_msg': 'xxx',
|
||||
'atnd_lut': f'{self.time_lut}',
|
||||
'fi_lut': f'{self.time_lut}',
|
||||
'ci_lut': f'{self.time_lut}',
|
||||
'qi_lut': f'{self.time_lut}',
|
||||
'pvl_lut': '2021-05-22 12:08:16.0',
|
||||
'shp_ctlg_lut': '2020-06-10 19:44:16.0',
|
||||
'cstmz_itm_ctlg_lut': '2019-10-08 20:23:12.0',
|
||||
'ngwl_lut': '2019-10-08 20:23:12.0',
|
||||
'rnk_nv_lut': '2020-06-10 19:51:30.0',
|
||||
'rnk_ps_lut': f'{self.time_lut}',
|
||||
'bi_lut': '2020-09-18 10:00:00.0',
|
||||
'cpi_lut': '2020-10-25 09:25:10.0',
|
||||
'bdlol_lut': '2020-09-18 10:00:00.0',
|
||||
'p_std_hc_lut': '2019-08-01 04:00:36.0',
|
||||
'p_std_i_n_lut': '2019-08-01 04:00:36.0',
|
||||
'pdcl_lut': '2019-08-01 04:00:36.0',
|
||||
'pnml_lut': '2019-08-01 04:00:36.0',
|
||||
'cinml_lut': '2019-08-01 04:00:36.0',
|
||||
'rwl_lut': '2019-08-01 04:00:36.0',
|
||||
'req_inv_cmd_num': '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
|
||||
'req_inv_cmd_prm1': '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
|
||||
'req_inv_cmd_prm2': '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
|
||||
'req_inv_cmd_prm3': '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
|
||||
'req_inv_cmd_prm4': '-1,-1,-1,-1,-1,-1,-1,-1,-1,-1',
|
||||
'pow_save_flg': 0,
|
||||
'nblss_dnt_p': 100,
|
||||
'nblss_ltt_rl_vp': 1500,
|
||||
'nblss_ex_ltt_flg': 1,
|
||||
'nblss_dnt_st_tm': "2019-07-15 12:00:00.0",
|
||||
'nblss_dnt_ed_tm': "2019-09-17 12:00:00.0",
|
||||
'nblss_ltt_st_tm': "2019-09-18 12:00:00.0",
|
||||
'nblss_ltt_ed_tm': "2019-09-22 12:00:00.0",
|
||||
"ping_b_msg": f"Welcome to {self.core_cfg.server.name} network!",
|
||||
"ping_m_msg": "xxx",
|
||||
"atnd_lut": f"{self.time_lut}",
|
||||
"fi_lut": f"{self.time_lut}",
|
||||
"ci_lut": f"{self.time_lut}",
|
||||
"qi_lut": f"{self.time_lut}",
|
||||
"pvl_lut": "2021-05-22 12:08:16.0",
|
||||
"shp_ctlg_lut": "2020-06-10 19:44:16.0",
|
||||
"cstmz_itm_ctlg_lut": "2019-10-08 20:23:12.0",
|
||||
"ngwl_lut": "2019-10-08 20:23:12.0",
|
||||
"rnk_nv_lut": "2020-06-10 19:51:30.0",
|
||||
"rnk_ps_lut": f"{self.time_lut}",
|
||||
"bi_lut": "2020-09-18 10:00:00.0",
|
||||
"cpi_lut": "2020-10-25 09:25:10.0",
|
||||
"bdlol_lut": "2020-09-18 10:00:00.0",
|
||||
"p_std_hc_lut": "2019-08-01 04:00:36.0",
|
||||
"p_std_i_n_lut": "2019-08-01 04:00:36.0",
|
||||
"pdcl_lut": "2019-08-01 04:00:36.0",
|
||||
"pnml_lut": "2019-08-01 04:00:36.0",
|
||||
"cinml_lut": "2019-08-01 04:00:36.0",
|
||||
"rwl_lut": "2019-08-01 04:00:36.0",
|
||||
"req_inv_cmd_num": "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"req_inv_cmd_prm1": "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"req_inv_cmd_prm2": "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"req_inv_cmd_prm3": "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"req_inv_cmd_prm4": "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"pow_save_flg": 0,
|
||||
"nblss_dnt_p": 100,
|
||||
"nblss_ltt_rl_vp": 1500,
|
||||
"nblss_ex_ltt_flg": 1,
|
||||
"nblss_dnt_st_tm": "2019-07-15 12:00:00.0",
|
||||
"nblss_dnt_ed_tm": "2019-09-17 12:00:00.0",
|
||||
"nblss_ltt_st_tm": "2019-09-18 12:00:00.0",
|
||||
"nblss_ltt_ed_tm": "2019-09-22 12:00:00.0",
|
||||
}
|
||||
|
||||
|
||||
encoded += urllib.parse.urlencode(params)
|
||||
encoded = encoded.replace("+", "%20")
|
||||
encoded = encoded.replace("%2C", ",")
|
||||
@ -122,7 +123,7 @@ class DivaBase():
|
||||
response += f"&pvl_lut={self.time_lut}"
|
||||
response += f"&pv_lst={pvlist}"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_shop_catalog_request(self, data: Dict) -> Dict:
|
||||
catalog = ""
|
||||
@ -137,7 +138,21 @@ class DivaBase():
|
||||
|
||||
else:
|
||||
for shop in shopList:
|
||||
line = str(shop["shopId"]) + "," + str(shop['unknown_0']) + "," + shop['name'] + "," + str(shop['points']) + "," + shop['start_date'] + "," + shop['end_date'] + "," + str(shop["type"])
|
||||
line = (
|
||||
str(shop["shopId"])
|
||||
+ ","
|
||||
+ str(shop["unknown_0"])
|
||||
+ ","
|
||||
+ shop["name"]
|
||||
+ ","
|
||||
+ str(shop["points"])
|
||||
+ ","
|
||||
+ shop["start_date"]
|
||||
+ ","
|
||||
+ shop["end_date"]
|
||||
+ ","
|
||||
+ str(shop["type"])
|
||||
)
|
||||
line = urllib.parse.quote(line) + ","
|
||||
catalog += f"{urllib.parse.quote(line)}"
|
||||
|
||||
@ -146,7 +161,7 @@ class DivaBase():
|
||||
response = f"&shp_ctlg_lut={self.time_lut}"
|
||||
response += f"&shp_ctlg={catalog[:-3]}"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_buy_module_request(self, data: Dict) -> Dict:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
@ -162,10 +177,7 @@ 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.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
|
||||
self.data.module.put_module(data["pd_id"], self.version, data["mdl_id"])
|
||||
|
||||
# generate the mdl_have string
|
||||
@ -191,7 +203,21 @@ class DivaBase():
|
||||
|
||||
else:
|
||||
for item in itemList:
|
||||
line = str(item["itemId"]) + "," + str(item['unknown_0']) + "," + item['name'] + "," + str(item['points']) + "," + item['start_date'] + "," + item['end_date'] + "," + str(item["type"])
|
||||
line = (
|
||||
str(item["itemId"])
|
||||
+ ","
|
||||
+ str(item["unknown_0"])
|
||||
+ ","
|
||||
+ item["name"]
|
||||
+ ","
|
||||
+ str(item["points"])
|
||||
+ ","
|
||||
+ item["start_date"]
|
||||
+ ","
|
||||
+ item["end_date"]
|
||||
+ ","
|
||||
+ str(item["type"])
|
||||
)
|
||||
line = urllib.parse.quote(line) + ","
|
||||
catalog += f"{urllib.parse.quote(line)}"
|
||||
|
||||
@ -200,11 +226,13 @@ class DivaBase():
|
||||
response = f"&cstmz_itm_ctlg_lut={self.time_lut}"
|
||||
response += f"&cstmz_itm_ctlg={catalog[:-3]}"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_buy_cstmz_itm_request(self, data: Dict) -> Dict:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
item = self.data.static.get_enabled_item(self.version, int(data["cstmz_itm_id"]))
|
||||
item = self.data.static.get_enabled_item(
|
||||
self.version, int(data["cstmz_itm_id"])
|
||||
)
|
||||
|
||||
# make sure module is available to purchase
|
||||
if not item:
|
||||
@ -217,15 +245,16 @@ 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
|
||||
self.data.profile.update_profile(profile["user"], vcld_pts=new_vcld_pts)
|
||||
|
||||
self.data.customize.put_customize_item(
|
||||
data["pd_id"], self.version, data["cstmz_itm_id"]
|
||||
)
|
||||
|
||||
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(data["pd_id"], self.version)
|
||||
cstmz_itm_have = self.data.customize.get_customize_items_have_string(
|
||||
data["pd_id"], self.version
|
||||
)
|
||||
|
||||
response = "&shp_rslt=1"
|
||||
response += f"&cstmz_itm_id={data['cstmz_itm_id']}"
|
||||
@ -237,33 +266,33 @@ class DivaBase():
|
||||
def handle_festa_info_request(self, data: Dict) -> Dict:
|
||||
encoded = "&"
|
||||
params = {
|
||||
'fi_id': '1,-1',
|
||||
'fi_name': f'{self.core_cfg.server.name} Opening,xxx',
|
||||
'fi_kind': '0,0',
|
||||
'fi_difficulty': '-1,-1',
|
||||
'fi_pv_id_lst': 'ALL,ALL',
|
||||
'fi_attr': '7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
|
||||
'fi_add_vp': '20,0',
|
||||
'fi_mul_vp': '1,1',
|
||||
'fi_st': '2022-06-17 17:00:00.0,2014-07-08 18:10:11.0',
|
||||
'fi_et': '2029-01-01 10:00:00.0,2014-07-08 18:10:11.0',
|
||||
'fi_lut': '{self.time_lut}',
|
||||
"fi_id": "1,-1",
|
||||
"fi_name": f"{self.core_cfg.server.name} Opening,xxx",
|
||||
"fi_kind": "0,0",
|
||||
"fi_difficulty": "-1,-1",
|
||||
"fi_pv_id_lst": "ALL,ALL",
|
||||
"fi_attr": "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
|
||||
"fi_add_vp": "20,0",
|
||||
"fi_mul_vp": "1,1",
|
||||
"fi_st": "2022-06-17 17:00:00.0,2014-07-08 18:10:11.0",
|
||||
"fi_et": "2029-01-01 10:00:00.0,2014-07-08 18:10:11.0",
|
||||
"fi_lut": "{self.time_lut}",
|
||||
}
|
||||
|
||||
|
||||
encoded += urllib.parse.urlencode(params)
|
||||
encoded = encoded.replace("+", "%20")
|
||||
encoded = encoded.replace("%2C", ",")
|
||||
|
||||
return encoded
|
||||
|
||||
|
||||
def handle_contest_info_request(self, data: Dict) -> Dict:
|
||||
response = ""
|
||||
|
||||
response += f"&ci_lut={self.time_lut}"
|
||||
response += "&ci_str=%2A%2A%2A,%2A%2A%2A,%2A%2A%2A,%2A%2A%2A,%2A%2A%2A,%2A%2A%2A,%2A%2A%2A,%2A%2A%2A"
|
||||
|
||||
return ( response )
|
||||
|
||||
|
||||
return response
|
||||
|
||||
def handle_qst_inf_request(self, data: Dict) -> Dict:
|
||||
quest = ""
|
||||
|
||||
@ -279,11 +308,31 @@ class DivaBase():
|
||||
response += f"&qhi_str={quest[:-1]}"
|
||||
else:
|
||||
for quests in questList:
|
||||
line = str(quests["questId"]) + "," + str(quests['quest_order']) + "," + str(quests['kind']) + "," + str(quests['unknown_0']) + "," + quests['start_datetime'] + "," + quests['end_datetime'] + "," + quests["name"] + "," + str(quests["unknown_1"]) + "," + str(quests["unknown_2"]) + "," + str(quests["quest_enable"])
|
||||
line = (
|
||||
str(quests["questId"])
|
||||
+ ","
|
||||
+ str(quests["quest_order"])
|
||||
+ ","
|
||||
+ str(quests["kind"])
|
||||
+ ","
|
||||
+ str(quests["unknown_0"])
|
||||
+ ","
|
||||
+ quests["start_datetime"]
|
||||
+ ","
|
||||
+ quests["end_datetime"]
|
||||
+ ","
|
||||
+ quests["name"]
|
||||
+ ","
|
||||
+ str(quests["unknown_1"])
|
||||
+ ","
|
||||
+ str(quests["unknown_2"])
|
||||
+ ","
|
||||
+ str(quests["quest_enable"])
|
||||
)
|
||||
quest += f"{urllib.parse.quote(line)}%0A,"
|
||||
|
||||
responseline = f"{quest[:-1]},"
|
||||
for i in range(len(questList),59):
|
||||
for i in range(len(questList), 59):
|
||||
responseline += "%2A%2A%2A%0A,"
|
||||
|
||||
response = ""
|
||||
@ -292,44 +341,44 @@ class DivaBase():
|
||||
|
||||
response += "&qrai_str=%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1,%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1,%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1%2C%2D1"
|
||||
|
||||
return ( response )
|
||||
|
||||
return response
|
||||
|
||||
def handle_nv_ranking_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_ps_ranking_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_ng_word_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_rmt_wp_list_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_pv_def_chr_list_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_pv_ng_mdl_list_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_cstmz_itm_ng_mdl_lst_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_banner_info_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_banner_data_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_cm_ply_info_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_pstd_h_ctrl_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_pstd_item_ng_lst_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_pre_start_request(self, data: Dict) -> str:
|
||||
profile = self.data.profile.get_profile(data["aime_id"], self.version)
|
||||
profile_shop = self.data.item.get_shop(data["aime_id"], self.version)
|
||||
@ -372,8 +421,10 @@ class DivaBase():
|
||||
return response
|
||||
|
||||
def handle_registration_request(self, data: Dict) -> Dict:
|
||||
self.data.profile.create_profile(self.version, data["aime_id"], data["player_name"])
|
||||
return (f"&cd_adm_result=1&pd_id={data['aime_id']}")
|
||||
self.data.profile.create_profile(
|
||||
self.version, data["aime_id"], data["player_name"]
|
||||
)
|
||||
return f"&cd_adm_result=1&pd_id={data['aime_id']}"
|
||||
|
||||
def handle_start_request(self, data: Dict) -> Dict:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
@ -384,12 +435,16 @@ class DivaBase():
|
||||
mdl_have = "F" * 250
|
||||
# generate the mdl_have string if "unlock_all_modules" is disabled
|
||||
if not self.game_config.mods.unlock_all_modules:
|
||||
mdl_have = self.data.module.get_modules_have_string(data["pd_id"], self.version)
|
||||
mdl_have = self.data.module.get_modules_have_string(
|
||||
data["pd_id"], self.version
|
||||
)
|
||||
|
||||
cstmz_itm_have = "F" * 250
|
||||
# generate the cstmz_itm_have string if "unlock_all_items" is disabled
|
||||
if not self.game_config.mods.unlock_all_items:
|
||||
cstmz_itm_have = self.data.customize.get_customize_items_have_string(data["pd_id"], self.version)
|
||||
cstmz_itm_have = self.data.customize.get_customize_items_have_string(
|
||||
data["pd_id"], self.version
|
||||
)
|
||||
|
||||
response = f"&pd_id={data['pd_id']}"
|
||||
response += "&start_result=1"
|
||||
@ -452,15 +507,16 @@ class DivaBase():
|
||||
response += f"&mdl_eqp_ary={mdl_eqp_ary}"
|
||||
response += f"&c_itm_eqp_ary={c_itm_eqp_ary}"
|
||||
response += f"&ms_itm_flg_ary={ms_itm_flg_ary}"
|
||||
|
||||
return ( response )
|
||||
|
||||
return response
|
||||
|
||||
def handle_pd_unlock_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
|
||||
return f""
|
||||
|
||||
def handle_spend_credit_request(self, data: Dict) -> Dict:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
if profile is None: return
|
||||
if profile is None:
|
||||
return
|
||||
|
||||
response = ""
|
||||
|
||||
@ -471,10 +527,16 @@ class DivaBase():
|
||||
response += f"&lv_efct_id={profile['lv_efct_id']}"
|
||||
response += f"&lv_plt_id={profile['lv_plt_id']}"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def _get_pv_pd_result(self, song: int, pd_db_song: Dict, pd_db_ranking: Dict,
|
||||
pd_db_customize: Dict, edition: int) -> str:
|
||||
def _get_pv_pd_result(
|
||||
self,
|
||||
song: int,
|
||||
pd_db_song: Dict,
|
||||
pd_db_ranking: Dict,
|
||||
pd_db_customize: Dict,
|
||||
edition: int,
|
||||
) -> str:
|
||||
"""
|
||||
Helper function to generate the pv_result string for every song, ranking and edition
|
||||
"""
|
||||
@ -483,7 +545,7 @@ class DivaBase():
|
||||
# make sure there are enough max scores to calculate a ranking
|
||||
if pd_db_ranking["ranking"] != 0:
|
||||
global_ranking = pd_db_ranking["ranking"]
|
||||
|
||||
|
||||
# pv_no
|
||||
pv_result = f"{song},"
|
||||
# edition
|
||||
@ -513,7 +575,7 @@ class DivaBase():
|
||||
f"{pd_db_customize['chsld_se']},"
|
||||
f"{pd_db_customize['sldtch_se']}"
|
||||
)
|
||||
|
||||
|
||||
pv_result += f"{module_eqp},"
|
||||
pv_result += f"{customize_eqp},"
|
||||
pv_result += f"{customize_flag},"
|
||||
@ -537,21 +599,35 @@ class DivaBase():
|
||||
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(data["pd_id"], int(song), data["difficulty"], edition=0)
|
||||
pd_db_song_1 = self.data.score.get_best_user_score(data["pd_id"], int(song), data["difficulty"], edition=1)
|
||||
|
||||
pd_db_song_0 = self.data.score.get_best_user_score(
|
||||
data["pd_id"], int(song), data["difficulty"], edition=0
|
||||
)
|
||||
pd_db_song_1 = self.data.score.get_best_user_score(
|
||||
data["pd_id"], int(song), data["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(data["pd_id"], int(song), data["difficulty"], edition=0)
|
||||
pd_db_ranking_0 = self.data.score.get_global_ranking(
|
||||
data["pd_id"], int(song), data["difficulty"], edition=0
|
||||
)
|
||||
|
||||
if pd_db_song_1:
|
||||
pd_db_ranking_1 = self.data.score.get_global_ranking(data["pd_id"], int(song), data["difficulty"], edition=1)
|
||||
pd_db_ranking_1 = self.data.score.get_global_ranking(
|
||||
data["pd_id"], int(song), data["difficulty"], edition=1
|
||||
)
|
||||
|
||||
pd_db_customize = self.data.pv_customize.get_pv_customize(
|
||||
data["pd_id"], int(song)
|
||||
)
|
||||
|
||||
pd_db_customize = self.data.pv_customize.get_pv_customize(data["pd_id"], int(song))
|
||||
|
||||
# generate the pv_result string with the ORIGINAL edition and the EXTRA edition appended
|
||||
pv_result = self._get_pv_pd_result(int(song), pd_db_song_0, pd_db_ranking_0, pd_db_customize, edition=0)
|
||||
pv_result += "," + self._get_pv_pd_result(int(song), pd_db_song_1, pd_db_ranking_1, pd_db_customize, edition=1)
|
||||
pv_result = self._get_pv_pd_result(
|
||||
int(song), pd_db_song_0, pd_db_ranking_0, pd_db_customize, edition=0
|
||||
)
|
||||
pv_result += "," + self._get_pv_pd_result(
|
||||
int(song), pd_db_song_1, pd_db_ranking_1, pd_db_customize, edition=1
|
||||
)
|
||||
|
||||
self.logger.debug(f"pv_result = {pv_result}")
|
||||
|
||||
@ -565,13 +641,12 @@ class DivaBase():
|
||||
response += "&pdddt_flg=0"
|
||||
response += f"&pdddt_tm={self.time_lut}"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_stage_start_request(self, data: Dict) -> Dict:
|
||||
return ( f'' )
|
||||
return f""
|
||||
|
||||
def handle_stage_result_request(self, data: Dict) -> Dict:
|
||||
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
|
||||
pd_song_list = data["stg_ply_pv_id"].split(",")
|
||||
@ -590,15 +665,100 @@ class DivaBase():
|
||||
|
||||
for index, value in enumerate(pd_song_list):
|
||||
if "-1" not in pd_song_list[index]:
|
||||
profile_pd_db_song = self.data.score.get_best_user_score(data["pd_id"], pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index])
|
||||
profile_pd_db_song = self.data.score.get_best_user_score(
|
||||
data["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(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
|
||||
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
|
||||
self.data.score.put_best_score(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
pd_song_list[index],
|
||||
pd_song_difficulty[index],
|
||||
pd_song_edition[index],
|
||||
pd_song_max_score[index],
|
||||
pd_song_max_atn_pnt[index],
|
||||
pd_song_ranking[index],
|
||||
pd_song_sort_kind,
|
||||
pd_song_cool_cnt[index],
|
||||
pd_song_fine_cnt[index],
|
||||
pd_song_safe_cnt[index],
|
||||
pd_song_sad_cnt[index],
|
||||
pd_song_worst_cnt[index],
|
||||
pd_song_max_combo[index],
|
||||
)
|
||||
self.data.score.put_playlog(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
pd_song_list[index],
|
||||
pd_song_difficulty[index],
|
||||
pd_song_edition[index],
|
||||
pd_song_max_score[index],
|
||||
pd_song_max_atn_pnt[index],
|
||||
pd_song_ranking[index],
|
||||
pd_song_sort_kind,
|
||||
pd_song_cool_cnt[index],
|
||||
pd_song_fine_cnt[index],
|
||||
pd_song_safe_cnt[index],
|
||||
pd_song_sad_cnt[index],
|
||||
pd_song_worst_cnt[index],
|
||||
pd_song_max_combo[index],
|
||||
)
|
||||
elif int(pd_song_max_score[index]) >= int(profile_pd_db_song["score"]):
|
||||
self.data.score.put_best_score(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
|
||||
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
|
||||
self.data.score.put_best_score(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
pd_song_list[index],
|
||||
pd_song_difficulty[index],
|
||||
pd_song_edition[index],
|
||||
pd_song_max_score[index],
|
||||
pd_song_max_atn_pnt[index],
|
||||
pd_song_ranking[index],
|
||||
pd_song_sort_kind,
|
||||
pd_song_cool_cnt[index],
|
||||
pd_song_fine_cnt[index],
|
||||
pd_song_safe_cnt[index],
|
||||
pd_song_sad_cnt[index],
|
||||
pd_song_worst_cnt[index],
|
||||
pd_song_max_combo[index],
|
||||
)
|
||||
self.data.score.put_playlog(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
pd_song_list[index],
|
||||
pd_song_difficulty[index],
|
||||
pd_song_edition[index],
|
||||
pd_song_max_score[index],
|
||||
pd_song_max_atn_pnt[index],
|
||||
pd_song_ranking[index],
|
||||
pd_song_sort_kind,
|
||||
pd_song_cool_cnt[index],
|
||||
pd_song_fine_cnt[index],
|
||||
pd_song_safe_cnt[index],
|
||||
pd_song_sad_cnt[index],
|
||||
pd_song_worst_cnt[index],
|
||||
pd_song_max_combo[index],
|
||||
)
|
||||
elif int(pd_song_max_score[index]) != int(profile_pd_db_song["score"]):
|
||||
self.data.score.put_playlog(data["pd_id"], self.version, pd_song_list[index], pd_song_difficulty[index], pd_song_edition[index], pd_song_max_score[index], pd_song_max_atn_pnt[index], pd_song_ranking[index], pd_song_sort_kind, pd_song_cool_cnt[index], pd_song_fine_cnt[index], pd_song_safe_cnt[index], pd_song_sad_cnt[index], pd_song_worst_cnt[index], pd_song_max_combo[index])
|
||||
self.data.score.put_playlog(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
pd_song_list[index],
|
||||
pd_song_difficulty[index],
|
||||
pd_song_edition[index],
|
||||
pd_song_max_score[index],
|
||||
pd_song_max_atn_pnt[index],
|
||||
pd_song_ranking[index],
|
||||
pd_song_sort_kind,
|
||||
pd_song_cool_cnt[index],
|
||||
pd_song_fine_cnt[index],
|
||||
pd_song_safe_cnt[index],
|
||||
pd_song_sad_cnt[index],
|
||||
pd_song_worst_cnt[index],
|
||||
pd_song_max_combo[index],
|
||||
)
|
||||
|
||||
# Profile saving based on registration list
|
||||
|
||||
@ -608,7 +768,7 @@ class DivaBase():
|
||||
total_atn_pnt = 0
|
||||
for best_score in best_scores:
|
||||
total_atn_pnt += best_score["atn_pnt"]
|
||||
|
||||
|
||||
new_level = (total_atn_pnt // 13979) + 1
|
||||
new_level_pnt = round((total_atn_pnt % 13979) / 13979 * 100)
|
||||
|
||||
@ -630,7 +790,7 @@ class DivaBase():
|
||||
nxt_dffclty=int(data["nxt_dffclty"]),
|
||||
nxt_edtn=int(data["nxt_edtn"]),
|
||||
my_qst_id=data["my_qst_id"],
|
||||
my_qst_sts=data["my_qst_sts"]
|
||||
my_qst_sts=data["my_qst_sts"],
|
||||
)
|
||||
|
||||
response += f"&lv_num={new_level}"
|
||||
@ -663,35 +823,51 @@ class DivaBase():
|
||||
response += "&my_ccd_r_hnd=-1,-1,-1,-1,-1"
|
||||
response += "&my_ccd_r_vp=-1,-1,-1,-1,-1"
|
||||
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_end_request(self, data: Dict) -> Dict:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
|
||||
self.data.profile.update_profile(
|
||||
profile["user"],
|
||||
my_qst_id=data["my_qst_id"],
|
||||
my_qst_sts=data["my_qst_sts"]
|
||||
profile["user"], my_qst_id=data["my_qst_id"], my_qst_sts=data["my_qst_sts"]
|
||||
)
|
||||
return (f'')
|
||||
return f""
|
||||
|
||||
def handle_shop_exit_request(self, data: Dict) -> Dict:
|
||||
self.data.item.put_shop(data["pd_id"], self.version, data["mdl_eqp_cmn_ary"], data["c_itm_eqp_cmn_ary"], data["ms_itm_flg_cmn_ary"])
|
||||
self.data.item.put_shop(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
data["mdl_eqp_cmn_ary"],
|
||||
data["c_itm_eqp_cmn_ary"],
|
||||
data["ms_itm_flg_cmn_ary"],
|
||||
)
|
||||
if int(data["use_pv_mdl_eqp"]) == 1:
|
||||
self.data.pv_customize.put_pv_customize(data["pd_id"], self.version, data["ply_pv_id"],
|
||||
data["mdl_eqp_pv_ary"], data["c_itm_eqp_pv_ary"], data["ms_itm_flg_pv_ary"])
|
||||
self.data.pv_customize.put_pv_customize(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
data["ply_pv_id"],
|
||||
data["mdl_eqp_pv_ary"],
|
||||
data["c_itm_eqp_pv_ary"],
|
||||
data["ms_itm_flg_pv_ary"],
|
||||
)
|
||||
else:
|
||||
self.data.pv_customize.put_pv_customize(data["pd_id"], self.version, data["ply_pv_id"],
|
||||
"-1,-1,-1", "-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1", "1,1,1,1,1,1,1,1,1,1,1,1")
|
||||
self.data.pv_customize.put_pv_customize(
|
||||
data["pd_id"],
|
||||
self.version,
|
||||
data["ply_pv_id"],
|
||||
"-1,-1,-1",
|
||||
"-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
"1,1,1,1,1,1,1,1,1,1,1,1",
|
||||
)
|
||||
|
||||
response = "&shp_rslt=1"
|
||||
return ( response )
|
||||
return response
|
||||
|
||||
def handle_card_procedure_request(self, data: Dict) -> str:
|
||||
profile = self.data.profile.get_profile(data["aime_id"], self.version)
|
||||
if profile is None:
|
||||
return "&cd_adm_result=0"
|
||||
|
||||
|
||||
response = "&cd_adm_result=1"
|
||||
response += "&chg_name_price=100"
|
||||
response += "&accept_idx=100"
|
||||
@ -706,20 +882,18 @@ class DivaBase():
|
||||
response += f"&passwd_stat={profile['passwd_stat']}"
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def handle_change_name_request(self, data: Dict) -> str:
|
||||
profile = 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"]):
|
||||
return "&cd_adm_result=0"
|
||||
|
||||
|
||||
# update the vocaloid points and player name
|
||||
new_vcld_pts = profile["vcld_pts"] - int(data["chg_name_price"])
|
||||
self.data.profile.update_profile(
|
||||
profile["user"],
|
||||
player_name=data["player_name"],
|
||||
vcld_pts=new_vcld_pts
|
||||
profile["user"], player_name=data["player_name"], vcld_pts=new_vcld_pts
|
||||
)
|
||||
|
||||
response = "&cd_adm_result=1"
|
||||
@ -728,19 +902,17 @@ class DivaBase():
|
||||
response += f"&player_name={data['player_name']}"
|
||||
|
||||
return response
|
||||
|
||||
|
||||
def handle_change_passwd_request(self, data: Dict) -> str:
|
||||
profile = self.data.profile.get_profile(data["pd_id"], self.version)
|
||||
|
||||
# TODO: return correct error number instead of 0
|
||||
if (data["passwd"] != profile["passwd"]):
|
||||
if data["passwd"] != profile["passwd"]:
|
||||
return "&cd_adm_result=0"
|
||||
|
||||
# set password to true and update the saved password
|
||||
self.data.profile.update_profile(
|
||||
profile["user"],
|
||||
passwd_stat=1,
|
||||
passwd=data["new_passwd"]
|
||||
profile["user"], passwd_stat=1, passwd=data["new_passwd"]
|
||||
)
|
||||
|
||||
response = "&cd_adm_result=1"
|
||||
|
||||
@ -1,30 +1,40 @@
|
||||
from core.config import CoreConfig
|
||||
|
||||
|
||||
class DivaServerConfig():
|
||||
class DivaServerConfig:
|
||||
def __init__(self, parent_config: "DivaConfig") -> None:
|
||||
self.__config = parent_config
|
||||
|
||||
@property
|
||||
def enable(self) -> bool:
|
||||
return CoreConfig.get_config_field(self.__config, 'diva', 'server', 'enable', default=True)
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "diva", "server", "enable", default=True
|
||||
)
|
||||
|
||||
@property
|
||||
def loglevel(self) -> int:
|
||||
return CoreConfig.str_to_loglevel(CoreConfig.get_config_field(self.__config, 'diva', 'server', 'loglevel', default="info"))
|
||||
return CoreConfig.str_to_loglevel(
|
||||
CoreConfig.get_config_field(
|
||||
self.__config, "diva", "server", "loglevel", default="info"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class DivaModsConfig():
|
||||
class DivaModsConfig:
|
||||
def __init__(self, parent_config: "DivaConfig") -> None:
|
||||
self.__config = parent_config
|
||||
|
||||
@property
|
||||
def unlock_all_modules(self) -> bool:
|
||||
return CoreConfig.get_config_field(self.__config, 'diva', 'mods', 'unlock_all_modules', default=True)
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "diva", "mods", "unlock_all_modules", default=True
|
||||
)
|
||||
|
||||
@property
|
||||
def unlock_all_items(self) -> bool:
|
||||
return CoreConfig.get_config_field(self.__config, 'diva', 'mods', 'unlock_all_items', default=True)
|
||||
return CoreConfig.get_config_field(
|
||||
self.__config, "diva", "mods", "unlock_all_items", default=True
|
||||
)
|
||||
|
||||
|
||||
class DivaConfig(dict):
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
class DivaConstants():
|
||||
class DivaConstants:
|
||||
GAME_CODE = "SBZV"
|
||||
|
||||
CONFIG_NAME = "diva.yaml"
|
||||
@ -10,4 +10,4 @@ class DivaConstants():
|
||||
|
||||
@classmethod
|
||||
def game_ver_to_string(cls, ver: int):
|
||||
return cls.VERSION_NAMES[ver]
|
||||
return cls.VERSION_NAMES[ver]
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
from core.data import Data
|
||||
from core.config import CoreConfig
|
||||
from titles.diva.schema import DivaProfileData, DivaScoreData, DivaModuleData, DivaCustomizeItemData, DivaPvCustomizeData, DivaItemData, DivaStaticData
|
||||
from titles.diva.schema import (
|
||||
DivaProfileData,
|
||||
DivaScoreData,
|
||||
DivaModuleData,
|
||||
DivaCustomizeItemData,
|
||||
DivaPvCustomizeData,
|
||||
DivaItemData,
|
||||
DivaStaticData,
|
||||
)
|
||||
|
||||
|
||||
class DivaData(Data):
|
||||
|
||||
@ -14,85 +14,112 @@ from titles.diva.config import DivaConfig
|
||||
from titles.diva.const import DivaConstants
|
||||
from titles.diva.base import DivaBase
|
||||
|
||||
class DivaServlet():
|
||||
|
||||
class DivaServlet:
|
||||
def __init__(self, core_cfg: CoreConfig, cfg_dir: str) -> None:
|
||||
self.core_cfg = core_cfg
|
||||
self.game_cfg = DivaConfig()
|
||||
if path.exists(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"):
|
||||
self.game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}")))
|
||||
self.game_cfg.update(
|
||||
yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"))
|
||||
)
|
||||
|
||||
self.base = DivaBase(core_cfg, self.game_cfg)
|
||||
|
||||
self.logger = logging.getLogger("diva")
|
||||
log_fmt_str = "[%(asctime)s] Diva | %(levelname)s | %(message)s"
|
||||
log_fmt = logging.Formatter(log_fmt_str)
|
||||
fileHandler = TimedRotatingFileHandler("{0}/{1}.log".format(self.core_cfg.server.log_dir, "diva"), encoding='utf8',
|
||||
when="d", backupCount=10)
|
||||
fileHandler = TimedRotatingFileHandler(
|
||||
"{0}/{1}.log".format(self.core_cfg.server.log_dir, "diva"),
|
||||
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)
|
||||
|
||||
coloredlogs.install(
|
||||
level=self.game_cfg.server.loglevel, logger=self.logger, fmt=log_fmt_str
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_allnet_info(cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str) -> Tuple[bool, str, str]:
|
||||
def get_allnet_info(
|
||||
cls, game_code: str, core_cfg: CoreConfig, cfg_dir: str
|
||||
) -> Tuple[bool, str, str]:
|
||||
game_cfg = DivaConfig()
|
||||
if path.exists(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"):
|
||||
game_cfg.update(yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}")))
|
||||
game_cfg.update(
|
||||
yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"))
|
||||
)
|
||||
|
||||
if not game_cfg.server.enable:
|
||||
return (False, "", "")
|
||||
|
||||
|
||||
if core_cfg.server.is_develop:
|
||||
return (True, f"http://{core_cfg.title.hostname}:{core_cfg.title.port}/{game_code}/$v/", "")
|
||||
|
||||
return (
|
||||
True,
|
||||
f"http://{core_cfg.title.hostname}:{core_cfg.title.port}/{game_code}/$v/",
|
||||
"",
|
||||
)
|
||||
|
||||
return (True, f"http://{core_cfg.title.hostname}/{game_code}/$v/", "")
|
||||
|
||||
def render_POST(self, req: Request, version: int, url_path: str) -> bytes:
|
||||
req_raw = req.content.getvalue()
|
||||
url_header = req.getAllHeaders()
|
||||
|
||||
#Ping Dispatch
|
||||
if "THIS_STRING_SEPARATES"in str(url_header):
|
||||
# Ping Dispatch
|
||||
if "THIS_STRING_SEPARATES" in str(url_header):
|
||||
binary_request = req_raw.splitlines()
|
||||
binary_cmd_decoded = binary_request[3].decode("utf-8")
|
||||
binary_array = binary_cmd_decoded.split('&')
|
||||
binary_array = binary_cmd_decoded.split("&")
|
||||
|
||||
bin_req_data = {}
|
||||
|
||||
for kvp in binary_array:
|
||||
split_bin = kvp.split("=")
|
||||
bin_req_data[split_bin[0]] = split_bin[1]
|
||||
|
||||
|
||||
self.logger.info(f"Binary {bin_req_data['cmd']} Request")
|
||||
self.logger.debug(bin_req_data)
|
||||
|
||||
handler = getattr(self.base, f"handle_{bin_req_data['cmd']}_request")
|
||||
resp = handler(bin_req_data)
|
||||
|
||||
self.logger.debug(f"Response cmd={bin_req_data['cmd']}&req_id={bin_req_data['req_id']}&stat=ok{resp}")
|
||||
return f"cmd={bin_req_data['cmd']}&req_id={bin_req_data['req_id']}&stat=ok{resp}".encode('utf-8')
|
||||
self.logger.debug(
|
||||
f"Response cmd={bin_req_data['cmd']}&req_id={bin_req_data['req_id']}&stat=ok{resp}"
|
||||
)
|
||||
return f"cmd={bin_req_data['cmd']}&req_id={bin_req_data['req_id']}&stat=ok{resp}".encode(
|
||||
"utf-8"
|
||||
)
|
||||
|
||||
# Main Dispatch
|
||||
json_string = json.dumps(
|
||||
req_raw.decode("utf-8")
|
||||
) # Take the response and decode as UTF-8 and dump
|
||||
b64string = json_string.replace(
|
||||
r"\n", "\n"
|
||||
) # Remove all \n and separate them as new lines
|
||||
gz_string = base64.b64decode(b64string) # Decompressing the base64 string
|
||||
|
||||
#Main Dispatch
|
||||
json_string = json.dumps(req_raw.decode("utf-8")) #Take the response and decode as UTF-8 and dump
|
||||
b64string = json_string.replace(r'\n', '\n') # Remove all \n and separate them as new lines
|
||||
gz_string = base64.b64decode(b64string) # Decompressing the base64 string
|
||||
|
||||
try:
|
||||
url_data = zlib.decompress( gz_string ).decode("utf-8") # Decompressing the gzip
|
||||
url_data = zlib.decompress(gz_string).decode(
|
||||
"utf-8"
|
||||
) # Decompressing the gzip
|
||||
except zlib.error as e:
|
||||
self.logger.error(f"Failed to defalte! {e} -> {gz_string}")
|
||||
return "stat=0"
|
||||
|
||||
req_kvp = urllib.parse.unquote(url_data)
|
||||
req_data = {}
|
||||
|
||||
|
||||
# We then need to split each parts with & so we can reuse them to fill out the requests
|
||||
splitted_request = str.split(req_kvp, "&")
|
||||
for kvp in splitted_request:
|
||||
@ -109,15 +136,25 @@ class DivaServlet():
|
||||
handler = getattr(self.base, func_to_find)
|
||||
resp = handler(req_data)
|
||||
|
||||
except AttributeError as e:
|
||||
except AttributeError as e:
|
||||
self.logger.warning(f"Unhandled {req_data['cmd']} request {e}")
|
||||
return f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok".encode('utf-8')
|
||||
return f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok".encode(
|
||||
"utf-8"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error handling method {func_to_find} {e}")
|
||||
return f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok".encode('utf-8')
|
||||
return f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok".encode(
|
||||
"utf-8"
|
||||
)
|
||||
|
||||
req.responseHeaders.addRawHeader(b"content-type", b"text/plain")
|
||||
self.logger.debug(f"Response cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok{resp}")
|
||||
self.logger.debug(
|
||||
f"Response cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok{resp}"
|
||||
)
|
||||
|
||||
return f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok{resp}".encode('utf-8')
|
||||
return (
|
||||
f"cmd={req_data['cmd']}&req_id={req_data['req_id']}&stat=ok{resp}".encode(
|
||||
"utf-8"
|
||||
)
|
||||
)
|
||||
|
||||
@ -7,13 +7,23 @@ from core.config import CoreConfig
|
||||
from titles.diva.database import DivaData
|
||||
from titles.diva.const import DivaConstants
|
||||
|
||||
|
||||
class DivaReader(BaseReader):
|
||||
def __init__(self, config: CoreConfig, version: int, bin_dir: Optional[str], opt_dir: Optional[str], extra: Optional[str]) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
config: CoreConfig,
|
||||
version: int,
|
||||
bin_dir: Optional[str],
|
||||
opt_dir: Optional[str],
|
||||
extra: Optional[str],
|
||||
) -> None:
|
||||
super().__init__(config, version, bin_dir, opt_dir, extra)
|
||||
self.data = DivaData(config)
|
||||
|
||||
try:
|
||||
self.logger.info(f"Start importer for {DivaConstants.game_ver_to_string(version)}")
|
||||
self.logger.info(
|
||||
f"Start importer for {DivaConstants.game_ver_to_string(version)}"
|
||||
)
|
||||
except IndexError:
|
||||
self.logger.error(f"Invalid project diva version {version}")
|
||||
exit(1)
|
||||
@ -30,7 +40,7 @@ class DivaReader(BaseReader):
|
||||
if not path.exists(f"{self.bin_dir}/rom"):
|
||||
self.logger.warn(f"Couldn't find rom folder in {self.bin_dir}, skipping")
|
||||
pull_bin_rom = False
|
||||
|
||||
|
||||
if self.opt_dir is not None:
|
||||
opt_dirs = self.get_data_directories(self.opt_dir)
|
||||
else:
|
||||
@ -44,18 +54,25 @@ class DivaReader(BaseReader):
|
||||
if pull_opt_rom:
|
||||
for dir in opt_dirs:
|
||||
self.read_rom(f"{dir}/rom")
|
||||
|
||||
|
||||
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"):
|
||||
for root, dirs, files in walk(f"{ram_root_dir}/databank"):
|
||||
for file in files:
|
||||
if file.startswith("ShopCatalog_") or file.startswith("CustomizeItemCatalog_") or \
|
||||
(file.startswith("QuestInfo") and not file.startswith("QuestInfoTm")):
|
||||
|
||||
if (
|
||||
file.startswith("ShopCatalog_")
|
||||
or file.startswith("CustomizeItemCatalog_")
|
||||
or (
|
||||
file.startswith("QuestInfo")
|
||||
and not file.startswith("QuestInfoTm")
|
||||
)
|
||||
):
|
||||
with open(f"{root}/{file}", "r") as f:
|
||||
file_data: str = urllib.parse.unquote(urllib.parse.unquote(f.read()))
|
||||
file_data: str = urllib.parse.unquote(
|
||||
urllib.parse.unquote(f.read())
|
||||
)
|
||||
if file_data == "***":
|
||||
self.logger.info(f"{file} is empty, skipping")
|
||||
continue
|
||||
@ -70,23 +87,54 @@ class DivaReader(BaseReader):
|
||||
|
||||
if file.startswith("ShopCatalog_"):
|
||||
for x in range(0, len(split), 7):
|
||||
self.logger.info(f"Added shop item {split[x+0]}")
|
||||
self.logger.info(
|
||||
f"Added shop item {split[x+0]}"
|
||||
)
|
||||
|
||||
self.data.static.put_shop(self.version, split[x+0], split[x+2], split[x+6], split[x+3],
|
||||
split[x+1], split[x+4], split[x+5])
|
||||
self.data.static.put_shop(
|
||||
self.version,
|
||||
split[x + 0],
|
||||
split[x + 2],
|
||||
split[x + 6],
|
||||
split[x + 3],
|
||||
split[x + 1],
|
||||
split[x + 4],
|
||||
split[x + 5],
|
||||
)
|
||||
|
||||
elif file.startswith("CustomizeItemCatalog_") and len(split) >= 7:
|
||||
elif (
|
||||
file.startswith("CustomizeItemCatalog_")
|
||||
and len(split) >= 7
|
||||
):
|
||||
for x in range(0, len(split), 7):
|
||||
self.logger.info(f"Added item {split[x+0]}")
|
||||
|
||||
self.data.static.put_items(self.version, split[x+0], split[x+2], split[x+6], split[x+3],
|
||||
split[x+1], split[x+4], split[x+5])
|
||||
self.data.static.put_items(
|
||||
self.version,
|
||||
split[x + 0],
|
||||
split[x + 2],
|
||||
split[x + 6],
|
||||
split[x + 3],
|
||||
split[x + 1],
|
||||
split[x + 4],
|
||||
split[x + 5],
|
||||
)
|
||||
|
||||
elif file.startswith("QuestInfo") and len(split) >= 9:
|
||||
self.logger.info(f"Added quest {split[0]}")
|
||||
|
||||
self.data.static.put_quests(self.version, split[0], split[6], split[2], split[3],
|
||||
split[7], split[8], split[1], split[4], split[5])
|
||||
|
||||
self.data.static.put_quests(
|
||||
self.version,
|
||||
split[0],
|
||||
split[6],
|
||||
split[2],
|
||||
split[3],
|
||||
split[7],
|
||||
split[8],
|
||||
split[1],
|
||||
split[4],
|
||||
split[5],
|
||||
)
|
||||
|
||||
else:
|
||||
continue
|
||||
@ -102,13 +150,13 @@ class DivaReader(BaseReader):
|
||||
elif path.exists(f"{rom_root_dir}/pv_db.txt"):
|
||||
file_path = f"{rom_root_dir}/pv_db.txt"
|
||||
else:
|
||||
self.logger.warn(f"Cannot find pv_db.txt or mdata_pv_db.txt in {rom_root_dir}, skipping")
|
||||
self.logger.warn(
|
||||
f"Cannot find pv_db.txt or mdata_pv_db.txt in {rom_root_dir}, skipping"
|
||||
)
|
||||
return
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
|
||||
for line in f.readlines():
|
||||
|
||||
if line.startswith("#") or not line:
|
||||
continue
|
||||
|
||||
@ -127,14 +175,13 @@ class DivaReader(BaseReader):
|
||||
|
||||
for x in range(1, len(key_split)):
|
||||
key_args.append(key_split[x])
|
||||
|
||||
|
||||
try:
|
||||
pv_list[pv_id] = self.add_branch(pv_list[pv_id], key_args, val)
|
||||
except KeyError:
|
||||
pv_list[pv_id] = {}
|
||||
pv_list[pv_id] = self.add_branch(pv_list[pv_id], key_args, val)
|
||||
|
||||
|
||||
for pv_id, pv_data in pv_list.items():
|
||||
song_id = int(pv_id.split("_")[1])
|
||||
if "songinfo" not in pv_data:
|
||||
@ -148,46 +195,99 @@ class DivaReader(BaseReader):
|
||||
if "music" not in pv_data["songinfo"]:
|
||||
pv_data["songinfo"]["music"] = "-"
|
||||
|
||||
if "easy" in pv_data['difficulty'] and '0' in pv_data['difficulty']['easy']:
|
||||
diff = pv_data['difficulty']['easy']['0']['level'].split('_')
|
||||
if "easy" in pv_data["difficulty"] and "0" in pv_data["difficulty"]["easy"]:
|
||||
diff = pv_data["difficulty"]["easy"]["0"]["level"].split("_")
|
||||
self.logger.info(f"Added song {song_id} chart 0")
|
||||
|
||||
self.data.static.put_music(self.version, song_id, 0, pv_data["song_name"], pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"], pv_data["songinfo"]["lyrics"], pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"), pv_data["bpm"], pv_data["date"])
|
||||
|
||||
if "normal" in pv_data['difficulty'] and '0' in pv_data['difficulty']['normal']:
|
||||
diff = pv_data['difficulty']['normal']['0']['level'].split('_')
|
||||
self.data.static.put_music(
|
||||
self.version,
|
||||
song_id,
|
||||
0,
|
||||
pv_data["song_name"],
|
||||
pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"],
|
||||
pv_data["songinfo"]["lyrics"],
|
||||
pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"),
|
||||
pv_data["bpm"],
|
||||
pv_data["date"],
|
||||
)
|
||||
|
||||
if (
|
||||
"normal" in pv_data["difficulty"]
|
||||
and "0" in pv_data["difficulty"]["normal"]
|
||||
):
|
||||
diff = pv_data["difficulty"]["normal"]["0"]["level"].split("_")
|
||||
self.logger.info(f"Added song {song_id} chart 1")
|
||||
|
||||
self.data.static.put_music(self.version, song_id, 1, pv_data["song_name"], pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"], pv_data["songinfo"]["lyrics"], pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"), pv_data["bpm"], pv_data["date"])
|
||||
|
||||
if "hard" in pv_data['difficulty'] and '0' in pv_data['difficulty']['hard']:
|
||||
diff = pv_data['difficulty']['hard']['0']['level'].split('_')
|
||||
self.data.static.put_music(
|
||||
self.version,
|
||||
song_id,
|
||||
1,
|
||||
pv_data["song_name"],
|
||||
pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"],
|
||||
pv_data["songinfo"]["lyrics"],
|
||||
pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"),
|
||||
pv_data["bpm"],
|
||||
pv_data["date"],
|
||||
)
|
||||
|
||||
if "hard" in pv_data["difficulty"] and "0" in pv_data["difficulty"]["hard"]:
|
||||
diff = pv_data["difficulty"]["hard"]["0"]["level"].split("_")
|
||||
self.logger.info(f"Added song {song_id} chart 2")
|
||||
|
||||
self.data.static.put_music(self.version, song_id, 2, pv_data["song_name"], pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"], pv_data["songinfo"]["lyrics"], pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"), pv_data["bpm"], pv_data["date"])
|
||||
|
||||
if "extreme" in pv_data['difficulty']:
|
||||
if "0" in pv_data['difficulty']['extreme']:
|
||||
diff = pv_data['difficulty']['extreme']['0']['level'].split('_')
|
||||
self.data.static.put_music(
|
||||
self.version,
|
||||
song_id,
|
||||
2,
|
||||
pv_data["song_name"],
|
||||
pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"],
|
||||
pv_data["songinfo"]["lyrics"],
|
||||
pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"),
|
||||
pv_data["bpm"],
|
||||
pv_data["date"],
|
||||
)
|
||||
|
||||
if "extreme" in pv_data["difficulty"]:
|
||||
if "0" in pv_data["difficulty"]["extreme"]:
|
||||
diff = pv_data["difficulty"]["extreme"]["0"]["level"].split("_")
|
||||
self.logger.info(f"Added song {song_id} chart 3")
|
||||
|
||||
self.data.static.put_music(self.version, song_id, 3, pv_data["song_name"], pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"], pv_data["songinfo"]["lyrics"], pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"), pv_data["bpm"], pv_data["date"])
|
||||
self.data.static.put_music(
|
||||
self.version,
|
||||
song_id,
|
||||
3,
|
||||
pv_data["song_name"],
|
||||
pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"],
|
||||
pv_data["songinfo"]["lyrics"],
|
||||
pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"),
|
||||
pv_data["bpm"],
|
||||
pv_data["date"],
|
||||
)
|
||||
|
||||
if "1" in pv_data['difficulty']['extreme']:
|
||||
diff = pv_data['difficulty']['extreme']['1']['level'].split('_')
|
||||
if "1" in pv_data["difficulty"]["extreme"]:
|
||||
diff = pv_data["difficulty"]["extreme"]["1"]["level"].split("_")
|
||||
self.logger.info(f"Added song {song_id} chart 4")
|
||||
|
||||
self.data.static.put_music(self.version, song_id, 4, pv_data["song_name"], pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"], pv_data["songinfo"]["lyrics"], pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"), pv_data["bpm"], pv_data["date"])
|
||||
self.data.static.put_music(
|
||||
self.version,
|
||||
song_id,
|
||||
4,
|
||||
pv_data["song_name"],
|
||||
pv_data["songinfo"]["arranger"],
|
||||
pv_data["songinfo"]["illustrator"],
|
||||
pv_data["songinfo"]["lyrics"],
|
||||
pv_data["songinfo"]["music"],
|
||||
float(f"{diff[2]}.{diff[3]}"),
|
||||
pv_data["bpm"],
|
||||
pv_data["date"],
|
||||
)
|
||||
|
||||
def add_branch(self, tree: Dict, vector: List, value: str):
|
||||
"""
|
||||
@ -195,9 +295,9 @@ class DivaReader(BaseReader):
|
||||
Author: iJames on StackOverflow
|
||||
"""
|
||||
key = vector[0]
|
||||
tree[key] = value \
|
||||
if len(vector) == 1 \
|
||||
else self.add_branch(tree[key] if key in tree else {},
|
||||
vector[1:],
|
||||
value)
|
||||
return tree
|
||||
tree[key] = (
|
||||
value
|
||||
if len(vector) == 1
|
||||
else self.add_branch(tree[key] if key in tree else {}, vector[1:], value)
|
||||
)
|
||||
return tree
|
||||
|
||||
@ -6,6 +6,12 @@ from titles.diva.schema.pv_customize import DivaPvCustomizeData
|
||||
from titles.diva.schema.item import DivaItemData
|
||||
from titles.diva.schema.static import DivaStaticData
|
||||
|
||||
__all__ = [DivaProfileData, DivaScoreData, DivaModuleData,
|
||||
DivaCustomizeItemData, DivaPvCustomizeData, DivaItemData,
|
||||
DivaStaticData]
|
||||
__all__ = [
|
||||
DivaProfileData,
|
||||
DivaScoreData,
|
||||
DivaModuleData,
|
||||
DivaCustomizeItemData,
|
||||
DivaPvCustomizeData,
|
||||
DivaItemData,
|
||||
DivaStaticData,
|
||||
]
|
||||
|
||||
@ -10,25 +10,29 @@ customize = Table(
|
||||
"diva_profile_customize_item",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("item_id", Integer, nullable=False),
|
||||
UniqueConstraint("user", "version", "item_id", name="diva_profile_customize_item_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
UniqueConstraint(
|
||||
"user", "version", "item_id", name="diva_profile_customize_item_uk"
|
||||
),
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaCustomizeItemData(BaseData):
|
||||
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
|
||||
)
|
||||
sql = insert(customize).values(version=version, user=aime_id, item_id=item_id)
|
||||
|
||||
result = 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}")
|
||||
self.logger.error(
|
||||
f"{__name__} Failed to insert diva profile customize item! aime id: {aime_id} item: {item_id}"
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
@ -36,10 +40,9 @@ class DivaCustomizeItemData(BaseData):
|
||||
"""
|
||||
Given a game version and an aime id, return all the customize items, not used directly
|
||||
"""
|
||||
sql = customize.select(and_(
|
||||
customize.c.version == version,
|
||||
customize.c.user == aime_id
|
||||
))
|
||||
sql = customize.select(
|
||||
and_(customize.c.version == version, customize.c.user == aime_id)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
||||
@ -11,37 +11,48 @@ shop = Table(
|
||||
"diva_profile_shop",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("mdl_eqp_ary", String(32)),
|
||||
Column("c_itm_eqp_ary", String(59)),
|
||||
Column("ms_itm_flg_ary", String(59)),
|
||||
UniqueConstraint("user", "version", name="diva_profile_shop_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaItemData(BaseData):
|
||||
def put_shop(self, aime_id: int, version: int, mdl_eqp_ary: str,
|
||||
c_itm_eqp_ary: str, ms_itm_flg_ary: str) -> None:
|
||||
|
||||
def put_shop(
|
||||
self,
|
||||
aime_id: int,
|
||||
version: int,
|
||||
mdl_eqp_ary: str,
|
||||
c_itm_eqp_ary: str,
|
||||
ms_itm_flg_ary: str,
|
||||
) -> None:
|
||||
sql = insert(shop).values(
|
||||
version=version,
|
||||
user=aime_id,
|
||||
mdl_eqp_ary=mdl_eqp_ary,
|
||||
c_itm_eqp_ary=c_itm_eqp_ary,
|
||||
ms_itm_flg_ary=ms_itm_flg_ary
|
||||
ms_itm_flg_ary=ms_itm_flg_ary,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
mdl_eqp_ary=mdl_eqp_ary,
|
||||
c_itm_eqp_ary=c_itm_eqp_ary,
|
||||
ms_itm_flg_ary=ms_itm_flg_ary
|
||||
ms_itm_flg_ary=ms_itm_flg_ary,
|
||||
)
|
||||
|
||||
result = 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}")
|
||||
self.logger.error(
|
||||
f"{__name__} Failed to insert diva profile! aime id: {aime_id} array: {mdl_eqp_ary}"
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
@ -49,10 +60,7 @@ class DivaItemData(BaseData):
|
||||
"""
|
||||
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
|
||||
))
|
||||
sql = shop.select(and_(shop.c.version == version, shop.c.user == aime_id))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
||||
@ -10,25 +10,27 @@ module = Table(
|
||||
"diva_profile_module",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("module_id", Integer, nullable=False),
|
||||
UniqueConstraint("user", "version", "module_id", name="diva_profile_module_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaModuleData(BaseData):
|
||||
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
|
||||
)
|
||||
sql = insert(module).values(version=version, user=aime_id, module_id=module_id)
|
||||
|
||||
result = 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}")
|
||||
self.logger.error(
|
||||
f"{__name__} Failed to insert diva profile module! aime id: {aime_id} module: {module_id}"
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
@ -36,10 +38,7 @@ class DivaModuleData(BaseData):
|
||||
"""
|
||||
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
|
||||
))
|
||||
sql = module.select(and_(module.c.version == version, module.c.user == aime_id))
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
||||
@ -11,8 +11,11 @@ profile = Table(
|
||||
"diva_profile",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade",
|
||||
onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("player_name", String(10), nullable=False),
|
||||
Column("lv_str", String(24), nullable=False, server_default="Dab on 'em"),
|
||||
@ -29,10 +32,8 @@ profile = Table(
|
||||
Column("use_pv_skn_eqp", Boolean, nullable=False, server_default="0"),
|
||||
Column("use_pv_btn_se_eqp", Boolean, nullable=False, server_default="1"),
|
||||
Column("use_pv_sld_se_eqp", Boolean, nullable=False, server_default="0"),
|
||||
Column("use_pv_chn_sld_se_eqp", Boolean,
|
||||
nullable=False, server_default="0"),
|
||||
Column("use_pv_sldr_tch_se_eqp", Boolean,
|
||||
nullable=False, server_default="0"),
|
||||
Column("use_pv_chn_sld_se_eqp", Boolean, nullable=False, server_default="0"),
|
||||
Column("use_pv_sldr_tch_se_eqp", Boolean, nullable=False, server_default="0"),
|
||||
Column("nxt_pv_id", Integer, nullable=False, server_default="708"),
|
||||
Column("nxt_dffclty", Integer, nullable=False, server_default="2"),
|
||||
Column("nxt_edtn", Integer, nullable=False, server_default="0"),
|
||||
@ -44,35 +45,39 @@ profile = Table(
|
||||
Column("lv_plt_id", Integer, nullable=False, server_default="1"),
|
||||
Column("passwd_stat", Integer, nullable=False, server_default="0"),
|
||||
Column("passwd", String(12), nullable=False, server_default="**********"),
|
||||
Column("my_qst_id", String(
|
||||
128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
|
||||
Column("my_qst_sts", String(
|
||||
128), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
|
||||
Column(
|
||||
"my_qst_id",
|
||||
String(128),
|
||||
server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
),
|
||||
Column(
|
||||
"my_qst_sts",
|
||||
String(128),
|
||||
server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
),
|
||||
UniqueConstraint("user", "version", name="diva_profile_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaProfileData(BaseData):
|
||||
def create_profile(self, version: int, aime_id: int,
|
||||
player_name: str) -> Optional[int]:
|
||||
def create_profile(
|
||||
self, version: int, aime_id: int, player_name: str
|
||||
) -> Optional[int]:
|
||||
"""
|
||||
Given a game version, aime id, and player_name, create a profile and return it's ID
|
||||
"""
|
||||
sql = insert(profile).values(
|
||||
version=version,
|
||||
user=aime_id,
|
||||
player_name=player_name
|
||||
version=version, user=aime_id, player_name=player_name
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
player_name=sql.inserted.player_name
|
||||
)
|
||||
conflict = sql.on_duplicate_key_update(player_name=sql.inserted.player_name)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.error(
|
||||
f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}")
|
||||
f"{__name__} Failed to insert diva profile! aime id: {aime_id} username: {player_name}"
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
@ -86,17 +91,17 @@ class DivaProfileData(BaseData):
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
self.logger.error(
|
||||
f"update_profile: failed to update profile! profile: {aime_id}")
|
||||
f"update_profile: failed to update profile! profile: {aime_id}"
|
||||
)
|
||||
return None
|
||||
|
||||
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
|
||||
"""
|
||||
sql = profile.select(and_(
|
||||
profile.c.version == version,
|
||||
profile.c.user == aime_id
|
||||
))
|
||||
sql = profile.select(
|
||||
and_(profile.c.version == version, profile.c.user == aime_id)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
||||
@ -10,27 +10,44 @@ pv_customize = Table(
|
||||
"diva_profile_pv_customize",
|
||||
metadata,
|
||||
Column("id", Integer, primary_key=True, nullable=False),
|
||||
Column("user", ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"), nullable=False),
|
||||
Column(
|
||||
"user",
|
||||
ForeignKey("aime_user.id", ondelete="cascade", onupdate="cascade"),
|
||||
nullable=False,
|
||||
),
|
||||
Column("version", Integer, nullable=False),
|
||||
Column("pv_id", Integer, nullable=False),
|
||||
Column("mdl_eqp_ary", String(14), server_default="-999,-999,-999"),
|
||||
Column("c_itm_eqp_ary", String(59), server_default="-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999"),
|
||||
Column("ms_itm_flg_ary", String(59), server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1"),
|
||||
Column(
|
||||
"c_itm_eqp_ary",
|
||||
String(59),
|
||||
server_default="-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999,-999",
|
||||
),
|
||||
Column(
|
||||
"ms_itm_flg_ary",
|
||||
String(59),
|
||||
server_default="-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1",
|
||||
),
|
||||
Column("skin", Integer, server_default="-1"),
|
||||
Column("btn_se", Integer, server_default="-1"),
|
||||
Column("sld_se", Integer, server_default="-1"),
|
||||
Column("chsld_se", Integer, server_default="-1"),
|
||||
Column("sldtch_se", Integer, server_default="-1"),
|
||||
UniqueConstraint("user", "version", "pv_id", name="diva_profile_pv_customize_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaPvCustomizeData(BaseData):
|
||||
def put_pv_customize(self, aime_id: int, version: int, pv_id: int,
|
||||
mdl_eqp_ary: str, c_itm_eqp_ary: str,
|
||||
ms_itm_flg_ary: str) -> Optional[int]:
|
||||
|
||||
def put_pv_customize(
|
||||
self,
|
||||
aime_id: int,
|
||||
version: int,
|
||||
pv_id: int,
|
||||
mdl_eqp_ary: str,
|
||||
c_itm_eqp_ary: str,
|
||||
ms_itm_flg_ary: str,
|
||||
) -> Optional[int]:
|
||||
sql = insert(pv_customize).values(
|
||||
version=version,
|
||||
user=aime_id,
|
||||
@ -49,19 +66,19 @@ class DivaPvCustomizeData(BaseData):
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.error(f"{__name__} Failed to insert diva pv customize! aime id: {aime_id}")
|
||||
self.logger.error(
|
||||
f"{__name__} Failed to insert diva pv customize! aime id: {aime_id}"
|
||||
)
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_pv_customize(self, aime_id: int,
|
||||
pv_id: int) -> Optional[List[Dict]]:
|
||||
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
|
||||
"""
|
||||
sql = pv_customize.select(and_(
|
||||
pv_customize.c.user == aime_id,
|
||||
pv_customize.c.pv_id == pv_id
|
||||
))
|
||||
sql = pv_customize.select(
|
||||
and_(pv_customize.c.user == aime_id, pv_customize.c.pv_id == pv_id)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
|
||||
@ -28,7 +28,7 @@ score = Table(
|
||||
Column("worst", Integer),
|
||||
Column("max_combo", Integer),
|
||||
UniqueConstraint("user", "pv_id", "difficulty", "edition", name="diva_score_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
playlog = Table(
|
||||
@ -51,16 +51,29 @@ playlog = Table(
|
||||
Column("worst", Integer),
|
||||
Column("max_combo", Integer),
|
||||
Column("date_scored", TIMESTAMP, server_default=func.now()),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaScoreData(BaseData):
|
||||
def put_best_score(self, user_id: int, game_version: int, song_id: int,
|
||||
difficulty: int, edition: int, song_score: int,
|
||||
atn_pnt: int, clr_kind: int, sort_kind: int,
|
||||
cool: int, fine: int, safe: int, sad: int,
|
||||
worst: int, max_combo: int) -> Optional[int]:
|
||||
def put_best_score(
|
||||
self,
|
||||
user_id: int,
|
||||
game_version: int,
|
||||
song_id: int,
|
||||
difficulty: int,
|
||||
edition: int,
|
||||
song_score: int,
|
||||
atn_pnt: int,
|
||||
clr_kind: int,
|
||||
sort_kind: int,
|
||||
cool: int,
|
||||
fine: int,
|
||||
safe: int,
|
||||
sad: int,
|
||||
worst: int,
|
||||
max_combo: int,
|
||||
) -> Optional[int]:
|
||||
"""
|
||||
Update the user's best score for a chart
|
||||
"""
|
||||
@ -98,16 +111,30 @@ class DivaScoreData(BaseData):
|
||||
result = self.execute(conflict)
|
||||
if result is None:
|
||||
self.logger.error(
|
||||
f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}")
|
||||
f"{__name__} failed to insert best score! profile: {user_id}, song: {song_id}"
|
||||
)
|
||||
return None
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
def put_playlog(self, user_id: int, game_version: int, song_id: int,
|
||||
difficulty: int, edition: int, song_score: int,
|
||||
atn_pnt: int, clr_kind: int, sort_kind: int,
|
||||
cool: int, fine: int, safe: int, sad: int,
|
||||
worst: int, max_combo: int) -> Optional[int]:
|
||||
def put_playlog(
|
||||
self,
|
||||
user_id: int,
|
||||
game_version: int,
|
||||
song_id: int,
|
||||
difficulty: int,
|
||||
edition: int,
|
||||
song_score: int,
|
||||
atn_pnt: int,
|
||||
clr_kind: int,
|
||||
sort_kind: int,
|
||||
cool: int,
|
||||
fine: int,
|
||||
safe: int,
|
||||
sad: int,
|
||||
worst: int,
|
||||
max_combo: int,
|
||||
) -> Optional[int]:
|
||||
"""
|
||||
Add an entry to the user's play log
|
||||
"""
|
||||
@ -126,24 +153,28 @@ class DivaScoreData(BaseData):
|
||||
safe=safe,
|
||||
sad=sad,
|
||||
worst=worst,
|
||||
max_combo=max_combo
|
||||
max_combo=max_combo,
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
self.logger.error(
|
||||
f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}")
|
||||
f"{__name__} failed to insert playlog! profile: {user_id}, song: {song_id}, chart: {difficulty}"
|
||||
)
|
||||
return None
|
||||
|
||||
return result.lastrowid
|
||||
|
||||
def get_best_user_score(self, user_id: int, pv_id: int, difficulty: int,
|
||||
edition: int) -> Optional[Dict]:
|
||||
def get_best_user_score(
|
||||
self, user_id: int, pv_id: int, difficulty: int, edition: int
|
||||
) -> Optional[Dict]:
|
||||
sql = score.select(
|
||||
and_(score.c.user == user_id,
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition)
|
||||
and_(
|
||||
score.c.user == user_id,
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
@ -151,36 +182,48 @@ class DivaScoreData(BaseData):
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
def get_top3_scores(self, pv_id: int, difficulty: int,
|
||||
edition: int) -> Optional[List[Dict]]:
|
||||
sql = score.select(
|
||||
and_(score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition)
|
||||
).order_by(score.c.score.desc()).limit(3)
|
||||
def get_top3_scores(
|
||||
self, pv_id: int, difficulty: int, edition: int
|
||||
) -> Optional[List[Dict]]:
|
||||
sql = (
|
||||
score.select(
|
||||
and_(
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition,
|
||||
)
|
||||
)
|
||||
.order_by(score.c.score.desc())
|
||||
.limit(3)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_global_ranking(self, user_id: int, pv_id: int, difficulty: int,
|
||||
edition: int) -> Optional[List]:
|
||||
def get_global_ranking(
|
||||
self, user_id: int, pv_id: int, difficulty: int, edition: int
|
||||
) -> Optional[List]:
|
||||
# get the subquery max score of a user with pv_id, difficulty and
|
||||
# edition
|
||||
sql_sub = select([score.c.score]).filter(
|
||||
score.c.user == user_id,
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition
|
||||
).scalar_subquery()
|
||||
sql_sub = (
|
||||
select([score.c.score])
|
||||
.filter(
|
||||
score.c.user == user_id,
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition,
|
||||
)
|
||||
.scalar_subquery()
|
||||
)
|
||||
|
||||
# Perform the main query, also rename the resulting column to ranking
|
||||
sql = select(func.count(score.c.id).label("ranking")).filter(
|
||||
score.c.score >= sql_sub,
|
||||
score.c.pv_id == pv_id,
|
||||
score.c.difficulty == difficulty,
|
||||
score.c.edition == edition
|
||||
score.c.edition == edition,
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
|
||||
@ -25,7 +25,7 @@ music = Table(
|
||||
Column("bpm", Integer),
|
||||
Column("date", String(255)),
|
||||
UniqueConstraint("version", "songId", "chartId", name="diva_static_music_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
quests = Table(
|
||||
@ -43,9 +43,8 @@ quests = Table(
|
||||
Column("quest_order", Integer),
|
||||
Column("start_datetime", String(255)),
|
||||
Column("end_datetime", String(255)),
|
||||
|
||||
UniqueConstraint("version", "questId", name="diva_static_quests_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
shop = Table(
|
||||
@ -62,7 +61,7 @@ shop = Table(
|
||||
Column("end_date", String(255)),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
UniqueConstraint("version", "shopId", name="diva_static_shop_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
items = Table(
|
||||
@ -79,64 +78,91 @@ items = Table(
|
||||
Column("end_date", String(255)),
|
||||
Column("enabled", Boolean, server_default="1"),
|
||||
UniqueConstraint("version", "itemId", name="diva_static_items_uk"),
|
||||
mysql_charset='utf8mb4'
|
||||
mysql_charset="utf8mb4",
|
||||
)
|
||||
|
||||
|
||||
class DivaStaticData(BaseData):
|
||||
def put_quests(self, version: int, questId: int, name: str, kind: int, unknown_0: int, unknown_1: int, unknown_2: int, quest_order: int, start_datetime: str, end_datetime: str) -> Optional[int]:
|
||||
def put_quests(
|
||||
self,
|
||||
version: int,
|
||||
questId: int,
|
||||
name: str,
|
||||
kind: int,
|
||||
unknown_0: int,
|
||||
unknown_1: int,
|
||||
unknown_2: int,
|
||||
quest_order: int,
|
||||
start_datetime: str,
|
||||
end_datetime: str,
|
||||
) -> Optional[int]:
|
||||
sql = insert(quests).values(
|
||||
version = version,
|
||||
questId = questId,
|
||||
name = name,
|
||||
kind = kind,
|
||||
unknown_0 = unknown_0,
|
||||
unknown_1 = unknown_1,
|
||||
unknown_2 = unknown_2,
|
||||
quest_order = quest_order,
|
||||
start_datetime = start_datetime,
|
||||
end_datetime = end_datetime
|
||||
version=version,
|
||||
questId=questId,
|
||||
name=name,
|
||||
kind=kind,
|
||||
unknown_0=unknown_0,
|
||||
unknown_1=unknown_1,
|
||||
unknown_2=unknown_2,
|
||||
quest_order=quest_order,
|
||||
start_datetime=start_datetime,
|
||||
end_datetime=end_datetime,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
name = name
|
||||
)
|
||||
conflict = sql.on_duplicate_key_update(name=name)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
|
||||
def get_enabled_quests(self, version: int) -> Optional[List[Row]]:
|
||||
sql = select(quests).where(and_(quests.c.version == version, quests.c.quest_enable == True))
|
||||
sql = select(quests).where(
|
||||
and_(quests.c.version == version, quests.c.quest_enable == True)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_shop(self, version: int, shopId: int, name: str, type: int, points: int, unknown_0: int, start_date: str, end_date: str) -> Optional[int]:
|
||||
def put_shop(
|
||||
self,
|
||||
version: int,
|
||||
shopId: int,
|
||||
name: str,
|
||||
type: int,
|
||||
points: int,
|
||||
unknown_0: int,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
) -> Optional[int]:
|
||||
sql = insert(shop).values(
|
||||
version = version,
|
||||
shopId = shopId,
|
||||
name = name,
|
||||
type = type,
|
||||
points = points,
|
||||
unknown_0 = unknown_0,
|
||||
start_date = start_date,
|
||||
end_date = end_date
|
||||
version=version,
|
||||
shopId=shopId,
|
||||
name=name,
|
||||
type=type,
|
||||
points=points,
|
||||
unknown_0=unknown_0,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
name = name
|
||||
)
|
||||
conflict = sql.on_duplicate_key_update(name=name)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_enabled_shop(self, version: int, shopId: int) -> Optional[Row]:
|
||||
sql = select(shop).where(and_(
|
||||
shop.c.version == version,
|
||||
shop.c.shopId == shopId,
|
||||
shop.c.enabled == True))
|
||||
sql = select(shop).where(
|
||||
and_(
|
||||
shop.c.version == version,
|
||||
shop.c.shopId == shopId,
|
||||
shop.c.enabled == True,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
@ -144,40 +170,52 @@ class DivaStaticData(BaseData):
|
||||
return result.fetchone()
|
||||
|
||||
def get_enabled_shops(self, version: int) -> Optional[List[Row]]:
|
||||
sql = select(shop).where(and_(
|
||||
shop.c.version == version,
|
||||
shop.c.enabled == True))
|
||||
sql = select(shop).where(
|
||||
and_(shop.c.version == version, shop.c.enabled == True)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_items(self, version: int, itemId: int, name: str, type: int, points: int, unknown_0: int, start_date: str, end_date: str) -> Optional[int]:
|
||||
def put_items(
|
||||
self,
|
||||
version: int,
|
||||
itemId: int,
|
||||
name: str,
|
||||
type: int,
|
||||
points: int,
|
||||
unknown_0: int,
|
||||
start_date: str,
|
||||
end_date: str,
|
||||
) -> Optional[int]:
|
||||
sql = insert(items).values(
|
||||
version = version,
|
||||
itemId = itemId,
|
||||
name = name,
|
||||
type = type,
|
||||
points = points,
|
||||
unknown_0 = unknown_0,
|
||||
start_date = start_date,
|
||||
end_date = end_date
|
||||
version=version,
|
||||
itemId=itemId,
|
||||
name=name,
|
||||
type=type,
|
||||
points=points,
|
||||
unknown_0=unknown_0,
|
||||
start_date=start_date,
|
||||
end_date=end_date,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
name = name
|
||||
)
|
||||
conflict = sql.on_duplicate_key_update(name=name)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_enabled_item(self, version: int, itemId: int) -> Optional[Row]:
|
||||
sql = select(items).where(and_(
|
||||
items.c.version == version,
|
||||
items.c.itemId == itemId,
|
||||
items.c.enabled == True))
|
||||
sql = select(items).where(
|
||||
and_(
|
||||
items.c.version == version,
|
||||
items.c.itemId == itemId,
|
||||
items.c.enabled == True,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
@ -185,66 +223,89 @@ class DivaStaticData(BaseData):
|
||||
return result.fetchone()
|
||||
|
||||
def get_enabled_items(self, version: int) -> Optional[List[Row]]:
|
||||
sql = select(items).where(and_(
|
||||
items.c.version == version,
|
||||
items.c.enabled == True))
|
||||
sql = select(items).where(
|
||||
and_(items.c.version == version, items.c.enabled == True)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def put_music(self, version: int, song: int, chart: int, title: str, arranger: str, illustrator: str,
|
||||
lyrics: str, music_comp: str, level: float, bpm: int, date: str) -> Optional[int]:
|
||||
def put_music(
|
||||
self,
|
||||
version: int,
|
||||
song: int,
|
||||
chart: int,
|
||||
title: str,
|
||||
arranger: str,
|
||||
illustrator: str,
|
||||
lyrics: str,
|
||||
music_comp: str,
|
||||
level: float,
|
||||
bpm: int,
|
||||
date: str,
|
||||
) -> Optional[int]:
|
||||
sql = insert(music).values(
|
||||
version = version,
|
||||
songId = song,
|
||||
chartId = chart,
|
||||
title = title,
|
||||
vocaloid_arranger = arranger,
|
||||
pv_illustrator = illustrator,
|
||||
lyrics = lyrics,
|
||||
bg_music = music_comp,
|
||||
level = level,
|
||||
bpm = bpm,
|
||||
date = date
|
||||
version=version,
|
||||
songId=song,
|
||||
chartId=chart,
|
||||
title=title,
|
||||
vocaloid_arranger=arranger,
|
||||
pv_illustrator=illustrator,
|
||||
lyrics=lyrics,
|
||||
bg_music=music_comp,
|
||||
level=level,
|
||||
bpm=bpm,
|
||||
date=date,
|
||||
)
|
||||
|
||||
conflict = sql.on_duplicate_key_update(
|
||||
title = title,
|
||||
vocaloid_arranger = arranger,
|
||||
pv_illustrator = illustrator,
|
||||
lyrics = lyrics,
|
||||
bg_music = music_comp,
|
||||
level = level,
|
||||
bpm = bpm,
|
||||
date = date
|
||||
title=title,
|
||||
vocaloid_arranger=arranger,
|
||||
pv_illustrator=illustrator,
|
||||
lyrics=lyrics,
|
||||
bg_music=music_comp,
|
||||
level=level,
|
||||
bpm=bpm,
|
||||
date=date,
|
||||
)
|
||||
|
||||
result = self.execute(conflict)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.lastrowid
|
||||
|
||||
def get_music(self, version: int, song_id: Optional[int] = None) -> Optional[List[Row]]:
|
||||
|
||||
def get_music(
|
||||
self, version: int, song_id: Optional[int] = None
|
||||
) -> Optional[List[Row]]:
|
||||
if song_id is None:
|
||||
sql = select(music).where(music.c.version == version)
|
||||
else:
|
||||
sql = select(music).where(and_(
|
||||
music.c.version == version,
|
||||
music.c.songId == song_id,
|
||||
))
|
||||
sql = select(music).where(
|
||||
and_(
|
||||
music.c.version == version,
|
||||
music.c.songId == song_id,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchall()
|
||||
|
||||
def get_music_chart(self, version: int, song_id: int, chart_id: int) -> Optional[List[Row]]:
|
||||
sql = select(music).where(and_(
|
||||
music.c.version == version,
|
||||
music.c.songId == song_id,
|
||||
music.c.chartId == chart_id
|
||||
))
|
||||
|
||||
def get_music_chart(
|
||||
self, version: int, song_id: int, chart_id: int
|
||||
) -> Optional[List[Row]]:
|
||||
sql = select(music).where(
|
||||
and_(
|
||||
music.c.version == version,
|
||||
music.c.songId == song_id,
|
||||
music.c.chartId == chart_id,
|
||||
)
|
||||
)
|
||||
|
||||
result = self.execute(sql)
|
||||
if result is None: return None
|
||||
if result is None:
|
||||
return None
|
||||
return result.fetchone()
|
||||
|
||||
Reference in New Issue
Block a user