Deprecated: Function set_magic_quotes_runtime() is deprecated in /customers/stein-ivar.net/stein-ivar.net/httpd.www/textpattern/lib/txplib_db.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at /customers/stein-ivar.net/stein-ivar.net/httpd.www/textpattern/lib/txplib_db.php:14) in /customers/stein-ivar.net/stein-ivar.net/httpd.www/textpattern/lib/txplib_misc.php on line 1625

Warning: Cannot modify header information - headers already sent by (output started at /customers/stein-ivar.net/stein-ivar.net/httpd.www/textpattern/lib/txplib_db.php:14) in /customers/stein-ivar.net/stein-ivar.net/httpd.www/textpattern/publish.php on line 477
Quake2 ServerQuery in lua. — stein-ivar.net - hatin' php since 2002.

Quake2 ServerQuery in lua. · Jul 8, 07:22


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)


Permanent Link


Name

E-mail

http://

Message

 

Textile Help