fixed so it handles multiple packets from the masters

This commit is contained in:
Magnus Auvinen 2008-11-16 14:01:40 +00:00
parent e27e2d8b2a
commit 42553448f7

View file

@ -62,17 +62,23 @@ def get_servers(address):
sock.settimeout(1.5)
sock.sendto("\x20\x00\x00\x00\x00\x00\xff\xff\xff\xffreqt", (address, master_port))
while 1:
data, addr = sock.recvfrom(1024)
sock.close()
data = data[14:]
num_servers = len(data) / 6
num_players = 0
for n in range(0, num_servers):
ip = ".".join(map(str, map(ord, data[n*6:n*6+4])))
port = ord(data[n*6+5]) * 256 + ord(data[n*6+4])
servers += [[ip, port]]
# and we are done
if num_servers < 128:
break
sock.close()
return servers
except:
return None