All pastes #830994 Raw Edit

Stuff

public text v1 · immutable
#830994 ·published 2007-12-24 13:25 UTC
rendered paste body
alias 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
}