rendered paste bodyalias sping {
noop $$server | if (!$hget(sping)) hmake sping 1
hadd sping wnd $active
if (!$dll(time.dll)) noop $$dll(time.dll,GetTime,.)
var %i = 1000 | while (%i) dec %i
var %ts = $$dll(time.dll,GetTime,.)
hadd -u600 sping ts %ts | .quote PING $+(TS:,%ts)
}
on ^*:PONG:{
if (!$regex($2,^TS:[0-9]+$)) return
var %newts = $$dll(time.dll,GetTime,.) | haltdef
.signal spings $gettok($2,2,58) %newts
var %ts = $hget(sping,ts), %wnd = $$hget(sping,wnd)
hdel sping ts | if ($gettok($2,2,58) != %ts) halt
var %ping = $calc(%newts - %ts)
if (%ping < 1000) %ping = %ping ms
else %ping = $round($calc(%ping /1000),2) sec.
if (%wnd == Status Window) echo -sc info * Ping: %ping
else msg %wnd Lag to $server $+ : %ping
}