; TinyFugue ping command and trigger to find latency to the current world. ; ;; This script is copyrighted June 01, 2002 by Christian J. Robinson ;; . It is protected and distributed under the ;; terms of the GNU General Public License, version 2 or later. ; ;; Usage: ; ; /ping Determine the current latency to the current world and set ; LagTime as well as displaying the result. ; ; /ping Determine latency every %ping_delay minutes (default 1) and ; set %LagTime. The result isn't displayed; this is meant ; for use in your status bar or something. To force the ; result to be displayed, set %ping_force_display to 1. ; ; You can also set %ping_force_display to a number greater ; than 1, in which case the display is only forced if the lag ; time is greater than or equal to that many seconds. ; ; /ping Kill the ping loop started with "/ping on". ; ; /kp Same as /ping off ; /p Same as /ping ; ; ----------------------------------------------------------------------------- ; $Id: ping.tf,v 1.6 2008/02/12 04:30:47 infynity Exp $ ; $Log: ping.tf,v $ ; Revision 1.6 2008/02/12 04:30:47 infynity ; @pemit => @pemit/silent ; ; Revision 1.5 2003/10/09 10:15:13 infynity ; Convert the times to integers for TF5. ; ; Revision 1.4 2003/08/19 09:50:02 infynity ; Tweaks for TF5. ; ; Revision 1.3 2002/06/02 12:41:54 infynity ; ping_force_display forces display always when set to 1, or it can be ; a threshold in seconds. ; ; Some minor changes to variable names. ; ; ----------------------------------------------------------------------------- /loaded __OWNLIB__/ping.tf /if ({LagTime} =~ "") \ /set LagTime= %; \ /endif /eval /set pingid=$[pingid ? : -1] /eval /set ping_force_display=$[ping_force_display ? : 0] /eval /set ping_delay=$[ping_delay ? : 1] ; Ping the world or start/stop an auto ping loop, see above for usage: /def -i ping = \ /if (({1} =~ "1") | regmatch("^(on|yes)$", {1})) \ /if ({pingid} == -1) \ /_ping 1 %; \ /echo %% Ping loop started. %; \ /else \ /echo %% Ping loop already running. %; \ /endif %; \ /elseif (({1} =~ "0") | regmatch("^(off|no)$", {1})) \ /if ({pingid} != -1) \ /kill %pingid %; \ /set pingid=-1 %; \ /set LagTime=%LagTime %; \ /echo %% Ping loop killed. %; \ /else \ /echo %% Ping loop not running. %; \ /endif %; \ /else \ /_ping 0 %; \ /endif ; An alias to easily kill the auto ping loop, it takes no arguments: /def -i kp = /ping off ; An alias to ping the world once, it takes no arguments: /def -i p = /ping ; This shouldn't be called by hand. It decides how to send the ping request to ; the world, and whether to queue another delayed ping request: /def -i _ping = \ /if ({1} == 1) \ /repeat -0:%ping_delay 1 /_ping 1 %;\ /set pingid=%? %; \ /endif %; \ /if (regmatch("^tiny\\.mu(x|sh)", ${world_type})) \ /send @pemit/silent me= %; \ /elseif (${world_type} =~ 'echo') \ /send %; \ ; /elseif (${world_type} =~ 'tiny.muck') \ ; /send page ${world_character}= %; \ /elseif ({1} == 0) \ /echo %% Don't know how to ping the current world type (${world_type}). %; \ /endif ; Catch the ping "reply" and compute the latency: /def -i -ag -p100 -mregexp -t"" -q ping_trigger = \ /if ({P1} != getpid()) \ /return %; \ /endif %; \ /let lag_current_time=$[time()] %; \ /let lag=$[trunc({lag_current_time}) - trunc({P2})] %; \ /let lag_min=$[{lag} / 60] %; \ /let lag_sec=$[mod({lag}, 60)] %; \ /set LagTime=$[ lag_min ? strcat({lag_min},'m ') : "" ]%{lag_sec}s %; \ /if ({P3} == 0 | {ping_force_display} == 1 | \ ({ping_force_display} & {lag} >= {ping_force_display})) \ /echo %% Latency to world ${world_name}: %LagTime %; \ /endif ; Automatically update the lag time when the world is switched if the auto ping ; loop is running: /def -iqFp100 -mglob -h'WORLD ' auto_world_ping = \ /if ({pingid} > -1) \ /_ping 2 %; \ /endif