w-gao / py-mcpe-stats

A tool to get basic information from Minecraft: Bedrock Edition servers.
MIT License
16 stars 5 forks source link

IndexError: list index out of range #3

Closed ghost closed 3 years ago

ghost commented 5 years ago
nathfreder@Nathaniels-MacBook-Pro py-mcpe-stats % python main.py play.nethergames.org 19132
Traceback (most recent call last):
  File "main.py", line 15, in <module>
    server_data = q.query()
  File "/Users/nathfreder/Coding/py-mcpe-stats/py_mcpe_stats/query.py", line 78, in query
    server_data.MOTD = info[7]
IndexError: list index out of range
w-gao commented 5 years ago

Hey, thanks for the feedback!

py_mcpe_stats/query.py#L70

                if len(info) >= 6:
                    server_data.GAME_ID = info[0]
                    server_data.SERVER_NAME = info[1]
                    server_data.GAME_PROTOCOL = int(info[2])
                    server_data.GAME_VERSION = info[3]
                    server_data.NUM_PLAYERS = int(info[4])
                    server_data.MAX_PLAYERS = int(info[5])

                if len(info) >= 7:
                    server_data.HASH_CODE = info[6]

                if len(info) >= 9:
                    server_data.MOTD = info[7]
                    server_data.GAMEMODE = info[8]

(https://gist.github.com/w-gao/a2df002c5bad0e51c3fc1906ac41f0b7)

This should work for most servers, but there definitely should be some kind of error handling when parsing the data sent from the server.

Do you mind creating a PR or do you want me to push a fix? :)

w-gao commented 3 years ago

This should be fixed. Please reopen if this still happens.