Skip to content

Commit

Permalink
security update
Browse files Browse the repository at this point in the history
  • Loading branch information
Diving-Fish committed Jan 23, 2024
1 parent adf93b9 commit 336911e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 66 deletions.
36 changes: 10 additions & 26 deletions database/models/maimai.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ def verify_plate(player, version, plate_type) -> Tuple[bool, str]:
return False, ""


def get_masked_achievement(record: NewRecord):
sc = ScoreCoefficient(record.achievements)
def get_masked_achievement(record: NewRecord, sc: ScoreCoefficient, ra: int):
if record.achievements >= 100.5:
if record.fc == "ap" or record.fc == "app":
return 101
return math.floor(record.achievements * 10) / 10
if sc.c == 0:
return 0
acc = sc.ra(record.ds) * 100 / sc.c / record.ds
acc = ra * 100 / sc.c / record.ds
if acc < sc.min:
acc = sc.min
else:
Expand All @@ -157,51 +156,36 @@ def get_masked_achievement(record: NewRecord):


def record_json(record: NewRecord, masked: bool):
sc = ScoreCoefficient(record.achievements)
ra = sc.ra(record.ds)
data = {
"title": record.title,
"level": record.diff,
"level_index": record.level,
"level_label": ["Basic", "Advanced", "Expert", "Master", "Re:MASTER"][record.level],
"type": record.type,
"dxScore": 0 if masked else record.dxScore,
"achievements": get_masked_achievement(record) if masked else record.achievements,
"rate": ScoreCoefficient(record.achievements).r,
"achievements": get_masked_achievement(record, sc, ra) if masked else record.achievements,
"rate": sc.r,
"fc": record.fc,
"fs": record.fs,
"ra": ScoreCoefficient(record.achievements).ra(record.ds),
"ra": ra,
"ds": record.ds,
"song_id": record.id
}
return data


def record_json_output(record: NewRecord, masked: bool):
t1 = time.time()
chart = record.chart
print(time.time() - t1)
music = chart.music
print(time.time() - t1)
return {
"title": music.title,
"level": chart.level,
"level_index": chart.level,
"type": music.type,
"dxScore": 0 if masked else record.dxScore,
"achievements": get_masked_achievement(record) if masked else record.achievements,
"rate": ScoreCoefficient(record.achievements).r,
"fc": record.fc,
"fs": record.fs,
}


def platerecord_json(platerecord: NewRecord, masked: bool):
sc = ScoreCoefficient(platerecord.achievements)
ra = sc.ra(platerecord.ds)
data = {
"id": platerecord.id,
"title": platerecord.title,
"level": platerecord.diff,
"level_index": platerecord.level,
"type": platerecord.type,
"achievements": get_masked_achievement(platerecord) if masked else platerecord.achievements,
"achievements": get_masked_achievement(platerecord, sc, ra) if masked else platerecord.achievements,
"fc": platerecord.fc,
"fs": platerecord.fs
}
Expand Down
56 changes: 16 additions & 40 deletions database/routes/maimai.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def agreement():
obj = await request.json
if "accept_agreement" in obj:
g.user.accept_agreement = obj["accept_agreement"]
g.save()
g.user.save()
return {"message": "success"}


Expand Down Expand Up @@ -365,45 +365,21 @@ async def update_records():
cs_need_update = True
j = await request.get_json()
dicts = {}
if "userId" in j:
pass
try:
for ml in j["userMusicList"]:
for m in ml["userMusicDetailList"]:
if str(m["musicId"]) not in md_map:
continue
music = md_map[str(m["musicId"])]
level = m["level"]
achievement = min(1010000, m["achievement"])
fc = ["", "fc", "fcp", "ap", "app"][m["comboStatus"]]
fs = ["", "fs", "fsp", "fsd", "fsdp"][m["syncStatus"]]
dxScore = m["deluxscoreMax"]
cid = music["cids"][level]
dicts[cid] = (achievement / 10000.0, fc, fs, dxScore)
g.user.user_id = j["userId"]
g.user.user_data = json.dumps(j["userData"]) if "userData" in j else ""
g.user.save()
except Exception as e:
raise e
return {
"message": str(e)
}, 400
else:
if type(j) != type([]):
return {"message": "导入数据格式有误"}, 404
elif len(j) == 0:
return {"message": "更新成功"}
for record in j:
# print(time.time())
title = record['title']
_type = record['type']
level = record['level_index']
m = get_music_by_title(md_cache, title, _type)
if m is None or level >= len(m["cids"]):
continue
cid = m["cids"][level]
dicts[cid] = (record["achievements"], record["fc"],
record["fs"], record["dxScore"])
if type(j) != type([]):
return {"message": "导入数据格式有误"}, 404
elif len(j) == 0:
return {"message": "更新成功"}
for record in j:
# print(time.time())
title = record['title']
_type = record['type']
level = record['level_index']
m = get_music_by_title(md_cache, title, _type)
if m is None or level >= len(m["cids"]):
continue
cid = m["cids"][level]
dicts[cid] = (record["achievements"], record["fc"],
record["fs"], record["dxScore"])
rs = NewRecord.raw(
'select * from newrecord where player_id = %s', g.user.id)
updates = []
Expand Down
5 changes: 5 additions & 0 deletions database/routes/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ async def message_resp():
return resp


@app.route("/alive_check", methods=['GET'])
async def alive_check():
return {"message": "ok"}


@app.route("/message", methods=['GET'])
async def message_g():
return await message_resp()
Expand Down

0 comments on commit 336911e

Please sign in to comment.