mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-26 12:50:33 +08:00
抓一下刷请求的人
This commit is contained in:
parent
7a0423699c
commit
d5cd7f9f7e
@ -33,6 +33,8 @@ END_GAME_COMMON_SERVER_URL = COMMON_SERVER_BASE_URL + '/api/internal/open_live/e
|
||||
GAME_HEARTBEAT_COMMON_SERVER_URL = COMMON_SERVER_BASE_URL + '/api/internal/open_live/game_heartbeat'
|
||||
|
||||
_error_auth_code_cache = cachetools.LRUCache(256)
|
||||
# 应B站要求,抓一下刷请求的人,不会用于其他用途
|
||||
auth_code_room_id_cache = cachetools.LRUCache(256)
|
||||
# 用于限制请求开放平台的频率
|
||||
_open_live_rate_limiter = utils.rate_limit.TokenBucket(8, 8)
|
||||
|
||||
@ -210,14 +212,18 @@ class _StartGameMixin(_OpenLiveHandlerBase):
|
||||
if self.res is None:
|
||||
return
|
||||
|
||||
auth_code = self.json_args.get('code', None)
|
||||
try:
|
||||
room_id = self.res['data']['anchor_info']['room_id']
|
||||
except (TypeError, KeyError):
|
||||
room_id = None
|
||||
room_id = auth_code_room_id_cache.get(auth_code, None)
|
||||
else:
|
||||
auth_code_room_id_cache[auth_code] = room_id
|
||||
try:
|
||||
game_id = self.res['data']['game_info']['game_id']
|
||||
except (TypeError, KeyError):
|
||||
game_id = None
|
||||
|
||||
code = self.res['code']
|
||||
logger.info(
|
||||
'client=%s room_id=%s start game res: %s %s, game_id=%s', self.request.remote_ip, room_id,
|
||||
@ -226,10 +232,7 @@ class _StartGameMixin(_OpenLiveHandlerBase):
|
||||
if code == 7007:
|
||||
# 身份码错误
|
||||
# 让我看看是哪个混蛋把房间ID、UID当做身份码
|
||||
logger.info(
|
||||
'client=%s auth code error! auth_code=%s', self.request.remote_ip,
|
||||
self.json_args.get('code', None)
|
||||
)
|
||||
logger.info('client=%s auth code error! auth_code=%s', self.request.remote_ip, auth_code)
|
||||
|
||||
|
||||
class StartGamePublicHandler(_StartGameMixin, _PublicHandlerBase):
|
||||
|
@ -266,7 +266,10 @@ class OpenLiveClient(blivedm.OpenLiveClient):
|
||||
logger.error('_start_game() failed')
|
||||
return False
|
||||
except api_open_live.BusinessError as e:
|
||||
logger.warning('_start_game() failed')
|
||||
logger.warning(
|
||||
'_start_game() failed, room_id=%s',
|
||||
api_open_live.auth_code_room_id_cache.get(self._room_owner_auth_code, None)
|
||||
)
|
||||
|
||||
if e.code == 7007:
|
||||
# 身份码错误
|
||||
@ -288,7 +291,11 @@ class OpenLiveClient(blivedm.OpenLiveClient):
|
||||
})
|
||||
|
||||
return False
|
||||
return self._parse_start_game(data['data'])
|
||||
|
||||
res = self._parse_start_game(data['data'])
|
||||
if res:
|
||||
api_open_live.auth_code_room_id_cache[self._room_owner_auth_code] = self.room_id
|
||||
return res
|
||||
|
||||
async def _end_game(self):
|
||||
if self._game_id in (None, ''):
|
||||
|
Loading…
Reference in New Issue
Block a user