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 an accurate lagmeter

Lag time is measured with the same principle that sonars work: you send a signal, wait for it to return, and then measure how long the signal spent on its journey. When we are talking about IRC lag that is between you and the server, you send a command to the server and wait for the server to reply.

There are countless ways of making the server to reply to your command. Technically nearly every command could be used to accomplish this. However the best commands are the ones that let us to include a timestamp to the sent command and get it back exactly the way it was sent. When this happens, we don't have to store the moment we sent the message because the message coming back will include that information. Basically this means sending a message with one of the available commands: /msg, /notice, /ctcp, and /ctcpreply. /ctcpreply is clearly the best choice of the mentioned commands. Sending CTCP reply can easily be separated from the other traffic between client and server. It also doesn't reset your idle time like /msg and /ctcp do.

Since you probably want to measure the lag all the time, a timer that runs forever the best way to go. When you specify -i switch to timer and make it call an alias that executes the /ctcpreply command to all connections, you will get a nice solution that works realiably and for all connections. There are two reasonable timestamps you can use: $ctime and $ticks. The first would measure the time in seconds while the latter can achieve millisecond precision. Since you probably want the most accurate available time, I'm going to use $ticks in the example. The on CTCPREPLY event will always be triggered for the right connection so we don't have to worry about that.

When mIRC was capable of connecting only to one server, it was rather easy to display the lag time in titlebar or in a dedicated custom window. Since mIRC can now connect to multiple servers, I don't know an easy and reasonable way to display lag time smoothly for all connections. The example just opens a custom window called @Lag and whenever mIRC receives a reply to a sent lag check, the script forwards the lag time into the custom window. Note that this script is not good for alerting about increasing lag. To accomplish that, you would need to use more timers.

Example script

on *:START: {
  window @Lag
  .timerlagmeter -i 0 45 pingme
}

alias pingme scon -at1 .ctcpreply $!me LAG $ticks

on *:CTCPREPLY:LAG*: {
  if ( $nick != $me ) halt
  if ( $window(@Lag) == $null ) window @Lag
  echo -t @Lag Lag for $server $+ : $calc(($ticks - $2) / 1000) $+ s
  halt
}

Warning! Do not send the lag checks too often. It will generate unnecessary traffic for the server. If everyone sent lag checks every five seconds, the server would be lagged because people want to see how lagged they are. Naturally such a situation would be rather ridiculous.


Last updated 2003-04-05, Janne 'Geetee' Nikula, jn-mirc@zkelvin.net