;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PINGEXEC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;info: ; ; by wiebe @ QuakeNet ; version 1.0 (written and tested on mIRC 6.14) ; ; ; last edit: Sat Mar 27 2004 ; ; ;What does this script do? ; ; pings the server, another server or a nick and returns the delay to an alias ; ; ;How to use this script? ; ; /pingexec [-ns] [nick|server] [params] ; to request delay and send it to alias ; ; /pingexec [params] ; to ping the server, returns in ms to the alias ; using a bnc could break this, as for example psybnc replies to the ping ; and ignore the parameter given ; returns: ; pong ; ; /pingexec -n [params] ; to ping a nick, returns in ms to the alias ; returns: ; ctcpreply ; 401 No such nick ; ; /pingexec -s [params] ; to ping , need to be oper, may be a wildcard match ; returns in ms to the alias ; works on ircu (UnderNet, QuakeNet) ; returns: ; rpong ; 402 No such server ; ; ; WARNING: DO NOT USE HALT IN AN ALIAS, USE RETURN! ; halt also halts the calling alias/event, return only stops the current alias ; and gives control back to the calling alias/event ; using halt in alias'es that are called from this script can cause it not to work 100% ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PINGEXEC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; /pingexec [-ns] [params..] alias pingexec { ; on irc if ($status == connected) { ; set var var %x = $ticks ; switch -n used, $2 is there if ($1 == -n) && ($2) { ; add to hash table hadd -mu300 $+(pingexec.,$cid) $pingexec.lower($2) $2- ; send ctcp version to $2 .quote PRIVMSG $2 $+(:,$chr(1),PING) $+($ctime,-,%x,$chr(1)) } ; switch -s is used, $2 is there elseif ($1 == -s) && ($2) { ; add to hash table hadd -mu300 $+(pingexec.,$cid) $2 $2- ; send RPING .quote RPING $2 $+(:pingexec-,%x) } ; $1 is there elseif ($1) { ; add to hash table hadd -mu300 $+(pingexec.,$cid) $+(pingexec.,%x) $1- ; ping the server .quote ping $+(pingexec.,%x) } } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PONG EVENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; server on ^*:pong:{ ; check the param, check the hash table if ($gettok($2,1,46) == pingexec) && ($gettok($2,2,46) isnum) && ($hget($+(pingexec.,$cid),$2)) { ; send the info to the alias $hget($+(pingexec.,$cid),$2)) $event $calc($ticks - $gettok($2,2,46)) $3- ; remove from hash table hdel $+(pingexec.,$cid) $2 ; if hash table is empty if ($hget($+(pingexec.,$cid),0).item == 0) { ; free hash table hfree $+(pingexec.,$cid) } ; stop raw haltdef } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; CTCPREPLY EVENT ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; on *:ctcpreply:PING *:{ ; check param, check hash table if ($gettok($2,1,45) isnum) && ($gettok($2,2,45) isnum) && ($hget($+(pingexec.,$cid),$pingexec.lower($nick))) { ; set var var %t = $ifmatch ; send info to the alias $gettok(%t,2-,32) $event $gettok(%t,1,32) $calc($ticks - $gettok($2,2,45)) ; remove from hash table hdel $+(pingexec.,$cid) $pingexec.lower($nick) ; check hash table if ($hget($+(pingexec.,$cid),0).item == 0) { ; free hash table hfree $+(pingexec.,$cid) } ; stop raw haltdef } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RAW 401 NO SUCH NICK ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 401 me nick :No such nick raw 401:& & no such nick:{ ; check hash table if ($hget($+(pingexec.,$cid),$pingexec.lower($2))) { ; set var var %t = $ifmatch ; send info to alias $gettok(%t,2-,32) $numeric $gettok(%t,1,32) No such nick ; remove from hash table hdel $+(pingexec.,$cid) $pingexec.lower($nick) ; check hash table if ($hget($+(pingexec.,$cid),0).item == 0) { ; free hash table hfree $+(pingexec.,$cid) } ; stop raw haltdef } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RAW RPONG ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; me server delay :param raw rpong:& & & *:{ ; check param, check hash table if ($gettok($4,1,45) == pingexec) && ($gettok($4,2,45) isnum) && ($hfind($+(pingexec.,$cid),$2,1,W)) { ; set var var %t = $hget($+(pingexec.,$cid),$hfind($+(pingexec.,$cid),$2,1,W)) ; send info to the alias $gettok(%t,2-,32) $event $gettok(%t,1,32) $2 $3 ; remove from hash table hdel $+(pingexec.,$cid) $hfind($+(pingexec.,$cid),$2,1,W) ; check hash table if ($hget($+(pingexec.,$cid),0).item == 0) { ; free hash table hfree $+(pingexec.,$cid) } ; stop raw haltdef } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RAW 402 NO SUCH SERVER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; 402 me server :No such server raw 402:& & no such server:{ ; check hash table if ($hfind($+(pingexec.,$cid),$2,1,W)) { ; set var var %t = $hget($+(pingexec.,$cid),$hfind($+(pingexec.,$cid),$2,1,W)) ; send info to alias $gettok(%t,2-,32) $numeric $gettok(%t,1,32) No such server ; remove from hash table hdel $+(pingexec.,$cid) $hfind($+(pingexec.,$cid),$2,1,W) ; check hash table if ($hget($+(pingexec.,$cid),0).item == 0) { ; free hash table hfree $+(pingexec.,$cid) } ; stop raw haltdef } } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIAS PINGEXEC.LOWER ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; $pingexec.lower(nick) alias -l pingexec.lower { ; on IRC these chars are upper(lower) case of eachother: { = [, } = ], | = \, ~ = ^ ; so here we replace them to make sure we compare the right things right return $replace($1,$chr(123),$chr(91),$chr(125),$chr(93),$chr(124),$chr(92),$chr(126),$chr(94)) } ; this is an example script alias lag { pingexec echo -a lag to server: }