cmds.tin 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分。
  4. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  5. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  6. */
  7. #nop 本文件是 xtintin 的一部分,实现了一些实用命令。;
  8. ///=== {
  9. ///// 实用命令:
  10. //
  11. // ## clear
  12. // 清屏。类似于 DOS/Unix,也可以用 cls,作用相同。
  13. // };
  14. #alias {cls} {clear};
  15. #alias {clear} {
  16. #system {tput clear};
  17. tmux.SetTheme GAME;
  18. prompt.refresh;
  19. };
  20. ///=== {
  21. // ## exit
  22. // 退出客户端,但不退出游戏角色。也可以用 quit,作用相同。
  23. // 一些中文 MUD 服务器在接收到 quit 命令时会让角色从服务器上下线,
  24. // 这往往会导致玩家丢失背包里的物品。新手玩家常常因此懊恼万分。
  25. // 为了避免悲剧发生,这里特别映射一下,改成仅断开连接,而不退出服务器角色。
  26. // 如果玩家真的需要向服务器发送 quit 指令,请输入 #send quit。exit 同理。
  27. // };
  28. #alias {exit} {#end};
  29. #alias {quit} {#end};
  30. ///=== {
  31. // ## xtt.Tick <ID> <代码> <间隔时间> [<触发次数>]
  32. // 跟 #tick 功能类似,但是会立即执行一次代码。对于间隔时间比较长的定时器来说尤其有用。
  33. // 可选的触发次数会导致定时器在次数达到限制后自动销毁。省略此参数时将不限制触发次数。
  34. // 你也可以通过 Tick 别名来使用本别名。
  35. // };
  36. #alias {Tick} {xtt.Tick};
  37. #alias {xtt.Tick} {
  38. #local id {%1};
  39. #local code {%2};
  40. #local interval {%3};
  41. #local times {@defaultNum{%4;0}};
  42. #math times {$times - 1};
  43. #line sub var #untick {$id};
  44. #if { $times > 0 } {
  45. #line sub {var;escapes;functions} #line multishot {$times} #tick {$id} {$code} $interval;
  46. };
  47. #elseif { $times < 0 } {
  48. #line sub var #tick {$id} {$code} $interval;
  49. };
  50. #line sub {var;escapes;functions} $code;
  51. };
  52. ///=== {
  53. // ## xtt.ListTicker
  54. // 列出系统中所有的定时器。因为定时器一般不会很多因此暂时没有做过滤功能。
  55. // 你也可以通过 TICKS 别名来使用本别名。
  56. // };
  57. #alias {TICKS} {xtt.ListTicker};
  58. #alias {xtt.ListTicker} {
  59. #info tickers save;
  60. #echo {<128> %-30s %+20s %+10s %+20s} {所属模块} {定时器名称} {执行周期} {距离下次执行(s)};
  61. #draw Yellow scroll line 1 1 1 90;
  62. #format utime %U;
  63. #local index {};
  64. #loop {1} {&info[TICKERS][]} {index} {
  65. #local uval {};
  66. #math uval $info[TICKERS][+$index][arg3] * 1000000;
  67. #local name {$info[TICKERS][+$index][arg1]};
  68. #echo { %-30s %+20s %+10s %+20m}
  69. {@genModuleLink{$info[TICKERS][+$index][class];MOD}}
  70. {$name @mslp.Exec{{xtt.delTrigger tick $name};<119>✗<269>;false}}
  71. {$info[TICKERS][+$index][arg3]}
  72. {($uval - ($utime - $info[TICKERS][+$index][arg4]) % $uval) / 1000000.00};
  73. };
  74. };
  75. ///=== {
  76. // ## xtt.ListAlias [<正则表达式>]
  77. // 列出系统中符合条件的别名,如果省略条件则列出所有别名。
  78. // 一些不够规整的别名不会被列出。只有符合 PaoTin++ 规范的别名才会被列出。
  79. // 正则表达式会被运用到别名所属模块名称和别名名称上,两者符合其一即可被列出。
  80. // 你也可以通过 ALIASES 别名来使用本别名。
  81. // };
  82. #alias {ALIASES} {xtt.ListAlias};
  83. #alias {xtt.ListAlias} {
  84. #local pattern {%1};
  85. #info aliases save;
  86. #local aliasTable {};
  87. #local index {};
  88. #loop {1} {&info[ALIASES][]} {index} {
  89. #local name {$info[ALIASES][+$index][arg1]};
  90. #local class {$info[ALIASES][+$index][class]};
  91. #if { "$class" == "" && "$pattern" != "all" } {
  92. #continue;
  93. };
  94. #if { "$class" == "" } {
  95. #local class {未分组};
  96. };
  97. #if { "$name" == "%*{[^a-zA-Z0-9-_.]}%*" } {
  98. #continue;
  99. };
  100. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  101. #continue;
  102. };
  103. #list {aliasTable[$class]} sort {$name};
  104. };
  105. #local format { %-30s %-40s %-10s};
  106. #echo {<128>$format} {class} {别名} {类型};
  107. #draw Yellow scroll line 1 1 1 90;
  108. #local classList {@list.Sort{*aliasTable[]}};
  109. #local class {};
  110. #foreach {$classList} {class} {
  111. #local name {};
  112. #foreach {${aliasTable[$class][]}} {name} {
  113. #local type {<139>自定义<299>};
  114. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  115. #local type {<129>开放API<299>};
  116. };
  117. #if { "$class" == "module-loader" } {
  118. #if { "$name" == "{[A-Z]+}" } {
  119. #local type {<169>快捷方式<299>};
  120. };
  121. #else {
  122. #local type {<229>语法增强<299>};
  123. }
  124. };
  125. #if { "${class}.$name" == "main.class.%*" } {
  126. #local type {<229>语法增强<299>};
  127. };
  128. #if { "${class}.$name" == "main.load-{file|config}" } {
  129. #local type {<229>语法增强<299>};
  130. };
  131. #if { "${class}.$name" == "main.%*Log" } {
  132. #local type {<129>日志接口<299>};
  133. };
  134. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  135. #continue;
  136. };
  137. #echo {<060>$format}
  138. {@genModuleLink{$class;MOD}<060>}
  139. {@mslp.Exec{{xtt.delTrigger alias $name};<119>✗<269>;false} @linkToHelp{$class;$name}}
  140. {$type};
  141. };
  142. };
  143. };
  144. ///=== {
  145. // ## xtt.ListVar [<正则表达式>]
  146. // 列出系统中符合条件的变量,如果省略条件则列出所有变量。
  147. // 一些不够规整的变量不会被列出。只有符合 PaoTin++ 规范的变量才会被列出。
  148. // 正则表达式会被运用到变量所属模块名称和变量名称上,两者符合其一即可被列出。
  149. // 你也可以通过 VARS 别名来使用本别名。
  150. // };
  151. #alias {VARS} {xtt.ListVar};
  152. #alias {xtt.ListVar} {
  153. #local pattern {%1};
  154. #info variable save;
  155. #local varTable {};
  156. #local index {};
  157. #loop {1} {&info[VARIABLES][]} {index} {
  158. #local name {$info[VARIABLES][+$index][arg1]};
  159. #local class {$info[VARIABLES][+$index][class]};
  160. #local value {$info[VARIABLES][+$index][arg2]};
  161. #local nest {$info[VARIABLES][+$index][nest]};
  162. #if { "$class" == "" && "$pattern" != "all" } {
  163. #continue;
  164. };
  165. #if { "$class" == "" } {
  166. #local class {未分组};
  167. };
  168. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  169. #continue;
  170. };
  171. #local {varTable[$class][$name]} {
  172. {nest}{$nest}
  173. {value}{$value}
  174. };
  175. };
  176. #local format { %-30s %-40s %-10s %s};
  177. #echo {<128>$format} {class} {变量} {类型} {值};
  178. #draw Yellow scroll line 1 1 1 95;
  179. #local classList {@slist.Sort{*varTable[]}};
  180. #local class {};
  181. #foreach {$classList} {class} {
  182. #local name {};
  183. #local nameList {@slist.Sort{*varTable[$class][]}};
  184. #foreach {$nameList} {name} {
  185. #local type {<229>字符串<299>};
  186. #local value {<169>$varTable[$class][$name][value]<299>};
  187. #local nest {$varTable[$class][$name][nest]};
  188. #if { $nest > 0 } {
  189. #local type {<259>表格<299>};
  190. #local value {@mslp.Var{$name;<139>[... 共 $nest 项数据]<299>}};
  191. };
  192. #echo {<060>$format}
  193. {@genModuleLink{$class;MOD}<060>}
  194. {@mslp.Exec{{xtt.delTrigger var $name};<119>✗<269>;false} @linkToHelp{$class;$name}}
  195. {$type}
  196. {$value};
  197. };
  198. };
  199. };
  200. #alias {xtt.delTrigger} {
  201. #local type {%1};
  202. #local trigger {%2};
  203. #local cmd {#un$type $trigger};
  204. $cmd;
  205. };
  206. ///=== {
  207. // ## xtt.ListFunc [<正则表达式>]
  208. // 列出系统中符合条件的函数,如果省略条件则列出所有函数。
  209. // 正则表达式会被运用到函数所属模块名称和函数名称上,两者符合其一即可被列出。
  210. // 一些不够规整的函数不会被列出。只有符合 PaoTin++ 规范的函数才会被列出。
  211. // 你也可以通过 FUNCS 别名来使用本别名。
  212. // };
  213. #alias {FUNCS} {xtt.ListFunc};
  214. #alias {xtt.ListFunc} {
  215. #local pattern {%1};
  216. #info functions save;
  217. #local funcsTable {};
  218. #local index {};
  219. #loop {1} {&info[FUNCTIONS][]} {index} {
  220. #local name {$info[FUNCTIONS][+$index][arg1]};
  221. #local class {$info[FUNCTIONS][+$index][class]};
  222. #if { "$class" == "" && "$pattern" != "all" } {
  223. #continue;
  224. };
  225. #if { "$class" == "" } {
  226. #local class {未分组};
  227. };
  228. #if { "$name" == "%*{[^a-zA-Z0-9_./-]}%*" } {
  229. #continue;
  230. };
  231. #if { "$pattern" != "{|all}" && "$class/$name" != "%*$pattern%*" } {
  232. #continue;
  233. };
  234. #list {funcsTable[$class]} sort {$name};
  235. };
  236. #local format { %-30s %-40s %-10s};
  237. #echo {<128>$format} {class} {函数} {类型};
  238. #draw Yellow scroll line 1 1 1 90;
  239. #local classList {@list.Sort{*funcsTable[]}};
  240. #local class {};
  241. #foreach {$classList} {class} {
  242. #local name {};
  243. #foreach {${funcsTable[$class][]}} {name} {
  244. #local type {<139>自定义<299>};
  245. #if { "$name" == "%*.{[A-Z][a-zA-Z0-9]+}" } {
  246. #local type {<129>开放API<299>};
  247. };
  248. #if { "$class" == "{lib/xtintin|main}" } {
  249. #local type {<229>语法增强<299>};
  250. };
  251. #if { "${class}.$name" == "main.%*Log" } {
  252. #local type {<129>日志接口<299>};
  253. };
  254. #if { "$pattern" == "" && "$type" == "%*自定义%*" } {
  255. #continue;
  256. };
  257. #echo {<060>$format}
  258. {@genModuleLink{$class;MOD}<060>}
  259. {@mslp.Exec{{xtt.delTrigger func $name};<119>✗<269>;false} @linkToHelp{$class;$name}}
  260. {$type};
  261. };
  262. };
  263. };
  264. ///=== {
  265. // ## xtt.Var <变量中文含义> <变量名> <值>
  266. // 声明并初始化变量。和 #var 不同,如果该变量已存在,则不会修改它的值。
  267. // 另外,如果在模块中使用本方法,则声明的变量会自动存放在 #class data/$MODULE 中。
  268. // 这意味着即使你重新载入模块代码,也不会破坏该变量的值。
  269. // 因此建议将通过触发抓取到的任务进度信息用本方法存储,可以有效避免机器代码迭代
  270. // 开发过程中,丢失任务信息从而导致任务失败。
  271. //
  272. // 也可以通过短名称 VAR 来使用本命令,效果相同。
  273. // };
  274. #alias {VAR} {xtt.Var};
  275. #alias {xtt.Var} {
  276. #local cnName {%1};
  277. #local name {%2};
  278. #local value {%3};
  279. #if { @existsVar{$name} } {
  280. #return;
  281. };
  282. #if { @existsVar{MODULE} } {
  283. #class data/$MODULE open;
  284. #var {$name} {$value};
  285. #class data/$MODULE close;
  286. };
  287. #else {
  288. #var {$name} {$value};
  289. };
  290. };
  291. load-lib option;
  292. option.Define {DisableOutput} {Bool} {是否禁止向服务器发送命令} {false};
  293. ///=== {
  294. // ## xtt.Send <命令> [<参数> ...]
  295. // 向服务器发送命令。如果命令拦截总开关被打开,则不会真的向服务器发送。
  296. // };
  297. #alias {xtt.Send} {
  298. #if { @option.IsEnable{DisableOutput} } {
  299. #echo {<169>命令已被抑制: <429>%p<299>} {%0};
  300. #return;
  301. };
  302. #send %0;
  303. };
  304. ///=== {
  305. // ## xtt.SendAtOnce <分号分隔的命令序列>
  306. // 一次性向服务器发送多条命令。
  307. // 有的 MUD 服务器专门为这种方式开辟了通道,本方法可以使用这种通道。
  308. // TODO: 需要区分 MUD,需要支持定制的命令分隔符。
  309. // };
  310. #alias {xtt.SendAtOnce} {
  311. #local cmds {%1};
  312. xtt.Send {#$cmds#};
  313. };
  314. ///=== {
  315. // ## xtt.Answer <问题答复>
  316. // 如果游戏中有需要回答的问题,并且给出了特定的提示符(就是不带换行的文本),
  317. // 那么由于 TinTin++ 的某种机制,导致回答的内容和问题就会有重叠,不能正确显示。
  318. // 此时建议用 xtt.Answer 来回答此类问题。将会留下美观的 buffer 记录。
  319. // };
  320. #alias {xtt.Answer} {
  321. #delay 0 {
  322. #echo {};
  323. #buffer end;
  324. xtt.Send {%1};
  325. };
  326. };
  327. ///=== {
  328. // ## xtt.Stop <命令>
  329. // 暂时阻断某个命令的执行。
  330. // 某些基于触发的机器会周而复始地执行动作。本命令可以用来终止它的运行,并保留状态。
  331. // 例如新手机器人会循环执行 ask job/do/finish 流程,那么只需要输入 xtt.Stop ask,
  332. // 就可以在下一次 ask NPC 时,暂停机器执行,但并不影响机器状态。此时玩家可以手动
  333. // 操作角色,临时去做点别的,比如收个包袱之类的,然后回到房间,手动执行一次 ask 命令,
  334. // 就可以继续机器运行了。
  335. // };
  336. #alias {xtt.Stop} {
  337. #if { "%1" == "" } {
  338. xtt.Usage xtt.Stop;
  339. #return;
  340. };
  341. #line oneshot #alias {%1} {halt; #echo {<119>任务已暂停,请输入 <139>%1 %s <119>继续运行。<299>} {%%0}}
  342. };
  343. option.Define {DisableAllCommands} {Bool} {是否禁用所有的触发器和定时器} {false};
  344. ///=== {
  345. // ## xtt.DisableAllCommands
  346. // 禁止发送任何命令。
  347. // 某些游戏模式下,玩家必须小心地输入,否则一旦输错会造成损失。此时可以用本
  348. // 命令来禁止所有的触发、定时器、事件,防止误发命令。
  349. // 此时玩家只能用 #send {.....} 命令来发送命令。
  350. // 注意快捷键并不会被禁止,所以玩家可以通过快捷键来切换状态。
  351. // };
  352. #alias {xtt.DisableAllCommands} {
  353. #class disable-all-commands open;
  354. option.Enable DisableAllCommands;
  355. warnLog 所有定时器、触发器和事件句柄已被禁用。;
  356. warnLog 600 秒后自动解除该状态。;
  357. #alias {^%*{|ID=paotin/disable-all-commands}$} {
  358. #echo {<119>命令已被抑制,可用 <129>#send<119> 强制发送。撤销请用 <129>xtt.UndoDisableAllCommands<119> : <139>%s<299>} {%%0}
  359. } {1.001};
  360. #gts {#delay 600 {#ats xtt.UndoDisableAllCommands}};
  361. #line quiet #ignore actions on;
  362. #line quiet #ignore tickers on;
  363. #line quiet #ignore events on;
  364. #class disable-all-commands close;
  365. };
  366. ///=== {
  367. // ## xtt.DisableAllCommands
  368. // 禁止发送任何命令。
  369. // 某些游戏模式下,玩家必须小心地输入,否则一旦输错会造成损失。此时可以用本
  370. // 命令来禁止所有的触发、定时器、事件,防止误发命令。
  371. // 此时玩家只能用 #send {.....} 命令来发送命令。
  372. // 注意快捷键并不会被禁止,所以玩家可以通过快捷键来切换状态。
  373. // };
  374. #alias {xtt.UndoDisableAllCommands} {
  375. #class disable-all-commands kill;
  376. #line quiet #ignore actions off;
  377. #line quiet #ignore tickers off;
  378. #line quiet #ignore events off;
  379. okLog 命令已恢复正常。;
  380. option.Disable DisableAllCommands;
  381. } {1.000};
  382. ///=== {
  383. // ## xtt.ToggleDisableCommands
  384. // 在禁止和打开所有的定时器、触发器和事件句柄之间来回切换。
  385. // 本命令可用作绑定快捷键使用。
  386. // };
  387. #alias {xtt.ToggleDisableCommands} {
  388. #if { @option.IsEnable{DisableAllCommands} } {
  389. xtt.UndoDisableAllCommands;
  390. };
  391. #else {
  392. xtt.DisableAllCommands;
  393. };
  394. } {1.000};
  395. #func {linkToHelp} {
  396. #local module {%1};
  397. #local keyword {%2};
  398. #local text {$keyword};
  399. #local cmd {HELP $keyword};
  400. #if { "$keyword" == "" } {
  401. #local text {$module};
  402. #local keyword {MODULE};
  403. #local cmd {HELP $module};
  404. };
  405. #if { "$module" == "" } {
  406. #return {$text};
  407. };
  408. #if { &xtt.module-doc[$module][] == 0 } {
  409. #return {$text};
  410. };
  411. #if { &xtt.module-doc[$module][$keyword][] == 0 } {
  412. #return {$text};
  413. };
  414. #return {<149>@mslp.Exec{{$cmd};{$text}}<299>};
  415. };
  416. ///=== {
  417. // ## cli.SmartToggle
  418. // 命令行智能切换。
  419. // 出于方便起见,该命令实际上集成了三个作用,并推荐使用快捷键来调用本命令。
  420. // - 作用1: 当命令行尚未输入内容时,用来切换 PaoTin++ 的调试开关。
  421. // 调试开关开启时,玩家可以看到触发的执行细节,方便调试代码。
  422. // - 作用2: 当命令行输入了 #alias/#action 等 TinTin++ 可被取消的触发时,会
  423. // 自动修改成对应的 #unalias/#unaction 命令,利用这一点可以方便取
  424. // 消已有触发。可被取消的触发列表见下方完整清单。
  425. // - 作用3: 当命令行输入了其它命令时,会自动开启或关闭以调试方式执行该命令。
  426. // 该切换并不会影响全局调试开关。因此不会受到来自其它触发的干扰,
  427. // 内容更精准,方便查看。
  428. //
  429. // 作用2中可被取消的命令清单:
  430. // - 常用 TinTin++ 命令: action alias tick variable delay gag
  431. // - 不常用 TinTin++ 命令: button event function highlight macro pathdir
  432. // prompt substitute tab
  433. // 以上命令的 3 字母以上简写,无论大小写,都会被自动添加或者删除 un,
  434. // 以达到切换的目的。
  435. // - 常用的 PaoTin++ 命令: event.Handle/event.HandleOnce VS event.UnHandle
  436. // };
  437. #alias {cli.SmartToggle} {
  438. #local input {};
  439. #cursor get input;
  440. #line quiet #ignore function on;
  441. #if { {$input} == {} } {
  442. #line quiet #ignore function off;
  443. xtt.ToggleDebug;
  444. #return;
  445. };
  446. #if { {$input} == {#line debug %*} } {
  447. #replace input {^#line debug } {};
  448. };
  449. #else {
  450. #local cmds {act(|i(|o(|n)))|ali(|a(|s))|tic(|k(|e(|r)))
  451. |var(|i(|a(|b(|l(|e)))))
  452. |del(|a(|y))|gag|tab
  453. |but(|t(|o(|n)))|eve(|n(|t))
  454. |fun(|c(|t(|i(|o(|n)))))
  455. |hig(|h(|l(|i(|g(|h(|t))))))
  456. |mac(|r(|o))|pat(|h(|d(|i(|r))))
  457. |pro(|m(|p(|t)))
  458. |sub(|s(|t(|i(|t(|u(|t(|e)))))))};
  459. #replace cmds { } {};
  460. #if { {$input} == {{?i}#un{$cmds} %*} } {
  461. #replace input {{?i}#un} {#};
  462. };
  463. #elseif { {$input} == {{?i}#{$cmds} %*} } {
  464. #replace input {^#} {#un};
  465. };
  466. #elseif { {$input} == {{tt|}event.{Class|}Handle{|Once} %*} } {
  467. #replace input {^{tt|}event.{Class|}Handle{Once|}} {&1event.UnHandle};
  468. };
  469. #elseif { {$input} == {{tt|}event.UnHandle %*} } {
  470. #replace input {^{tt|}event.UnHandle} {&1event.Handle};
  471. };
  472. #else {
  473. #local input {#line debug $input};
  474. };
  475. };
  476. #cursor clear;
  477. #local cmd {
  478. #line quiet #ignore variable on;
  479. #line quiet #line sub escapes #cursor set {$input};
  480. #line quiet #ignore variable off;
  481. };
  482. $cmd;
  483. #line quiet #ignore function off;
  484. };
  485. ///=== {
  486. // ## xtt.Ping [<次数>]
  487. // 计算服务器延迟,输出以毫秒为单位的统计数据;
  488. // };
  489. #alias {PING} {xtt.Ping};
  490. #alias {xtt.Ping} {
  491. #class xtt.Ping open;
  492. #list xtt-ping-samples create {};
  493. #var xtt-ping-send-time {};
  494. #var xtt-ping-times {10};
  495. #alias {xtt.Ping.ping} {
  496. #if { $xtt-ping-times <= 0 } {
  497. xtt.Ping.done;
  498. #return;
  499. };
  500. #var xtt-ping-send-time {@str.Format{%U}};
  501. sync.Wait xtt.Ping.pong;
  502. };
  503. #alias {xtt.Ping.pong} {
  504. #math xtt-ping-times {$xtt-ping-times - 1};
  505. #list xtt-ping-samples add {@math.Eval{ @str.Format{%U} - $xtt-ping-send-time }};
  506. xtt.Ping.ping;
  507. };
  508. #alias {xtt.Ping.done} {
  509. #list xtt-ping-samples order;
  510. #list xtt-ping-samples delete -1;
  511. #list xtt-ping-samples delete 1;
  512. #local min {@math.Eval{ $xtt-ping-samples[1] / 1000 }};
  513. #local max {@math.Eval{ $xtt-ping-samples[-1] / 1000 }};
  514. #local avg {@math.Eval{ @math.Sum{$xtt-ping-samples[]} / &xtt-ping-samples[] / 1000 }};
  515. #class xtt.Ping kill;
  516. okLog 网络测速结果如右,最大值 $max 毫秒,最小值: $min 毫秒,平均值 $avg 毫秒;
  517. };
  518. #class xtt.Ping close;
  519. sync.Wait {xtt.Ping.ping};
  520. };