Fix a bug and add a new thing

- Add support for logging Arcaea's errors
- Fix a bug when world maps' data don't have some unnecessary parts the client of iOS may break down
This commit is contained in:
Lost-MSth
2022-07-16 19:50:07 +08:00
parent 6801af197f
commit 47f05cdf1e
23 changed files with 549 additions and 613 deletions

View File

@@ -177,10 +177,12 @@ class UserCharacter(Character):
x = self.c.fetchone()
if not x:
raise NoData('The character of the user does not exist.')
self.is_uncapped = x[0] == 1
self.is_uncapped_override = x[1] == 1
self.is_uncapped = False
self.is_uncapped_override = False
# raise NoData('The character of the user does not exist.')
else:
self.is_uncapped = x[0] == 1
self.is_uncapped_override = x[1] == 1
def select_character_info(self, user=None):
# parameter: user - User类或子类的实例

View File

@@ -1,9 +1,10 @@
class ArcError(Exception):
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None) -> None:
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None, status=200) -> None:
self.message = message
self.error_code = error_code
self.api_error_code = api_error_code
self.extra_data = extra_data
self.status = status
def __str__(self) -> str:
return repr(self.message)
@@ -11,8 +12,8 @@ class ArcError(Exception):
class InputError(ArcError):
# 输入类型错误
def __init__(self, message=None, error_code=108, api_error_code=-100, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=108, api_error_code=-100, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class DataExist(ArcError):
@@ -22,62 +23,62 @@ class DataExist(ArcError):
class NoData(ArcError):
# 数据不存在
def __init__(self, message=None, error_code=108, api_error_code=-2, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=108, api_error_code=-2, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class PostError(ArcError):
# 缺少输入
def __init__(self, message=None, error_code=108, api_error_code=-100, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=108, api_error_code=-100, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class UserBan(ArcError):
# 用户封禁
def __init__(self, message=None, error_code=121, api_error_code=-202, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=121, api_error_code=-202, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class ItemNotEnough(ArcError):
# 物品数量不足
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class ItemUnavailable(ArcError):
# 物品不可用
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class RedeemUnavailable(ArcError):
# 兑换码不可用
def __init__(self, message=None, error_code=505, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=505, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class MapLocked(ArcError):
# 地图锁定
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class StaminaNotEnough(ArcError):
# 体力不足
def __init__(self, message=None, error_code=107, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=107, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class TicketNotEnough(ArcError):
# 记忆源点不足
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=-6, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class FriendError(ArcError):
# 好友系统出错
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None) -> None:
super().__init__(message, error_code, api_error_code, extra_data)
def __init__(self, message=None, error_code=108, api_error_code=-999, extra_data=None, status=200) -> None:
super().__init__(message, error_code, api_error_code, extra_data, status)
class NoAccess(ArcError):

View File

@@ -98,10 +98,11 @@ class LocalMultiPlayer:
if self.conn.poll(Constant.LINK_PLAY_TIMEOUT):
self.data_recv = self.conn.recv()
if self.data_recv[0] != 0:
raise ArcError('Link Play error.', self.data_recv[0])
raise ArcError('Link Play error.',
self.data_recv[0], status=400)
else:
raise Timeout(
'Timeout when waiting for data from local udp server.')
'Timeout when waiting for data from local udp server.', status=400)
def create_room(self, user: 'Player' = None) -> None:
'''创建房间'''

View File

@@ -4,7 +4,7 @@ import traceback
from flask import current_app
from .constant import Constant
from .error import InputError
from .error import ArcError, InputError
class Connect:
@@ -24,18 +24,22 @@ class Connect:
return self.c
def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
flag = True
if exc_type is not None:
if self.conn:
self.conn.rollback()
if issubclass(exc_type, ArcError):
flag = False
else:
if self.conn:
self.conn.rollback()
current_app.logger.error(
traceback.format_exception(exc_type, exc_val, exc_tb))
current_app.logger.error(
traceback.format_exception(exc_type, exc_val, exc_tb))
if self.conn:
self.conn.commit()
self.conn.close()
return True
return flag
class Query:

View File

@@ -450,6 +450,10 @@ class UserInfo(User):
favorite_character_id = self.favorite_character.character_id
else:
favorite_character_id = -1
if self.character.character_id not in character_list:
self.character.character_id = 0
return {
"is_aprilfools": Config.IS_APRILFOOLS,
"curr_available_maps": self.curr_available_maps_list,
@@ -477,7 +481,7 @@ class UserInfo(User):
"world_songs": self.world_songs,
"singles": self.singles,
"packs": self.packs,
"characters": self.characters_list,
"characters": character_list,
"cores": self.cores,
"recent_score": self.recent_score_list,
"max_friend": Constant.MAX_FRIEND_COUNT,

View File

@@ -158,17 +158,17 @@ class Map:
self.is_legacy = raw_dict.get('is_legacy')
self.is_beyond = raw_dict.get('is_beyond')
self.beyond_health = raw_dict.get('beyond_health')
self.character_affinity = raw_dict.get('character_affinity')
self.affinity_multiplier = raw_dict.get('affinity_multiplier')
self.character_affinity = raw_dict.get('character_affinity', [])
self.affinity_multiplier = raw_dict.get('affinity_multiplier', [])
self.chapter = raw_dict.get('chapter')
self.available_from = raw_dict.get('available_from')
self.available_to = raw_dict.get('available_to')
self.available_from = raw_dict.get('available_from', -1)
self.available_to = raw_dict.get('available_to', 9999999999999)
self.is_repeatable = raw_dict.get('is_repeatable')
self.require_id = raw_dict.get('require_id')
self.require_type = raw_dict.get('require_type')
self.require_value = raw_dict.get('require_value')
self.require_id = raw_dict.get('require_id', '')
self.require_type = raw_dict.get('require_type', '')
self.require_value = raw_dict.get('require_value', 1)
self.coordinate = raw_dict.get('coordinate')
self.custom_bg = raw_dict.get('custom_bg')
self.custom_bg = raw_dict.get('custom_bg', '')
self.stamina_cost = raw_dict.get('stamina_cost')
self.steps = [Step().from_dict(s) for s in raw_dict.get('steps')]
return self