find_by_ip.py 1.21 KB
Newer Older
1 2
#!/usr/bin/env python2

m!nus's avatar
m!nus committed
3 4 5

import sys

6 7 8
from teeworlds.teeworlds import Teeworlds


m!nus's avatar
m!nus committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
# set up stuff
tw = Teeworlds(timeout=2)

# ask the masters for servers
tw.query_masters()

# query servers, wait for responses
# stops if no packet is received for `timeout` seconds
tw.run_loop()

# filter the serverlist
ip_filter = "^"+sys.argv[1].replace(".", "\\.")
servers = tw.serverlist.find(address=ip_filter)

# sort by ping
servers.sort(key=lambda s: s.address)

# display a nice list
for server in servers:
        print("{server: <64} {address: <15} [{gametype: ^16}] on {master}: {clients: >2}/{max_clients: <2} - {latency: >4.0f} ms" \
        .format(server=server.name, address=server.address, gametype=server.gametype, master=server.master.name, clients=server.clients, \
                max_clients=server.max_clients, latency=server.latency*1000))

# check if m!nus is currently playing
#minus_list = tw.playerlist.find(name="^m!nus$")
#if minus_list.players:
#	minus = minus_list.players[0]
#	print("m!nus is currently playing on {server} ({address}) with {players} other player(s)."
#		.format(server=minus.server.name, address=minus.server.address, players=(minus.server.players-1)))
#else:
#	print("m!nus isn't playing at the moment.")