4 # :title: Half-Life 2 plugin for rbot
\r
6 # Author:: Ole Christian Rynning <oc@rynning.no>
\r
7 # Copyright:: (C) 2006 Ole Christian Rynning
\r
10 # Simple Half-Life 2 (Source Engine) plugin to query online
\r
11 # servers to see if its online and kicking and how many users.
\r
13 # Added 2 seconds timeout to the response. And sockets are now
\r
19 class HL2Plugin < Plugin
\r
21 A2S_INFO = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00"
\r
25 def a2s_info(addr, port)
\r
26 socket = UDPSocket.new()
\r
27 socket.send(A2S_INFO, 0, addr, port.to_i)
\r
32 response = socket.recvfrom(1400,0)
\r
38 response ? response.first.unpack("iACZ*Z*Z*Z*sCCCaaCCZ*") : nil
\r
41 def help(plugin, topic="")
\r
42 "hl2 'server:port' => show basic information about the given server"
\r
46 addr, port = params[:conn_str].split(':')
\r
48 info = a2s_info(addr, port)
\r
50 m.reply "#{info[3]} is online with #{info[8]}/#{info[9]} players."
\r
52 m.reply "Couldn't connect to #{params[:conn_str]}"
\r
59 plugin = HL2Plugin.new
\r
60 plugin.map 'hl2 :conn_str'
\r