Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created July 4, 2015 23:12
Show Gist options
  • Select an option

  • Save XMPPwocky/ed0c7f48a86d981932ec to your computer and use it in GitHub Desktop.

Select an option

Save XMPPwocky/ed0c7f48a86d981932ec to your computer and use it in GitHub Desktop.
import valve.source.a2s
import re
import valve.source.master_server
regex = re.compile(".*McKay.*")
msq = valve.source.master_server.MasterServerQuerier(timeout=1.0)
try:
for address in msq.find(region=[u"na"],
gamedir=u"tf",
empty="false",
full="false",
gametype=[u"valve"]):
try:
server = valve.source.a2s.ServerQuerier(address, 0.35)
players = server.get_players()
targets = [pl["name"] for pl in players["players"] if regex.match(pl["name"]) is not None]
if len(targets) > 0:
info = server.get_info()
print address
print targets
print info["server_name"]
except: continue
except valve.source.a2s.NoResponseError:
print "Master server request timed out!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment