diff --git a/core/huya/wss_client.py b/core/huya/wss_client.py index 7b91b86..8fb9a6f 100644 --- a/core/huya/wss_client.py +++ b/core/huya/wss_client.py @@ -163,6 +163,19 @@ class HuyaWssClient: + HuyaWssClient._make_big_tail() ) + @staticmethod + def _encode_activity_launch_body(wup_data: bytes) -> bytes: + """活动 wsLaunch 使用浏览器的固定大包头,即使包体小于 255B。""" + if len(wup_data) < 4: + return wup_data + TAIL_BYTES + packet_len = len(wup_data) + return ( + bytes([packet_len & 0xFF]) + + packet_len.to_bytes(4, "big") + + wup_data[4:] + + TAIL_BYTES + ) + @staticmethod def _normalize_biz_cookie(cookie: str) -> str: """业务 RPC 的 huya_ua Cookie 值按浏览器 WSS 抓包修正""" @@ -398,7 +411,7 @@ class HuyaWssClient: wup.setRequestId(-1) wup.iTimeout = 0 wup.newdata["tReq"] = os.get_bytes() - body = self._encode_rpc_body(wup.encode()) + body = self._encode_activity_launch_body(wup.encode()) msg = WssMessage(WssCommand.RPC_REQUEST, SEQ_ACTIVITY_WSLAUNCH, body) future = asyncio.Future() self.rpc_queue.append(future)