Dinnerbone / mcstatus

A Python class for checking the status of an enabled Minecraft server
http://dinnerbone.com/minecraft/tools/status/
1.11k stars 146 forks source link

Ports > 32767 do not work #23

Closed ctian1 closed 5 years ago

ctian1 commented 9 years ago

If the port used to connect to/lookup a server is not less than or equal to 32767, mcstatus will error.

Traceback:

----> 1 test.status()

C:\Python34\lib\site-packages\mcstatus\server.py in status(self, retries, **kwargs)
     61                 exception = e
     62                 attempt += 1
---> 63         raise exception
     64
     65     def query(self, retries=3):

C:\Python34\lib\site-packages\mcstatus\server.py in status(self, retries, **kwargs)
     54             try:
     55                 pinger = ServerPinger(connection, host=self.host, port=self.port, **kwargs)
---> 56                 pinger.handshake()
     57                 result = pinger.read_status()
     58                 result.latency = pinger.test_ping()

C:\Python34\lib\site-packages\mcstatus\pinger.py in handshake(self)
     22         packet.write_varint(self.version)
     23         packet.write_utf(self.host)
---> 24         packet.write_short(self.port)
     25         packet.write_varint(1)  # Intention to query status
     26

C:\Python34\lib\site-packages\mcstatus\protocol\connection.py in write_short(self, value)
     80
     81     def write_short(self, value):
---> 82         self.write(self._pack("h", value))
     83
     84     def read_ushort(self):

C:\Python34\lib\site-packages\mcstatus\protocol\connection.py in _pack(self, format, data)
     37
     38     def _pack(self, format, data):
---> 39         return struct.pack(">" + format, data)
     40
     41     def read_varint(self):

error: 'h' format requires -32768 <= number <= 32767
winny- commented 9 years ago

Looks like the port in handshake should be an unsigned short (H in python.struct's functions).

http://wiki.vg/Server_List_Ping#1.7

kevinkjt2000 commented 5 years ago

Fixed in #29