From 9636cfcae8f6b38fad32a209a3ffd739bd86dc66 Mon Sep 17 00:00:00 2001 From: Lost-MSth Date: Mon, 6 May 2024 18:01:34 +0800 Subject: [PATCH] [Enhance][Bug fix] ETR world score & Finale & Bundle Update Message - Start to consider the ETR scores when getting the sum of all scores in global ranking. - Add support for automatically adding partner "Hikari & Tairitsu (Reunion)" and "Hikari (Fatalis)", to try to unlock Finale stories correctly. #110 #164 - Fix a bug that the POST requests will be neglected if a new content bundle update exists. --- latest version/core/constant.py | 2 +- latest version/core/user.py | 53 +++++++++++++-------------------- latest version/server/func.py | 2 +- latest version/server/others.py | 27 +++++++++++++---- 4 files changed, 44 insertions(+), 40 deletions(-) diff --git a/latest version/core/constant.py b/latest version/core/constant.py index f9c1a87..64b0a4c 100644 --- a/latest version/core/constant.py +++ b/latest version/core/constant.py @@ -1,6 +1,6 @@ from .config_manager import Config -ARCAEA_SERVER_VERSION = 'v2.11.3.11' +ARCAEA_SERVER_VERSION = 'v2.11.3.12' ARCAEA_DATABASE_VERSION = 'v2.11.3.11' ARCAEA_LOG_DATBASE_VERSION = 'v1.1' diff --git a/latest version/core/user.py b/latest version/core/user.py index 914f154..91787ba 100644 --- a/latest version/core/user.py +++ b/latest version/core/user.py @@ -155,7 +155,6 @@ class UserRegister(User): ''', {'user_code': self.user_code, 'user_id': self.user_id, 'join_date': now, 'name': self.name, 'password': self.hash_pwd, 'memories': Config.DEFAULT_MEMORIES, 'email': self.email}) - class UserLogin(User): # 密码和token的加密方式为 SHA-256 limiter = ArcLimiter(Config.GAME_LOGIN_RATE_LIMIT, 'game_login') @@ -663,38 +662,28 @@ class UserInfo(User): def update_global_rank(self) -> None: '''用户世界排名计算,有新增成绩则要更新''' - self.c.execute('''select song_id, rating_ftr, rating_byn from chart''') - x = self.c.fetchall() + self.c.execute( + ''' + with user_scores as ( + select song_id, difficulty, score from best_score where user_id = ? and difficulty in (2, 3, 4) + ) + select sum(a) from( + select sum(score) as a from user_scores where difficulty = 2 and song_id in (select song_id from chart where rating_ftr > 0) + union + select sum(score) as a from user_scores where difficulty = 3 and song_id in (select song_id from chart where rating_byn > 0) + union + select sum(score) as a from user_scores where difficulty = 4 and song_id in (select song_id from chart where rating_etr > 0) + ) + ''', + (self.user_id,) + ) + x = self.c.fetchone() + if x[0] is None: + return - song_list_ftr = [self.user_id] - song_list_byn = [self.user_id] - for i in x: - if i[1] > 0: - song_list_ftr.append(i[0]) - if i[2] > 0: - song_list_byn.append(i[0]) - - score_sum = 0 - if len(song_list_ftr) >= 2: - self.c.execute( - f'''select sum(score) from best_score where user_id=? and difficulty=2 and song_id in ({','.join(['?']*(len(song_list_ftr)-1))})''', tuple(song_list_ftr)) - - x = self.c.fetchone() - if x[0] is not None: - score_sum += x[0] - - if len(song_list_byn) >= 2: - self.c.execute( - f'''select sum(score) from best_score where user_id=? and difficulty=3 and song_id in ({','.join(['?']*(len(song_list_byn)-1))})''', tuple(song_list_byn)) - - x = self.c.fetchone() - if x[0] is not None: - score_sum += x[0] - - self.c.execute('''update user set world_rank_score = :b where user_id = :a''', { - 'a': self.user_id, 'b': score_sum}) - - self.world_rank_score = score_sum + self.c.execute( + '''update user set world_rank_score = ? where user_id = ?''', (x[0], self.user_id)) + self.world_rank_score = x[0] def select_user_one_column(self, column_name: str, default_value=None) -> None: ''' diff --git a/latest version/server/func.py b/latest version/server/func.py index 6aa7534..65be2b0 100644 --- a/latest version/server/func.py +++ b/latest version/server/func.py @@ -110,7 +110,7 @@ def header_check(request) -> ArcError: if Config.ALLOW_APPVERSION: # 版本检查 if 'AppVersion' not in headers or headers['AppVersion'] not in Config.ALLOW_APPVERSION: return LowVersion('Invalid app version', 5) - if 'ContentBundle' in headers and headers['ContentBundle'] != BundleParser.max_bundle_version.get(headers.get('AppVersion', ''), '0.0.0'): + if request.method == 'GET' and 'ContentBundle' in headers and headers['ContentBundle'] != BundleParser.max_bundle_version.get(headers.get('AppVersion', ''), '0.0.0'): return LowVersion('Invalid content bundle version', 11) if has_arc_hash and not ArcHashChecker(request).check(): diff --git a/latest version/server/others.py b/latest version/server/others.py index f433d36..4f5f3fb 100644 --- a/latest version/server/others.py +++ b/latest version/server/others.py @@ -7,6 +7,7 @@ from werkzeug.datastructures import ImmutableMultiDict from core.bundle import BundleDownload from core.download import DownloadList from core.error import RateLimit +from core.item import ItemCharacter from core.sql import Connect from core.system import GameInfo from core.user import UserOnline @@ -14,7 +15,7 @@ from core.user import UserOnline from .auth import auth_required from .func import arc_try, error_return, success_return from .present import present_info -from .purchase import bundle_bundle, get_single, bundle_pack +from .purchase import bundle_bundle, bundle_pack, get_single from .score import song_score_friend from .user import user_me from .world import world_all @@ -65,15 +66,29 @@ def finale_progress(): @bp.route('/finale/finale_start', methods=['POST']) -def finale_start(): +@auth_required(request) +@arc_try +def finale_start(user_id): # testify开始,对立再见 - # 没数据 - return success_return({}) + # 但是对立不再见 + + with Connect() as c: + item = ItemCharacter(c) + item.set_id('55') # Hikari (Fatalis) + item.user_claim_item(UserOnline(c, user_id)) + return success_return({}) @bp.route('/finale/finale_end', methods=['POST']) -def finale_end(): - return success_return({}) +@auth_required(request) +@arc_try +def finale_end(user_id): + + with Connect() as c: + item = ItemCharacter(c) + item.set_id('5') # Hikari & Tairitsu (Reunion) + item.user_claim_item(UserOnline(c, user_id)) + return success_return({}) @bp.route('/applog/me/log', methods=['POST'])