|
1 | 1 | import asyncio |
2 | 2 | import contextlib |
3 | | -import socket |
4 | 3 | from copy import deepcopy |
5 | 4 | from pathlib import Path |
6 | 5 | from typing import Any, Dict, List, Literal, Optional, Tuple, Union, cast |
@@ -70,11 +69,7 @@ async def a2s_server_info( |
70 | 69 | encoding="utf8", |
71 | 70 | ) |
72 | 71 |
|
73 | | - except ( |
74 | | - asyncio.exceptions.TimeoutError, |
75 | | - ConnectionRefusedError, |
76 | | - socket.gaierror, |
77 | | - ): |
| 72 | + except Exception: |
78 | 73 | server = a2s.SourceInfo( |
79 | 74 | protocol=0, |
80 | 75 | server_name="服务器无响应", |
@@ -124,7 +119,7 @@ async def a2s_info( |
124 | 119 |
|
125 | 120 | try: |
126 | 121 | results = await asyncio.gather(*tasks) |
127 | | - msg_list = [r for r in results if r is not None] |
| 122 | + msg_list = results # 不过滤 None,保持与输入列表相同的长度 |
128 | 123 | except Exception as e: |
129 | 124 | logger.error(f"获取服务器信息时发生错误: {e}") |
130 | 125 |
|
@@ -156,11 +151,7 @@ async def process_message( |
156 | 151 | ) |
157 | 152 | if server is not None: |
158 | 153 | server.steam_id = index # type: ignore |
159 | | - except ( |
160 | | - asyncio.exceptions.TimeoutError, |
161 | | - ConnectionRefusedError, |
162 | | - socket.gaierror, |
163 | | - ): |
| 154 | + except Exception: |
164 | 155 | server = a2s.SourceInfo( |
165 | 156 | protocol=0, |
166 | 157 | server_name="服务器无响应", |
@@ -204,11 +195,7 @@ async def process_message( |
204 | 195 | ) |
205 | 196 |
|
206 | 197 | if is_player: |
207 | | - with contextlib.suppress( |
208 | | - asyncio.exceptions.TimeoutError, |
209 | | - ConnectionRefusedError, |
210 | | - socket.gaierror, |
211 | | - ): |
| 198 | + with contextlib.suppress(Exception): |
212 | 199 | play = await a2s.aplayers(ip, timeout=3, encoding="utf8") |
213 | 200 | else: |
214 | 201 | play = [] |
|
0 commit comments