serverstf / python-valve

A Python Interface to various Valve products and services
Other
236 stars 71 forks source link

valve.source.messages.BufferExhaustedError: No string terminator #72

Closed Terkodai closed 5 years ago

Terkodai commented 5 years ago

Hi guys, I try to get data from the Atlas server (www.playatlas.com). Their map are divided in node and each node is a server with an ip address and a port (3 port for 1 address). I got an error message when I try to get the players present on a server when they are more than 80-90 players.

Traceback (most recent call last):
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 285, in decode
    entry = self.element.decode(buffer)
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 423, in decode
    values[field.name], buffer = field.decode(buffer, values)
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 41, in needs_buffer
    return func(self, buffer, *args, **kwargs)
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 152, in decode
    raise BufferExhaustedError("No string terminator")
valve.source.messages.BufferExhaustedError: No string terminator

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/a2s.py", line 200, in players
    return messages.PlayersResponse.decode(self.get_response())
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 423, in decode
    values[field.name], buffer = field.decode(buffer, values)
  File "/opt/mysite/venv/lib/python3.6/site-packages/valve/source/messages.py", line 295, in decode
    raise BrokenMessageError(exc)
valve.source.messages.BrokenMessageError: No string terminator

I don't understand why my code does not work, I see some tracker for Atlas on the net that does not have the same problem as me and get the data (https://atlas.hgn.hu/ for example)

To test the problem here a little snippet :

with a2s.ServerQuerier(('server_addr', port)) as s:
    print(s.players())

All EU PvP server list and prot are in the attached file, it's a json format, you can see on https://atlas.hgn.hu/grid/eu/pvp for a node with 90+ player and try it yourself with the corresponding address and port ni the attached file.

eu_pvp_server_dict.txt

Feel free to ask me anything if you need more informations or if I missed something.

Nothing4You commented 5 years ago

I'm having a similar issue with rust, it used to work against this server, might be related to player count or nicks on the server now though:

Traceback (most recent call last):
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 280, in decode
    entry = self.element.decode(buffer)
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 416, in decode
    values[field.name], buffer = field.decode(buffer, values)
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 41, in needs_buffer
    return func(self, buffer, *args, **kwargs)
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 126, in decode
    raise BufferExhaustedError
valve.source.messages.BufferExhaustedError: Incomplete message

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "servercheck.py", line 44, in <module>
    main()
  File "servercheck.py", line 15, in main
    check.poll()
  File "/Users/me/dev/project/mylib/servercheck.py", line 14, in poll
    self.last_players = self.get_player_list()
  File "/Users/me/dev/project/mylib/servercheck.py", line 74, in get_player_list
    players = server.players()
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/a2s.py", line 200, in players
    return messages.PlayersResponse.decode(self.get_response())
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 416, in decode
    values[field.name], buffer = field.decode(buffer, values)
  File "/Users/me/.local/share/virtualenvs/project-aIC__YKN/lib/python3.7/site-packages/valve/source/messages.py", line 288, in decode
    raise BrokenMessageError(exc)
valve.source.messages.BrokenMessageError: Incomplete message

Sometimes this shows as Incomplete message, sometimes I'm getting No string terminator.

Essentially

with valve.source.a2s.ServerQuerier(self.target) as server:
    players = server.players(("5.1.81.57", 28015))
Yepoleb commented 5 years ago

Does the byteio branch work for you? The API is slightly different because all Source query classes have been moved to the valve.source namespace, but the basic functions have remained the same, so it should be really easy to adapt.

Nothing4You commented 5 years ago

@Yepoleb same issue there:

import valve.source.a2s

target = "185.107.96.22:28080"

target = target.split(":")
target[1] = int(target[1])

with valve.source.a2s.ServerQuerier(target) as server:
    server.players()
Traceback (most recent call last):
  File "issue.py", line 9, in <module>
    server.players()
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/a2s.py", line 202, in players
    return messages.PlayersResponse.decode(resp)
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/messages.py", line 34, in decode
    instance.read(stream)
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/messages.py", line 211, in read
    player.read(stream)
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/messages.py", line 194, in read
    self.name = reader.read_cstring()
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/byteio.py", line 83, in read_cstring
    c = self.read(charsize)
  File "/Users/me/.local/share/virtualenvs/valve-python-issue-72-kDh6esd3/lib/python3.7/site-packages/valve/source/byteio.py", line 20, in read
    raise BufferExhaustedError()
valve.source.util.BufferExhaustedError: Incomplete message

It may or may not work against this server when you test it, usually after testing a few from this list I can find one that errors: http://playrust.io/#type:vanilla%20players:50-250 (when you visit the server page it'll show ip/port).

Yepoleb commented 5 years ago

Sorry, forgot to comment on this after testing. It indeed seems like a bug on our side, probably due to the high player count.

Yepoleb commented 5 years ago

Seems to have been related to #71, should be fixed now.