WHO usage and numeric events

From Scriptwiki
Jump to: navigation, search

This script is supposed to show everyone how easy it is to get someones Q-authname, save it in a variable and/or return it.

Covers the usage of raw events and the /who command.

; A simple little alias that returns the time interval for the flood protection (in seconds).
; We make this alias local (-l switch), since we wont need it outside this script.

alias -l authflood {
 return 3
}

; Basic On Text event to trigger the script.

on *:Text:!auth *:#: {

 ; Flood protection so that noone can abuse the command and flood you off the server.
 ; If the variable %authflood doesnt exist, the script continues.

 if (!%authflood) {

   ; Check if there really is a nick to get the auth of, by making sure $2 exists.

   if ($2) {

     ; At first, we will save $2 in a variable, since we need it later on.

     set %nickname $2

     ; Perform a /who request of the nick with the appropriate flags (n%nat). For more info on /who command, read:
     ; http://www.mircscripts.org/showdoc.php?type=tutorial&id=2412
     ; the t flag is to identify the reply, which we assign a random number, in this case 465 (later on being used in the "raw 354"-event)

     who $2 n%nat,465  

     ; Assign %authchan the value of $chan so we can access it later

     set %authchan $chan

   }

   ; if there is no $2, show the syntax

   else {
     msg $chan To use it correctly, type !auth <nickname>
   }

   ; Set the %authflood variable (in order to prevent abuse of the command) to $authflood seconds using the -u switch.

   set -u [ $+ [ $authflood ] ] %authflood 1
 }
}

; Raw numeric 354 is the servers reply of the /who request. We check if "465" is in the reply
; to be sure its the reply we are looking for.
;
; (To read more about raws, have a look at: Raws

raw 354:& 465 & *: {

 ; syntax of raw 354 (with our flags): "me 465 nick authname" for authed people or
 ; "me 465 nick 0" for non-authed ones.
 ; but for now we will just assign %authname the value of $4 without checking if is 0 or not

 set %authname $4

}

; Raw numeric 315 notifies us that the /who request is over. Now is the time to
; process whatever data we have.

raw 315:*: {

 ; syntax of raw 315: "me nick End of /WHO list."
 ;
 ; We check if its really our reply by comparing the nickname ($2) against requested nickname (%nickname)

 if ($2 == %nickname) {

   ; At this stage %nickname should contain the nick of the requested nick, %authname the authname of %authnick
   ; and %authchan the channel to which we should send the information.
   ;
   ; We have to check if %authname isnt 0, since "!%authname" would return $true if %authname is 0

   if (!%authname) && (%authname != 0) {
     msg %authchan There is noone with the nick %nickname $+ .
   }

   ; if %authname is set to 0 the nick isnt authed.

   elseif (%authname == 0) {
     msg %authchan %nickname is currently not authed.
   }

   ; else we assume the user is authed and print the authname

   else {
     msg %authchan %nickname is authed as %authname $+ .

   }

   ; Unset the used variables

   unset %authname
   unset %authchan
   unset %nickname

 }
}