main.tin 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 模块名称:框架主程序
  4. 模块说明:本文件属于框架代码的一部分,不建议修改。如有需求请在 GitHub 发 issue 或者 PR
  5. 版权声明:本文件属于 PaoTin++ 的一部分
  6. ===========
  7. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  8. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  9. ===========
  10. */
  11. #class main open;
  12. #kill all;
  13. #event {PROGRAM START} {
  14. #if { "$user[manual]" == "true" } {
  15. #var user[id] {};
  16. #var user[name] {};
  17. #var user[passwd] {};
  18. #screen set title {};
  19. };
  20. #else {
  21. #if { "$user[id]" != "{[A-Za-z0-9]+}" } {
  22. #echo {<119>请参考使用文档指定用户正确的 user id。<299>};
  23. #return;
  24. };
  25. #local path {$user[id]};
  26. #if { "$session[log_path]" != "" } {
  27. #local path {$session[log_path]};
  28. };
  29. #if { !@InitLog{$path} } {
  30. #echo {<119>创建日志目录 $gLog[PATH]/$path 时遇到错误。<299>};
  31. #echo {<139>请检查你的安装环境,或者参考使用手册重新安装本软件。<299>};
  32. #return;
  33. };
  34. };
  35. load-module basic/login;
  36. auto-login;
  37. };
  38. #event {PROGRAM TERMINATION} {
  39. #screen set title {NONE};
  40. };
  41. #alias {auto-login} {
  42. login {$session} {$user} {
  43. load-file {framework/online.tin};
  44. };
  45. };
  46. #event {SESSION CREATED} {
  47. #nop #gts 中残留的 #tick 会在 mud 会话被创建时继承并错误地激活,从而影响游戏过程,特别是登录。;
  48. #kill ticker;
  49. #if { "%0" !== "$session[name]" } {
  50. #return;
  51. };
  52. #%0 {
  53. log.Open;
  54. load-module lib/event;
  55. event.Define {user-online} {无参} {framework} {已经登录到服务器,所有命令都可以正常使用了。};
  56. load-module lib/ui;
  57. #if { "$user[manual]" != "true" } {
  58. #delay online.WatchDog {#zap} {$session[reconnect]};
  59. };
  60. };
  61. };
  62. #event {SESSION TIMED OUT} {
  63. #echo {%s} {<119>连接服务器超时,稍后自动重试。<299>};
  64. #gts #delay 3 auto-login;
  65. };
  66. #event {SESSION DISCONNECTED} {
  67. #if { "%0" == "$session[name]" } {
  68. #local reconnect {$session[reconnect]};
  69. #if { "$session[remote_maint]" == "true" } {
  70. #local reconnect {$session[reconnect_slow]};
  71. #var session[remote_maint] {false};
  72. };
  73. #if { "$reconnect" == "{|0}" } {
  74. #local reconnect 12;
  75. };
  76. #nop 断开连接后再次重连不要太频繁,以免服务器不高兴。;
  77. #echo {%s} {<119>连接已被服务器断开,$reconnect 秒后自动重连。<299>};
  78. #gts #delay {$reconnect} {
  79. #echo {%s} {<129>自动重连。<299>};
  80. auto-login;
  81. };
  82. };
  83. };
  84. #nop 优先加载 var/$file(玩家自定义文件),其次加载 mud/$file(MUDLIB 相关文件);
  85. #alias {load-file} {
  86. #local file {%1};
  87. #if { @isEmpty{$file} } {
  88. xtt.Usage load-file;
  89. #return;
  90. };
  91. #local output {};
  92. #script output {test -f var/$file && echo true || echo false};
  93. #if { "$output[1]" == "true" } {
  94. #read var/$file;
  95. #return;
  96. };
  97. #if { "$gCurrentMUDLIB" != "" } {
  98. #local output {};
  99. #script output {test -f mud/$gCurrentMUDLIB/$file && echo true || echo false};
  100. #if { "$output[1]" == "true" } {
  101. #read mud/$gCurrentMUDLIB/$file;
  102. #return;
  103. };
  104. };
  105. #read $file;
  106. #replace file {.tin$} {.extra.tin};
  107. #local output {};
  108. #script output {test -f mud/$gCurrentMUDLIB/$file && echo true || echo false};
  109. #if { "$output[1]" == "true" } {
  110. #read mud/$gCurrentMUDLIB/$file;
  111. };
  112. #local output {};
  113. #script output {test -f var/$file && echo true || echo false};
  114. #if { "$output[1]" == "true" } {
  115. #read var/$file;
  116. };
  117. };
  118. #alias {init} {
  119. #nop 调整 tintin 环境;
  120. load-file framework/settings.tin;
  121. #nop 框架依赖的基本函数;
  122. load-file framework/utils.tin;
  123. #nop 日志支持;
  124. load-file framework/log.tin;
  125. #nop 为 TinTin 赋能,实现模块加载器;
  126. load-file framework/module-loader.tin;
  127. #nop 支持不同的 MUD 服务器环境;
  128. load-file framework/multi-mud.tin;
  129. #nop 为 TinTin 赋能,自行实现的扩展语法和实用函数集。;
  130. load-lib xtintin;
  131. #nop 提供 TinTin++ 命令行自动补全功能。;
  132. load-lib tab-completion;
  133. #nop 默认的用户环境配置;
  134. load-file ids/DEFAULT;
  135. };
  136. #var session {};
  137. #var user {};
  138. #var char {};
  139. #var info {};
  140. init;
  141. #class main close;