Yepoleb / python-a2s

A2S Query API for Python
MIT License
154 stars 17 forks source link

a2s.rules doesn't work for goldsrc servers #26

Open SergeyShorokhov opened 3 years ago

SergeyShorokhov commented 3 years ago
import a2s

address = ("51.38.60.53", 27015)
print(a2s.info(address), "\n===================")
print(a2s.players(address), "\n===================")
print(a2s.rules(address), "\n===================")
❯ python3 test.py
GoldSrcInfo(address='51.38.60.53:27015', server_name='Emirates-KiNGS 亗 ||͇̿P͇̿U͇̿B͇̿L͇̿I͇̿C͇̿| ✪', map_name='de_dust2', folder='cstrike', game='Counter-Strike', player_count=32, max_players=32, protocol=47, server_type='d', platform='l', password_protected=False, is_mod=False, vac_enabled=True, bot_count=0, mod_website=None, mod_download=None, mod_version=None, mod_size=None, multiplayer_only=False, uses_hl_dll=True, ping=0.078310297) 
===================
[Player(index=0, name='0000000', score=3, duration=713.0708618164062), Player(index=1, name='CaNaPu5', score=20, duration=10951.25390625), Player(index=2, name='man', score=0, duration=3180.58349609375), Player(index=3, name='Naxo', score=2, duration=4307.5185546875), Player(index=4, name='ALAAAALA', score=31, duration=6036.9609375), Player(index=5, name='hoktri_spn', score=3, duration=828.8158569335938), Player(index=6, name='BENZEMA', score=37, duration=3634.5341796875), Player(index=7, name='Free World', score=22, duration=767.990966796875), Player(index=8, name='ﺭﻮﺴﻴﻓﻭﺮﺒﻟﺍ', score=1, duration=2330.75146484375), Player(index=9, name='[+]N0.$moK!ng[+]', score=0, duration=28.972854614257812), Player(index=10, name="lemon'haze", score=0, duration=983.9241943359375), Player(index=11, name='TheKiller', score=1, duration=1530.94287109375), Player(index=12, name='[S]KY', score=5, duration=1246.8905029296875), Player(index=13, name='FreeWillAboveAll ! _ celT1c^', score=62, duration=4017.47314453125), Player(index=14, name='pro,,man', score=31, duration=3365.847412109375), Player(index=15, name='misko pasaka', score=10, duration=1125.6868896484375), Player(index=16, name="-TatLA'", score=0, duration=26.366531372070312), Player(index=17, name='BABAK', score=32, duration=13625.2490234375), Player(index=18, name='Ali-G ((:', score=39, duration=2772.572509765625), Player(index=19, name='<3    NaSHmI   <3', score=43, duration=10373.259765625), Player(index=20, name='self.less', score=15, duration=1443.3994140625), Player(index=21, name='nomind', score=25, duration=4056.402587890625), Player(index=22, name='m@x1n3', score=13, duration=1183.256591796875), Player(index=23, name='QaFF', score=10, duration=1370.1153564453125), Player(index=24, name='OTTOMAN_cCc', score=18, duration=1803.26123046875), Player(index=25, name='CoMyNoMeRcY', score=20, duration=10086.8076171875), Player(index=26, name='GoaT', score=15, duration=1718.1759033203125), Player(index=27, name='Cigani ludaci!', score=14, duration=2449.064453125), Player(index=28, name='driloun', score=19, duration=9504.6044921875), Player(index=29, name='kappa', score=6, duration=817.0953369140625), Player(index=30, name='Dweezil', score=0, duration=18447.14453125), Player(index=31, name='usp', score=0, duration=1330.7908935546875)] 
===================
Traceback (most recent call last):
  File "/Users/sergejsorohov/Documents/trash/A2S_INFO-checker/src/test.py", line 7, in <module>
    print(a2s.rules(address), "\n===================")
  File "/usr/local/lib/python3.9/site-packages/a2s/rules.py", line 15, in rules
    return request_sync(address, timeout, encoding, RulesProtocol)
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 22, in request_sync
    response = request_sync_impl(conn, encoding, a2s_proto)
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 43, in request_sync_impl
    return request_sync_impl(
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 47, in request_sync_impl
    raise BrokenMessageError(
a2s.exceptions.BrokenMessageError: Invalid response type: 0x6d

Why rules not work?

Invalid response type: 0x6d or

Traceback (most recent call last):
  File "/Users/sergejsorohov/Documents/trash/A2S_INFO-checker/src/test.py", line 7, in <module>
    print(a2s.rules(address), "\n===================")
  File "/usr/local/lib/python3.9/site-packages/a2s/rules.py", line 15, in rules
    return request_sync(address, timeout, encoding, RulesProtocol)
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 22, in request_sync
    response = request_sync_impl(conn, encoding, a2s_proto)
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 43, in request_sync_impl
    return request_sync_impl(
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 28, in request_sync_impl
    resp_data = conn.request(a2s_proto.serialize_request(challenge))
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 92, in request
    return self.recv()
  File "/usr/local/lib/python3.9/site-packages/a2s/a2s_sync.py", line 76, in recv
    packet = self._socket.recv(4096)
socket.timeout: timed out

When i increase timeout - server not respond.

But all data from rules has been succefully parsed by every 3rd service https://www.gametracker.com/server_info/51.38.60.53:27015/server_variables/

Yepoleb commented 3 years ago

I looked into this and found out the server uses the Goldsource multipacket format, which is not currently implemented. It's also impossible to detect on a per server basis just from the response, so supporting it would require a major API change. I consider this a valid bug, but I don't know if or when I will fix it because it's such a big change.