local socket = require("socket")
local port = "27910"
local host = "aq2.catchgamer.no"
local packet = "\255\255\255\255status\n"
local ip = assert(socket.dns.toip(host))
local udp = socket.udp()
udp:setpeername(ip, port)
local nsent, err = udp:send(packet)
local header, err = udp:receive()
local t = {players = {}}
header = header:sub(11) -- strip away the firstline
for key, var in header:gmatch'\\([^\\]+)\\([^\\\n]+)' do
t[key] = var
end
for frag, ping, player in header:gmatch'(%d+) (%d+) "(.-)"\n' do
table.insert(t.players, { player = player, frag = frag, ping = ping })
end
local output = string.format("%s, players: %s/%s, map: %s [%s]", t["hostname"], #t.players, t["maxclients"], t["mapname"], t["gamename"])
print(output)
Prints out:
23:17:14 steino@kimiko work $ time lua q2.lua
Catch-Gamer.no AQ2 #1 Teamplay, players: 7/16, map: urban3 [action]
real 0m0.078s
user 0m0.000s
sys 0m0.010s
Requires Luasocket.
Made by Me and haste.
You can basicly make this work with any kind of game out there aslong as you know what packet to send. Qstat is a nice place to look for info on other types of games (hf reading that source :—D)