From 2c7c761a44f95bf203e3b9604516e37180624666 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Thu, 14 Aug 2025 07:44:13 +0000 Subject: [PATCH] feat(score): add simple suspicious score check TODO: use another lib to check the beatmap is whether suspicious or not --- .env.example | 1 + README.md | 1 + app/calculator.py | 15 ++++++++++++++- app/config.py | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 67e0c2f..c253552 100644 --- a/.env.example +++ b/.env.example @@ -55,6 +55,7 @@ ENABLE_ALL_MODS_PP=false # 启用所有 Mod 的 PP 计算 ENABLE_SUPPORTER_FOR_ALL_USERS=false # 启用所有新注册用户的支持者状态 ENABLE_ALL_BEATMAP_LEADERBOARD=false # 启用所有谱面的排行榜(没有排行榜的谱面会以 APPROVED 状态返回) ENABLE_ALL_BEATMAP_PP=false # 允许任何谱面获得 PP +SUSPICIOUS_SCORE_CHECK=true # 是否检查可疑的分数,默认开启 SEASONAL_BACKGROUNDS='[]' # 季节背景图 URL 列表 # 存储服务设置 diff --git a/README.md b/README.md index a48cd8a..02c2983 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ Fetcher 用于从 osu! 官方 API 获取数据,使用 osu! 官方 API 的 OAut | `ENABLE_SUPPORTER_FOR_ALL_USERS` | 启用所有新注册用户的支持者状态 | `false` | | `ENABLE_ALL_BEATMAP_LEADERBOARD` | 启用所有谱面的排行榜 | `false` | | `ENABLE_ALL_BEATMAP_PP` | 允许任何谱面获得 PP | `false` | +| `SUSPICIOUS_SCORE_CHECK` | 启用可疑分数检查(star>25&acc<80 或 pp>2300) | `true` | | `SEASONAL_BACKGROUNDS` | 季节背景图 URL 列表 | `[]` | ### 存储服务设置 diff --git a/app/calculator.py b/app/calculator.py index 950bd45..508bf58 100644 --- a/app/calculator.py +++ b/app/calculator.py @@ -3,6 +3,8 @@ from __future__ import annotations import math from typing import TYPE_CHECKING +from app.config import settings +from app.log import logger from app.models.beatmap import BeatmapAttributes from app.models.mods import APIMod from app.models.score import GameMode @@ -75,7 +77,18 @@ def calculate_pp( misses=score.nmiss, ) attrs = perf.calculate(map) - return attrs.pp + pp = attrs.pp + # mrekk bp1: 2048pp; ppy-sb top1 rxbp1: 2198pp + if settings.suspicious_score_check and ( + (attrs.difficulty.stars > 25 and score.accuracy < 0.8) or pp > 2300 + ): + logger.warning( + f"User {score.user_id} played {score.beatmap_id} with {pp=} " + f"acc={score.accuracy}. The score is suspicious and return 0pp" + f"({score.id=})" + ) + return 0 + return pp # https://osu.ppy.sh/wiki/Gameplay/Score/Total_score diff --git a/app/config.py b/app/config.py index 83b87b5..b73fdbc 100644 --- a/app/config.py +++ b/app/config.py @@ -94,6 +94,7 @@ class Settings(BaseSettings): enable_supporter_for_all_users: bool = False enable_all_beatmap_leaderboard: bool = False enable_all_beatmap_pp: bool = False + suspicious_score_check: bool = True seasonal_backgrounds: list[str] = [] # 存储设置