hl query snippet
Posted by bunkahumpa
Thursday, March 18, 2004
Description: customizable HL server query
Here's a customizable Half-Life server query which takes a bunch of stuff out of the infostring query. Feel free to make changes to it as you wish!
The code above just echos the results to the active channel, if you know what you're doing you can change that. I know most people who are new to scripting or just want this on a bot or something in their channel would like an on text event for this so here you go:
If you just want the bot version, ignore the code above and copy all of this. FOLLOW THE DIRECTIONS IN THE CODE IF YOU WANT TO CUSTOMIZE IT!
Here's a customizable Half-Life server query which takes a bunch of stuff out of the infostring query. Feel free to make changes to it as you wish!
alias hlquery2 {
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; original author: bunkahumpa ;;
;; bh@scriptsurge.org ;;
;; irc.GameSurge.net #script ;;
;; usage: /hlquery2 IP PORT ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if ($sock(hlquery2)) {
sockclose hlquery2
}
sockudp -k hlquery2 $1 $2 $str($chr(255),4) $+ infostring
}
on *:udpread:hlquery2:{
sockread &hlquery2
breplace &hlquery2 0 160
breplace &hlquery2 32 160
var %hlquery2.return = $bvar(&hlquery2,1,$bvar(&hlquery2,0)).text
var %x = 1
while (%x <= $numtok(%hlquery2.return,92)) {
var %hlquery2.current = $gettok(%hlquery2.return,%x,92)
; this is where we grab all of the stuff from the return
if (protocol isin %hlquery2.current) {
var %hlquery2.protocol = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (gamedir isin %hlquery2.current) {
var %hlquery2.mod = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (address isin %hlquery2.current) {
var %hlquery2.ip = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (players isin %hlquery2.current) {
var %hlquery2.players = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (max isin %hlquery2.current) {
var %hlquery2.maxplayers = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (description isin %hlquery2.current) {
var %hlquery2.game = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (hostname isin %hlquery2.current) {
var %hlquery2.name = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (map isin %hlquery2.current) {
var %hlquery2.map = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (password isin %hlquery2.current) {
var %hlquery2.password = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (secure isin %hlquery2.current) {
var %hlquery2.secure = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (type isin %hlquery2.current) {
var %hlquery2.type = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (os isin %hlquery2.current) {
var %hlquery2.os = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
inc %x
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; now we format some of our retrieved data for a return ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if ((%hlquery2.game == Counter-Strike) || (%hlquery2.game == CounterStrike)) {
if (%hlquery2.protocol == 46) {
var %hlquery2.ver = 1.5
}
if (%hlquery2.protocol == 47) {
var %hlquery2.ver = 1.6
}
}
if (%hlquery2.password == 1) {
var %hlquery2.password = Yes
}
else {
var %hlquery2.password = No
}
if (%hlquery2.secure == 1) {
var %hlquery2.secure = Yes
}
else {
var %hlquery2.secure = No
}
if (%hlquery2.os == l) {
var %hlquery2.os = linux
}
if (%hlquery2.os == w) {
var %hlquery2.os = win32
}
if (%hlquery2.type == d) {
var %hlquery2.type = dedicated
}
if (%hlquery2.type == l) {
var %hlquery2.type = listen
}
var %hlquery2.players = %hlquery2.players $+ / $+ %hlquery2.maxplayers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; now we return which ones we want - the available ones are: ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; %hlquery2.game - returns the game name in its full format (like Counter-Strike) ;;
;; %hlquery2.mod - returns the game name in its short format (like cstrike) ;;
;; %hlquery2.ver - returns which version of CS it is (1.5/1.6 - only if it is CS) ;;
;; %hlquery2.ip - returns the server IP address ;;
;; %hlquery2.name - returns the server name ;;
;; %hlquery2.players - returns the players in the format of Players/Maxplayers (e.g. 0/16) ;;
;; %hlquery2.map - returns the name of the current map ;;
;; %hlquery2.password - returns Yes or No if it the server is password-protected (locked) ;;
;; %hlquery2.secure - returns Yes or No if Valve Anti-Cheat (VAC) is enabled on the server ;;
;; %hlquery2.type - returns the type of server, dedicated or listen ;;
;; %hlquery2.os - returns the operating system of the server, linux or win32 ;;
;; now we can return the information, feel free to edit this part as you wish ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
echo -a [^B]IP:[^B] %hlquery2.ip - [^B]Name[^B]: %hlquery2.name - [^B]Game[^B]: %hlquery2.game $iif(%hlquery2.ver,%hlquery2.ver) ( $+ %hlquery2.mod $+ ) - [^B]Map[^B]: %hlquery2.map - [^B]Players[^B]: %hlquery2.players - [^B]Locked?[^B] %hlquery2.password - [^B]VAC?[^B] %hlquery2.secure - [^B]Type[^B]: %hlquery2.type - [^B]Operating System[^B]: %hlquery2.os
; if the socket is still open, close it
if ($sock(hlquery2)) {
sockclose hlquery2
}
}
The code above just echos the results to the active channel, if you know what you're doing you can change that. I know most people who are new to scripting or just want this on a bot or something in their channel would like an on text event for this so here you go:
If you just want the bot version, ignore the code above and copy all of this. FOLLOW THE DIRECTIONS IN THE CODE IF YOU WANT TO CUSTOMIZE IT!
on *:text:@server:#channel:{
; change #channel to the channel you want it to work in
set %hlquery2.source $nick
; this will notice the nick, change $nick to $chan if you want to msg the chan
set %hlquery2.sourcetype nick
; and also change nick to chan if you want to msg the chan
hlquery2 IP PORT
; change this to the ip and port of the server
}
alias hlquery2 {
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; original author: bunkahumpa ;;
;; bh@scriptsurge.org ;;
;; irc.GameSurge.net #script ;;
;; usage: /hlquery2 IP PORT ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if ($sock(hlquery2)) {
sockclose hlquery2
}
sockudp -k hlquery2 $1 $2 $str($chr(255),4) $+ infostring
}
on *:udpread:hlquery2:{
sockread &hlquery2
breplace &hlquery2 0 160
breplace &hlquery2 32 160
var %hlquery2.return = $bvar(&hlquery2,1,$bvar(&hlquery2,0)).text
var %x = 1
while (%x <= $numtok(%hlquery2.return,92)) {
var %hlquery2.current = $gettok(%hlquery2.return,%x,92)
; this is where we grab all of the stuff from the return
if (protocol isin %hlquery2.current) {
var %hlquery2.protocol = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (gamedir isin %hlquery2.current) {
var %hlquery2.mod = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (address isin %hlquery2.current) {
var %hlquery2.ip = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (players isin %hlquery2.current) {
var %hlquery2.players = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (max isin %hlquery2.current) {
var %hlquery2.maxplayers = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (description isin %hlquery2.current) {
var %hlquery2.game = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (hostname isin %hlquery2.current) {
var %hlquery2.name = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (map isin %hlquery2.current) {
var %hlquery2.map = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (password isin %hlquery2.current) {
var %hlquery2.password = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (secure isin %hlquery2.current) {
var %hlquery2.secure = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (type isin %hlquery2.current) {
var %hlquery2.type = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
if (os isin %hlquery2.current) {
var %hlquery2.os = $gettok(%hlquery2.return,$calc(%x + 1),92)
}
inc %x
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; now we format some of our retrieved data for a return ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if ((%hlquery2.game == Counter-Strike) || (%hlquery2.game == CounterStrike)) {
if (%hlquery2.protocol == 46) {
var %hlquery2.ver = 1.5
}
if (%hlquery2.protocol == 47) {
var %hlquery2.ver = 1.6
}
}
if (%hlquery2.password == 1) {
var %hlquery2.password = Yes
}
else {
var %hlquery2.password = No
}
if (%hlquery2.secure == 1) {
var %hlquery2.secure = Yes
}
else {
var %hlquery2.secure = No
}
if (%hlquery2.os == l) {
var %hlquery2.os = linux
}
if (%hlquery2.os == w) {
var %hlquery2.os = win32
}
if (%hlquery2.type == d) {
var %hlquery2.type = dedicated
}
if (%hlquery2.type == l) {
var %hlquery2.type = listen
}
var %hlquery2.players = %hlquery2.players $+ / $+ %hlquery2.maxplayers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; now we return which ones we want - the available ones are: ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; %hlquery2.game - returns the game name in its full format (like Counter-Strike) ;;
;; %hlquery2.mod - returns the game name in its short format (like cstrike) ;;
;; %hlquery2.ver - returns which version of CS it is (1.5/1.6 - only if it is CS) ;;
;; %hlquery2.ip - returns the server IP address ;;
;; %hlquery2.name - returns the server name ;;
;; %hlquery2.players - returns the players in the format of Players/Maxplayers (e.g. 0/16) ;;
;; %hlquery2.map - returns the name of the current map ;;
;; %hlquery2.password - returns Yes or No if it the server is password-protected (locked) ;;
;; %hlquery2.secure - returns Yes or No if Valve Anti-Cheat (VAC) is enabled on the server ;;
;; %hlquery2.type - returns the type of server, dedicated or listen ;;
;; %hlquery2.os - returns the operating system of the server, linux or win32 ;;
;; now we can return the information, feel free to edit this part as you wish ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; change this next line after the = sign to customize it
var %hlquery2.total = [^B]IP:[^B] %hlquery2.ip - [^B]Name[^B]: %hlquery2.name - [^B]Game[^B]: %hlquery2.game $iif(%hlquery2.ver,%hlquery2.ver) ( $+ %hlquery2.mod $+ ) - [^B]Map[^B]: %hlquery2.map - [^B]Players[^B]: %hlquery2.players - [^B]Locked?[^B] %hlquery2.password - [^B]VAC?[^B] %hlquery2.secure - [^B]Type[^B]: %hlquery2.type - [^B]Operating System[^B]: %hlquery2.os
if (%hlquery2.sourcetype == chan) {
msg %hlquery2.source %hlquery2.total
}
if (%hlquery2.sourcetype == nick) {
.notice %hlquery2.source %hlquery2.total
}
; if the socket is still open, close it
if ($sock(hlquery2)) {
sockclose hlquery2
}
unset %hlquery2.source*
}