RAW Events

Contributed by INSIDES
While using mIRC and supposedly scripting for it as well, most of the scripters have found difficulties trying to handle some of the events that the servers raise including the standard server messages. mIRC itself anticipates these messages and handles the events in a manner that its author found convenient.

In some cases, you may find these manners inapropriate, and try to produce a different handle for the server notices. These cases could cover different MOTD display, advanced WHOIS reply, external information logging and so on.
Recognizing RAW Events
RAW events are raised by using a simple command mostly issued by you or the IRC client, like mIRC in this tutorial. Some of that commands are /MOTD, /WHOIS , /LIST and so on. According to the command your client issues, the server replies with a numeric response, that has been previously set and can not be dynamicaly changed. At some times, some of the events can be anticipated by using the name of the event, in which case you must know the exact name of the event that has been raised.

Note: For a full list of numeric replies, please check the memo covering the basics of the IRC protocol, called RFC1459.txt, which you can find at the miscellaneous section of this site. There you can find the full list of numeric replies and their descriptions.
RAW Prefix
RAW events can be easily anticipated and handled using the RAW pefix in the remote section of mIRC. The correct format of the RAW prefix handling the RAW events is:

RAW <numeric reply>:<match text>:<script commands>

Note: Using the match text parameter often means true anticipation of the text that has been sent to you from the server. Having not being able to make sure what the text will contain, try to use an asterisk <*> for the match text. On the other hand, having so many RAW events that can be raised by the servers, filtering can be quite time-consuming.
Handling the RAW events
A simple reply to a RAW event that I've set fore an example below coresponds to the numeric reply 322, which is the standard server reply to the /LIST command, used to list the names of the channels on the net you are connected to. This example uses an asterisk <*> for the match text parameter, and then prints whatever text it receives from the server to the mIRC Status window.
RAW 322:*:{ echo -s $1- }
Note: Most of the events raised by the server seem to send several replies, further more if the information the server supplies is too big to fit within one line. In our example, that coresponds with as many server replies as there are channels. That's why, in order for the client to recognize the start and the end of the list of information that the server supplies, most of the numeric replies are related to similar repliesarking the start and the end of the list. According to the RFC1459 protocol:

Numeric Reply: 	321	RPL_LISTSTART
Server Text:	Channel :Users  Name

Numeric Reply: 	322	RPL_LIST
Server Text:      <channel> <# visible> :<topic>

Numeric Reply: 	323	RPL_LISTEND
Server Text:      :End of /LIST
Replies RPL_LISTSTART, RPL_LIST, RPL_LISTEND mark the start, actual replies with data and end of the server's response to a /LIST command. If there are no channels available to return, only the start and end reply must be sent.

We do not neccesarilly need to filter the replies marked with 321 and 323, but they offer an oportunity for initialisation events, especially if you want to print the replies to a specific window. For that to work, we'll set our example to list the channels in a different custom window, which will be created bu using the /WINDOW command.
RAW 321:*:{ 
  if ($window(@CHANNELS) == $null) {
    window @CHANNELS
    aline @CHANNELS Listing all available channels ...
  }
}

RAW 322:*:{ aline @CHANNELS $1- }

RAW 323:*:{ aline @CHANNELS Finished listing channels ... }
As you can see, the code is quite simple. In the first RAW event, the RPL_LISTSTART is processed. The script checks if a window has been opened. If not it opens a custom window named @CHANNELS, which does not have a listbox nore an editbox, simply cause they are not needed, and then prints the line Listing all available channels ...

The second RAW event processes the listing action itself. For every reply the client receives, the script prints a line in the @CHANNELS window according to the RFC1459 format tha has been set within the reply: <channel> <# visible> :<topic>.

The third RAW event simply announces the end of the channel listings.

Note: Even though the RFC1459 protocol, and therefor the servers cover every event that can be raised with a specific numeric reply, try to use the RAW events filtering and handling in situations that can not be avoided, such as the one described before. That is why, mIRC has been programmed to anticipate most of the events by not coresponding to the RAW events.

In addition to the tutorial is a script that, just like the one before, prints the MOTD to a custom window by using the specific replies.

Message Of The Day Anticipation

Numeric Reply: 	375	RPL_MOTDSTART
Server Text:	:- <server> Message of the day - 

Numeric Reply: 	372	RPL_MOTD
Server Text:      :- <text>

Numeric Reply: 	376	RPL_ENDOFMOTD
Server Text:      :End of /MOTD command
When responding to the MOTD message and the MOTD file is found, the file is displayed line by line, with each line no longer than 80 characters, using RPL_MOTD format replies. These should be surrounded by a RPL_MOTDSTART ( before the RPL_MOTDs ) and an RPL_ENDOFMOTD ( after ).
RAW 375:*:{ 
  if ($window(@MOTD) == $null) {
    window @MOTD
    aline @MOTD Printing the Message Of The Day at server $3 ...
  }
}
RAW 372:*:{ aline @MOTD $2- }

RAW 376:*:{ aline @MOTD Finished MOTD ... }
Note: Unlike the previous example, I used the $2- parameter because I tried to avoid the :- mark to be displayed.
All content is copyright by mircscripts.org and cannot be used without permission. For more details, click here.