Skip to content

Commit

Permalink
fix: exception & datetime handle
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueRou committed Dec 13, 2023
1 parent 34780ad commit 4e45d7c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/usecases/anticheat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
from datetime import datetime
import hashlib
import struct
from typing import Optional
from circleguard import Circleguard, ReplayString
from slider import Beatmap

Expand All @@ -25,7 +26,7 @@
vanilla_ur_limition = 60
snaps_limition = 20

def _parse_score(score: Score) -> (ReplayString, Beatmap):
def _parse_score(score: Score) -> (ReplayString, Optional[Beatmap]):
replay_file = REPLAYS_PATH / f"{score.id}.osr"
beatmap_file = BEATMAPS_PATH / f"{score.bmap.id}.osu"
raw_replay_data = replay_file.read_bytes()
Expand Down Expand Up @@ -79,8 +80,13 @@ def _parse_score(score: Score) -> (ReplayString, Beatmap):
replay_data += raw_replay_data
# pack additional info buffer.
replay_data += struct.pack("<q", score.id)
try:
cg_beatmap = Beatmap.from_path(beatmap_file)
except ValueError:
log(f"Failed to load beatmap ({beatmap_file}), skipped.", Ansi.RED)


return circleguard.ReplayString(replay_data), Beatmap.from_path(beatmap_file)
return circleguard.ReplayString(replay_data), cg_beatmap


async def _save_suspicion(score: Score, reason: str, detail: dict):
Expand Down Expand Up @@ -160,6 +166,8 @@ async def validate_checksum(unique_ids: str, osu_version: str, client_hash_decod

async def check_suspicion(player: Player, score: Score):
replay, beatmap = _parse_score(score)
if not beatmap:
return
has_relax = score.mods & Mods.RELAX or score.mods & Mods.AUTOPILOT

frametime = circleguard.frametime(replay)
Expand Down

0 comments on commit 4e45d7c

Please sign in to comment.