搜索
查看: 2066|回复: 3

请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区别

[复制链接]
发表于 2007-11-23 05:21:12 | 显示全部楼层 |阅读模式 来自 中国–北京–北京
附上源码 另外这个插件和wwcl有什么区别 wwcl也可以接触f1-12的按键绑定吧 考虑给服务器上这个 所以想先了解一下细节
请熟悉的朋友指出 非常感谢!

最后一个函数is_user_loopback没看明白 不知道是怎么判断某人是reconnect而不是刚加入游戏的 loopback是什么? 为什么可以用ips 和他进行equal判断
  1. /* Client Exec */
  2. /*
  3. *  Client exec some commands when connect, putin the server or player spawn.
  4. *  
  5. *  The config files are "client_exec_on_connect.cfg" , "client_exec_on_putinserv.cfg"
  6. *   and "client_exec_on_resethud.cfg" in the AMX Mod X configs dir.
  7. *
  8. *  [Change Log]
  9. *
  10. *   v1.2  divide "on_resethud" from "putinserv"
  11. *   v1.1  [L65] Fix config line number
  12. *
  13. */
  14. #include <amxmodx>
  15. #include <amxmisc>
  16. // don't exec commands on loopback
  17. #define LOOPBACK_NOT_EXEC 1
  18. new const PLUGIN_NAME[] = "Client Exec"
  19. new const PLUGIN_VERSION[] = "1.2"
  20. new const PLUGIN_AUTHOR[] = "KinSprite"
  21. new const cfg_file_connect[] = "client_exec_on_connect.cfg"
  22. new const cfg_file_putinserv[] = "client_exec_on_putinserv.cfg"
  23. new const cfg_file_resethud[] = "client_exec_on_resethud.cfg"
  24. #define MAX_EXEC_CHARS 128
  25. #define MAX_EXEC_LINES_CONNECT 128
  26. #define MAX_EXEC_LINES_PUTINSERV 128
  27. #define MAX_EXEC_LINES_RESETHUD 128
  28. new const cl_exec_connect[MAX_EXEC_LINES_CONNECT][MAX_EXEC_CHARS]
  29. new const cl_exec_putinserv[MAX_EXEC_LINES_PUTINSERV][MAX_EXEC_CHARS]
  30. new const cl_exec_resethud[MAX_EXEC_LINES_RESETHUD][MAX_EXEC_CHARS]
  31. new g_execNum_connect
  32. new g_execNum_putinserv
  33. new g_execNum_resethud
  34. enum {
  35. read_connect_cfg = 0,
  36. read_putinserv_cfg,
  37. read_resethud_cfg
  38. };
  39. new g_client_exec
  40. public plugin_init() {
  41. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  42. register_event("ResetHUD", "player_spawn", "b")
  43. g_client_exec = register_cvar("amx_client_exec", "1")
  44. }
  45. public plugin_cfg() {
  46. set_task(2.0, "read_exec_cfg")
  47. }
  48. public read_exec_cfg() {
  49. new cfg_dir[128], cfg_path[192], max_lines, max_chars
  50. get_configsdir(cfg_dir, 127)
  51. max_chars = MAX_EXEC_CHARS
  52. format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_connect)  // connect to server
  53. max_lines = MAX_EXEC_LINES_CONNECT
  54. g_execNum_connect = read_lines(cfg_path, read_connect_cfg, max_lines, max_chars)
  55. format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_putinserv) // put in server
  56. max_lines = MAX_EXEC_LINES_PUTINSERV
  57. g_execNum_putinserv = read_lines(cfg_path, read_putinserv_cfg, max_lines, max_chars)
  58. format(cfg_path, 191, "%s/%s", cfg_dir, cfg_file_resethud) // reset HUD
  59. max_lines = MAX_EXEC_LINES_RESETHUD
  60. g_execNum_resethud = read_lines(cfg_path, read_resethud_cfg, max_lines, max_chars)
  61. }
  62. stock read_lines(filepath[], readcfg, read_max_lines, max_chars) {
  63. if (!file_exists(filepath))
  64.   return 0
  65. new line, curline, txtlen
  66. new max_line = file_size(filepath, 1)
  67. new no_end = 1
  68. while (no_end) {
  69.   curline = line
  70.   if (readcfg == read_connect_cfg)
  71.    line = read_file(filepath, line, cl_exec_connect[curline], max_chars, txtlen)
  72.   else if (readcfg == read_putinserv_cfg)
  73.    line = read_file(filepath, line, cl_exec_putinserv[curline], max_chars, txtlen)
  74.   else
  75.    line = read_file(filepath, line, cl_exec_resethud[curline], max_chars, txtlen)
  76.   if (line==0 || line==max_line || max_line == read_max_lines)
  77.    no_end = 0
  78. }
  79. return curline + 1
  80. }
  81. public client_connect(id) {
  82. if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
  83.   return PLUGIN_CONTINUE
  84. #if LOOPBACK_NOT_EXEC == 1
  85. if (is_user_loopback(id))
  86.   return PLUGIN_CONTINUE
  87. #endif
  88. for (new i = 0; i < g_execNum_connect; ++i)
  89.   client_cmd(id, cl_exec_connect[i])
  90. return PLUGIN_CONTINUE
  91. }
  92. public client_putinserver(id) {
  93. if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
  94.   return PLUGIN_CONTINUE
  95. #if LOOPBACK_NOT_EXEC == 1
  96. if (is_user_loopback(id))
  97.   return PLUGIN_CONTINUE
  98. #endif
  99. set_task(0.1, "client_putinserver_exec", id)
  100. return PLUGIN_CONTINUE
  101. }
  102. public client_putinserver_exec(id){
  103. if (!is_user_connected(id) || is_user_bot(id))
  104.   return
  105. for (new i = 0; i < g_execNum_putinserv; ++i)
  106.   client_cmd(id, cl_exec_putinserv[i])
  107. }
  108. public player_spawn(id) {
  109. if (!get_pcvar_num(g_client_exec) || is_user_bot(id))
  110.   return PLUGIN_CONTINUE
  111. #if LOOPBACK_NOT_EXEC == 1
  112. if (is_user_loopback(id))
  113.   return PLUGIN_CONTINUE
  114. #endif
  115. for (new i = 0; i < g_execNum_resethud; ++i)
  116.   client_cmd(id, cl_exec_resethud[i])
  117. return PLUGIN_CONTINUE
  118. }
  119. #if LOOPBACK_NOT_EXEC == 1
  120. stock is_user_loopback(id)
  121. {
  122. new ips[32]
  123. get_user_ip(id, ips, 31, 1)
  124. return equal(ips, "loopback")
  125. }
  126. #endif
复制代码
发表于 2007-11-24 04:40:56 | 显示全部楼层 来自 中国–广东–深圳–南山区

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

KinSprite的经典啊~~~~
大概是WWCL没这个好用吧
回复

使用道具 举报

 楼主| 发表于 2007-11-24 20:51:57 | 显示全部楼层 来自 中国–安徽–合肥

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

感谢 AE86兄的回复 其实我想把这个用在自己的服上 但是因为以后要改代码 所以有一段没看懂确实麻烦 最近kinsprite都没见到了
回复

使用道具 举报

 楼主| 发表于 2007-12-2 18:56:51 | 显示全部楼层 来自 中国–安徽–合肥

回复: 请问KinSprite在他的client_exec中最后一段代码的作用以及这个插件与wwcl的区

kinsprite是不是很久不来了 有懂这段代码的帮忙解释一下呀
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表