Skip to content

Commit

Permalink
FIX: Rewrite getting players and rules to support old servers
Browse files Browse the repository at this point in the history
  • Loading branch information
kiriharu committed Aug 4, 2024
1 parent 203912a commit f2a614f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions rei/checkers/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,37 @@ def __init__(self, target: str, port: int):
self.address = (self.target, self.port)

async def check(self) -> Union[Response[Error], Response[SourceServerResponse]]:

try:
info: a2s.SourceInfo = await a2s.ainfo(self.address)
except a2s.BrokenMessageError:
return send_error("Сервер вернул несериализуемый ответ")
except socket.gaierror:
return send_error("Неправильный или несуществующий адрес")
except asyncio.TimeoutError:
return send_error("Таймаут")

try:
players = [
SourceServerPlayer(
name=player.name,
duration=player.duration,
score=player.score
) for player in await a2s.aplayers(self.address)
]
except (socket.gaierror, asyncio.TimeoutError, a2s.BrokenMessageError):
players = []

try:
rules = await a2s.arules(self.address)
except a2s.BrokenMessageError:
return send_error("Сервер вернул несериализуемый ответ")
except socket.gaierror:
return send_error("Неправильный или несуществующий адрес")
except asyncio.TimeoutError:
return send_error("Таймаут")
else:
return Response[SourceServerResponse](
status=ResponseStatus.OK,
payload=SourceServerResponse(
ping=info.ping
),
details=SourceServerDetails(
**dict(info), players=players, rules=rules
)
except (socket.gaierror, asyncio.TimeoutError, a2s.BrokenMessageError):
rules = {}

return Response[SourceServerResponse](
status=ResponseStatus.OK,
payload=SourceServerResponse(
ping=info.ping
),
details=SourceServerDetails(
**dict(info), players=players, rules=rules
)
)

0 comments on commit f2a614f

Please sign in to comment.