Commit c948d20d authored by minus's avatar minus

fixed serverlist retrieval, added find_by_ip executable

parent 219ea049
#!/usr/bin/env python3
import re
import sys
from teeworlds import query_masters_serverlist, create_masters, EventSocket
e = EventSocket()
m = create_masters(e)
query_masters_serverlist(m)
e.run()
servers = []
ip_filter = re.compile("^" + sys.argv[1].replace(".", "\\."))
for master in m:
servers.extend(filter(lambda s: ip_filter.search(str(s.address)), master.serverlist))
servers.sort(key=lambda s: s.address)
for server in servers:
print("{address: <15} on {master}".format(address=str(server.address), master=server._master.name))
......@@ -37,6 +37,7 @@ class MasterServer(object):
packet_list_request = 10*b'\xff' + b'req2'
packet_list_response = 10*b'\xff' + b'lis2'
serveraddr_size = 18
max_servers_per_packet = 75
def __init__(self, address, data_cb):
self.address = address
......@@ -51,12 +52,14 @@ class MasterServer(object):
self.time_sent = time()
def response_received(self, data):
if len(data) <= len(self.packet_list_response) or not data.startswith(self.packet_list_response):
return True # that's not it, wait for more
if not data.startswith(self.packet_list_response):
return True # that's not our packet, wait for more
self.latency = time() - self.time_sent
L.debug("received list response from {} in {} seconds".format(self.address, self.latency))
self.data_cb(data[len(self.packet_list_response):])
return False
list_data = data[len(self.packet_list_response):]
self.data_cb(list_data)
if len(list_data) / self.serveraddr_size >= self.max_servers_per_packet:
return True # this is not the last packet
def __init__(self, socket, address, name=None, server_factory=None):
if server_factory:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment