Commit 3921a9e8 authored by minus's avatar minus

enhanced find_by_ip.py

parent c948d20d
......@@ -2,20 +2,29 @@
import re
import sys
from teeworlds import query_masters_serverlist, create_masters, EventSocket
from teeworlds import query_masters_serverlist, create_masters, EventSocket, MasterServer
ip_filter = re.compile("^" + sys.argv[1].replace(".", "\\."))
class FilteringMaster(MasterServer):
def on_server_add(self, server):
if ip_filter.search(str(server.address)):
server.request_info()
e = EventSocket()
m = create_masters(e)
m = create_masters(e, master_factory=FilteringMaster)
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.extend(filter(lambda s: s.name is not None, 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))
print("{address: <15} on {master}: {server.name} "
"({server.num_players: <2}/{server.max_players: <2})"
.format(address=str(server.address), master=server._master.name, server=server)
)
......@@ -53,7 +53,7 @@ class Server(object):
self.latency = None
self.playerlist = []
self.version = None
self.name = str(self.address)
self.name = None
self.map = None
self.gametype = None
self.password = None
......
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