diff --git a/scripts/tw_api.py b/scripts/tw_api.py index 6ef0cc6a6..8077e3ee1 100644 --- a/scripts/tw_api.py +++ b/scripts/tw_api.py @@ -61,17 +61,23 @@ def get_servers(address): sock = socket(AF_INET, SOCK_DGRAM) sock.settimeout(1.5) sock.sendto("\x20\x00\x00\x00\x00\x00\xff\xff\xff\xffreqt", (address, master_port)) - - data, addr = sock.recvfrom(1024) - sock.close() - data = data[14:] - num_servers = len(data) / 6 - num_players = 0 + + while 1: + data, addr = sock.recvfrom(1024) + + data = data[14:] + num_servers = len(data) / 6 - 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]] + 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: