-#-- vim:sw=2:et\r
-#++\r
-#\r
-# :title: Half-Life 2 plugin for rbot\r
-#\r
-# Author:: Ole Christian Rynning <oc@rynning.no>\r
-# Copyright:: (C) 2006 Ole Christian Rynning\r
-# License:: GPL v2\r
-#\r
-# Simple Half-Life 2 (Source Engine) plugin to query online\r
-# servers to see if its online and kicking and how many users.\r
-#\r
-# Added 2 seconds timeout to the response. And sockets are now\r
-# closing properly.\r
-\r
-require 'socket'\r
-require 'timeout'\r
-\r
-class HL2Plugin < Plugin\r
-\r
- 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
-\r
- TIMEOUT = 2\r
-\r
- def a2s_info(addr, port)\r
- socket = UDPSocket.new()\r
- socket.send(A2S_INFO, 0, addr, port.to_i)\r
- response = nil\r
-\r
- begin\r
- timeout(TIMEOUT) do\r
- response = socket.recvfrom(1400,0)\r
- end\r
- rescue Exception\r
- end\r
-\r
- socket.close()\r
- response ? response.first.unpack("iACZ*Z*Z*Z*sCCCaaCCZ*") : nil\r
- end\r
-\r
- def help(plugin, topic="")\r
- "hl2 'server:port' => show basic information about the given server"\r
- end\r
-\r
- def hl2(m, params)\r
- addr, port = params[:conn_str].split(':')\r
- info = a2s_info(addr, port)\r
- if info != nil\r
- m.reply "#{info[3]} is online with #{info[8]}/#{info[9]} players."\r
- else\r
- m.reply "Couldn't connect to #{params[:conn_str]}"\r
- end\r
- end\r
-\r
-end\r
-\r
-plugin = HL2Plugin.new\r
-plugin.map 'hl2 :conn_str', :thread => true\r
-\r
+#-- vim:sw=2:et
+#++
+#
+# :title: Half-Life 2 plugin for rbot
+#
+# Author:: Ole Christian Rynning <oc@rynning.no>
+# Copyright:: (C) 2006 Ole Christian Rynning
+# License:: GPL v2
+#
+# Simple Half-Life 2 (Source Engine) plugin to query online
+# servers to see if its online and kicking and how many users.
+#
+# Added 2 seconds timeout to the response. And sockets are now
+# closing properly.
+
+require 'socket'
+require 'timeout'
+
+class HL2Plugin < Plugin
+
+ 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"
+
+ TIMEOUT = 2
+
+ def a2s_info(addr, port)
+ socket = UDPSocket.new()
+ begin
+ socket.send(A2S_INFO, 0, addr, port.to_i)
+ response = nil
+
+ timeout(TIMEOUT) do
+ response = socket.recvfrom(1400,0)
+ end
+ rescue Exception => e
+ error e
+ end
+
+ socket.close()
+ response ? response.first.unpack("iACZ*Z*Z*Z*sCCCaaCCZ*") : nil
+ end
+
+ def help(plugin, topic="")
+ "hl2 'server:port' => show basic information about the given server"
+ end
+
+ def hl2(m, params)
+ addr, port = params[:conn_str].split(':')
+ info = a2s_info(addr, port)
+ if info
+ m.reply "#{info[3]} is online with #{info[8]}/#{info[9]} players."
+ else
+ m.reply "Couldn't connect to #{params[:conn_str]}"
+ end
+ end
+
+end
+
+plugin = HL2Plugin.new
+plugin.map 'hl2 :conn_str', :thread => true
+