Note: The mainteinance of the scripting examples is discontinued since I no longer have an interest to continue doing so. The pages will remain here, for now, but that might not be the case in the future. You are free to download all the material on these pages and set a up mirror, or even continue the maintenance of the material by enhancing the examples yourself.

All the material in these examples are for the mIRC version 6.03. It is very likely that some or most of these examples won't work in future versions.

Scripting milliseconds to the ping replies

The way mIRC normally handles pings allows only full seconds to be seen in the ping reply. However it is possible to tweak things a bit and make the milliseconds show too.

First we need to take a look at the IRC protocol. RFC1459 specifies that a normal message is actually sent in form "PRIVMSG <target> :<message>" A normal CTCP is a PRIVMSG that has the ASCII character 001 in the front and in the end. A CTCP ping is sent in form "<ASCII 001>PING <timestamp><ASCII 001>" The ping reply just forwards the timestamp back just the way it was sent. When the client receives the ping reply, it substracts the timestamp from the current time and thus it gets the actual lag time. This means that we can put anything we like to the timestamp.

The timestamp mIRC uses in CTCP ping is the $ctime identifier that has the number of seconds elapsed since 1.1.1970. The alternative solution is to use $ticks that has the number of milliseconds since the last reboot. There might be some compatibility problems though. That's why it's better to send both $ctime and $ticks and get the result from the most accurate available value. If we proceed like this, we are going to send "PRIVMSG <target> : $+ $chr(1) $+ PING $ctime $ticks $+ $chr(1)"

Example script

; Usage: /ping <nick> or /ping <channel>
alias ping {
  quote -q PRIVMSG $1 : $+ $chr(1) $+ PING $ctime $ticks $+ $chr(1)
  echo $color(ctcp text) -set -> $chr(91) $+ $1 $+ $chr(93) PING

  ; If the PING reply has a second timestamp that is a number, interpret that as $ticks timestamp
  ; Otherwise let mIRC show the default reply
  if ( ($3 != $null) && ($3 isnum) ) {
    echo $color(ctcp text) -set $chr(91) $+ $nick PING reply $+ $chr(93) $+ : $calc(($ticks - $3) / 1000) $+ secs

Note that there is no guarantee that the other side will send the timestamp back the way it was sent. Some people might have a script that replies with a silly phrase instead of the timestamp. Other people might have a script that substracts or adds numbers to the timestamp. The bottom line is that sometimes you get replies like "Here's a PONG just for you!" or -8.482 seconds which naturally have very little to do with the timestamp you sent.

Last updated 2003-04-05, Janne 'Geetee' Nikula,