diff options
author | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-08-11 12:33:33 +0000 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2006-08-11 12:33:33 +0000 |
commit | ad4bb5bf4fce69f1848f8b717abbab849fc37805 (patch) | |
tree | 5ad540ac0d64c1660c7a8122774df60ebc13417c /data | |
parent | 98066bb754014b343dea272ebf6ec22babf9e8bf (diff) |
Actually commit the halflife2 plugin
Diffstat (limited to 'data')
-rw-r--r-- | data/rbot/plugins/hl2.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/data/rbot/plugins/hl2.rb b/data/rbot/plugins/hl2.rb new file mode 100644 index 00000000..e0623433 --- /dev/null +++ b/data/rbot/plugins/hl2.rb @@ -0,0 +1,55 @@ +# Plugin for the Ruby IRC bot (http://linuxbrit.co.uk/rbot/)
+#
+# 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.
+#
+# (c) 2006 Ole Christian Rynning <oc@rynning.no>
+# Licensed under GPL V2.
+
+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()
+ socket.send(A2S_INFO, 0, addr, port.to_i)
+ response = nil
+
+ begin
+ timeout(TIMEOUT) do
+ response = socket.recvfrom(1400,0)
+ end
+ rescue Exception
+ 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(':')
+ Thread.start do
+ info = a2s_info(addr, port)
+ if info != nil
+ 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
+
+end
+plugin = HL2Plugin.new
+plugin.map 'hl2 :conn_str'
+
|