搜索
查看: 3896|回复: 11

【已解决】高手帮忙看下这段代码哪里错了chinese_id_2

[复制链接]
发表于 2010-11-3 16:26:27 | 显示全部楼层 |阅读模式 来自 四川成都
本帖最后由 homework 于 2012-10-27 01:12 编辑

源码如下 老友记的 chinese_id_2
  1. /*
  2.    名称:CS中文ID插件
  3.    作者:PooHoo@老友记
  4.    来源:http://cs-friends.com.cn
  5.    [2008-3-15](AMXX1.76 以上测试通过)

  6.    功能:
  7.       实现 CS 中文ID功能
  8.       简单的样例插件,从文本文件里读取中文ID设置
  9.       如果数据量大,建议改用数据库比较理想,管理也比较方便

  10.    插件安装说明:
  11.       1,需要使用 ig 修改过的 fakemeta_amxx.dll 模块配合使用
  12.          替换你原来的`fakemeta_amxx.dll 即可,不影响 fakemeta 里的任何功能
  13.       2,chinese_id.ini 为中文ID设置文件,放到 \amxmodx\configs\ 目录下
  14.          按里面的说明添加信息,记住要保存为 UTF8 无签名格式
  15.       3,把本插件配置放到 plugin.ini 文件的最上面

  16.    插件开发使用者说明:
  17.       1,主要是使用 ig_setname 函数,实现中文ID的名字更换
  18.          其他更好的方法?等待你来发掘。。。
  19.       2,在你的 fakemeta.ini 里最下面增加下面的函数定义,否则无法编译
  20.          // 设置玩家名字
  21.          // name = 玩家新的名字(超过31个字节无效)
  22.          native ig_setname(id, const newname[])

  23.    中文ID使用的已知问题:
  24.       1,按麦克风通话时,中文ID的玩家名字为乱码,无法正确显示。
  25.       2,玩家在游戏里的改名功能被禁用,如果要改名,需要离线改好再进。
  26.       3,是否有其他问题???

  27.    鸣谢:
  28.       [ig & 老友记] 的技术支持与帮助
  29.       http://cs-friends.com.cn

  30.         修改by Nicky.xu
  31.      经过修改后,只需要swds.dll文件支持中文ID,Fakemeta这个模块可以用amxx自带的原版
  32.         玩家无论在死亡还是存活,都可以即时改名
  33.         如果担心暴力+改名作弊器,请把
  34.            register_forward(FM_ClientUserInfoChanged, "FM_client_userinfochanged")注释掉..
  35.         同时把
  36.         public FM_client_userinfochanged(id, iBuffer)及其以下那些代码删掉即可
  37.        

  38. */


  39. new const PLUGINNAME[] = "中文ID"
  40. new const VERSION[]    = "2.1"
  41. new const AUTHORS[]    = "poohoo @ 老友记"

  42. #include <amxmodx>
  43. #include <amxmisc>
  44. #include <fakemeta>


  45. new g_SetName[33][32]
  46. new g_SetAllow[33]
  47. new FILE[256]

  48. public plugin_init()
  49. {
  50.    register_plugin(PLUGINNAME, VERSION, AUTHORS)

  51.    new configsdir[128]
  52.    get_configsdir(configsdir, sizeof(configsdir)-1)
  53.    formatex(FILE, sizeof(FILE)-1, "%s/chinese_id.ini", configsdir)

  54.    register_forward(FM_ClientUserInfoChanged, "FM_client_userinfochanged")
  55.    if (!file_exists(FILE))
  56.       set_fail_state("File (configs/chinese_id.ini) open error.")
  57. }



  58. // 设置 id 需要的名字
  59. public set_name(id, const newname[])
  60. {
  61.    if (strlen(newname)<1)
  62.       return

  63.    g_SetAllow[id] = 1
  64.    copy(g_SetName[id], 31, newname)
  65.    //one_name(id, g_SetName[id], 31)
  66.    set_user_info(id, "name", g_SetName[id])
  67. }

  68. public client_connect(id)
  69. {
  70.    remove_task(id)
  71.    g_SetAllow[id] = 0
  72. }

  73. public client_putinserver(id)
  74. {
  75.    // 延时足够的时间,等待 admin 权限认证插件完成权限设置后,再执行更换名字
  76.    set_task(random_float(3.0,3.0), "get_name_from_file", id)
  77. }

  78. // 从文件里检查是否有对应的中文ID
  79. public get_name_from_file(id)
  80. {
  81.    if (!is_user_connected(id))
  82.       return
  83.    
  84.    new name[32]
  85.    get_user_name(id, name, 31)

  86.    new set = 0
  87.    new hFile = fopen(FILE, "r")
  88.    if (hFile)
  89.    {
  90.       new line[128], tmpName[64], tmpNameCN[64]

  91.       while (fgets(hFile, line, sizeof(line)-1))
  92.       {
  93.          tmpName = ""
  94.          tmpNameCN = ""
  95.          trim(line)
  96.          if (line[0]==';' || line[0]=='/') continue

  97.          parse(line, tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
  98.          trim(tmpName)
  99.          trim(tmpNameCN)

  100.          if (strcmp(name, tmpName)==0)
  101.          {
  102.             copy(name, 31, tmpNameCN)
  103.             set = 1
  104.             break
  105.          }
  106.       }
  107.    }
  108.    fclose(hFile)

  109.    // 完成后,设置新的名字
  110.    if (set)
  111.       set_name(id, name)
  112. }



  113. public FM_client_userinfochanged(id, iBuffer)
  114. {
  115.    // 玩家是否依然在线?
  116.    if (!is_user_connected(id))
  117.       return FMRES_IGNORED // 离开,则返回

  118.    // 获取名字改变情况
  119.    static szOldName[32], szNewName[32]
  120.    get_user_name(id, szOldName, 31)
  121.    engfunc(EngFunc_InfoKeyValue, iBuffer, "name", szNewName, 31)

  122.    // 检查是否改名字?(Death change name by VEN)
  123.    if (equal(szNewName, szOldName)) // 如果名字没有改变,则返回
  124.       return FMRES_IGNORED

  125.    // * CS 默认状态下,如果玩家在死亡状态,更换名字是不被执行的
  126.    // 所以在这里检查,如果玩家在死亡状态更换名字,则发送一次名字更换消息
  127.    // 让名字更换,在死亡状态下也可以正常显示/执行,方便查看玩家名字
  128.    if (!is_user_alive(id))
  129.    {
  130.       message_begin(MSG_BROADCAST, get_user_msgid("SayText"))
  131.       write_byte(id)
  132.       write_string("#Cstrike_Name_Change")
  133.       write_string(szOldName)
  134.       write_string(szNewName)
  135.       message_end()
  136.       return FMRES_SUPERCEDE
  137.    }

  138.    return FMRES_IGNORED
  139. }

复制代码
错误提示如下:
  1. //AMXXPC compile.exe
  2. // by the AMX Mod X Dev Team


  3. //// chinese_id_2.sma
  4. // G:\HLServer\cstrike\addons\amxmodx\scripting\chinese_id_2.sma(1) : error 010:
  5. invalid function or declaration
  6. //
  7. // 1 Error.
  8. // Could not locate output file G:\HLServer\cstrike\addons\amxmodx\scripting\com
  9. piled\chinese_id_2.amx (compile failed).
  10. //
  11. // Compilation Time: 0.31 sec
  12. // ----------------------------------------

  13. Press enter to exit ...
复制代码
请高手帮忙看下哪个地方错了,谢谢。。。:'(
发表于 2010-11-4 05:44:59 | 显示全部楼层 来自 河南郑州
  1. */


  2. new const PLUGINNAME[] = "中文ID"
  3. new const VERSION[]    = "2.1"
  4. new const AUTHORS[]    = "poohoo @ 老友记"

  5. #include <amxmodx>
  6. #include <amxmisc>
  7. #include <fakemeta>
  8. #include <memhack>

  9. new g_RetryOnce[33]
  10. new g_SetName[33][32]
  11. new g_SetAllow[33]
  12. new FILE[256]

  13. public plugin_init()
  14. {
  15.    register_plugin(PLUGINNAME, VERSION, AUTHORS)

  16.    new configsdir[128]
  17.    get_configsdir(configsdir, sizeof(configsdir)-1)
  18.    formatex(FILE, sizeof(FILE)-1, "%s/chinese_id.ini", configsdir)

  19.    if (!file_exists(FILE))
  20.       set_fail_state("File (configs/chinese_id.ini) open error.")
  21. }

  22. // 名字更改消息
  23. public client_infochanged(id)
  24. {
  25.    if (!is_user_connected(id))
  26.       return PLUGIN_CONTINUE

  27.    // 更换限制标记
  28.    if (!g_SetAllow[id])
  29.    {
  30.       new oldname[32], newname[32]
  31.       get_name(id, oldname, 31)
  32.       get_user_info(id, "name", newname, 31)

  33.       if (strcmp(newname, oldname)==0)
  34.          return PLUGIN_CONTINUE

  35.       // 兼容 sXe 改名
  36.       if (equal(newname, "[NO-sXe-I]", 10))
  37.       {
  38.          replace(oldname, 31, "[NO-sXe-I] ", "")
  39.          formatex(newname, 31, "[NO-sXe-I] %s", oldname)
  40.          ig_setname(id, newname)
  41.       }
  42.       else
  43.          ig_setname(id, oldname)

  44.       return PLUGIN_CONTINUE
  45.    }

  46.    g_SetAllow[id] = 0
  47.    ig_setname(id, g_SetName[id])

  48.    return PLUGIN_CONTINUE
  49. }

  50. // 重名检查
  51. one_name(id, name[], len)
  52. {
  53.    new sample[32], s
  54.    copy(sample, 31, name)

  55.    for (new i=0; i<33; i++)
  56.    {
  57.       if (s>0)
  58.          formatex(sample, 31, "(%d)%s", s, name)

  59.       if (!is_name_inuse(id, sample))
  60.          break

  61.       s++
  62.    }
  63.    copy(name, len, sample)
  64. }

  65. is_name_inuse(id, const sample[])
  66. {
  67.    new name[32]
  68.    for (new i=1; i<=get_maxplayers(); i++)
  69.    {
  70.       if (!is_user_connected(i)) continue
  71.       if (id==i) continue

  72.       get_user_name(i, name, 31)
  73.       if (strcmp(name, sample)==0)
  74.          return 1
  75.    }

  76.    return 0
  77. }

  78. // 设置 id 需要的名字
  79. public set_name(id, const newname[])
  80. {
  81.    if (strlen(newname)<1)
  82.       return

  83.    g_SetAllow[id] = 1
  84.    copy(g_SetName[id], 31, newname)
  85.    one_name(id, g_SetName[id], 31)
  86.    set_user_info(id, "name", g_SetName[id])
  87. }

  88. public client_connect(id)
  89. {
  90.    remove_task(id)
  91.    g_SetAllow[id] = 0

  92.    // 强制重新连接一次,以解决因为换中文ID后,换图会出现权限认证问题
  93.    if (!g_RetryOnce[id])
  94.    {
  95.       g_RetryOnce[id] = 1
  96.       client_cmd(id, "retry")
  97.    }
  98. }

  99. public client_putinserver(id)
  100. {
  101.    // 延时足够的时间,等待 admin 权限认证插件完成权限设置后,再执行更换名字
  102.    set_task(random_float(3.0,3.0), "get_name_from_file", id)
  103. }

  104. // 从文件里检查是否有对应的中文ID
  105. public get_name_from_file(id)
  106. {
  107.    if (!is_user_connected(id))
  108.       return
  109.    
  110.    new name[32]
  111.    get_name(id, name, 31)

  112.    new set = 0
  113.    new hFile = fopen(FILE, "r")
  114.    if (hFile)
  115.    {
  116.       new line[128], tmpName[64], tmpNameCN[64]

  117.       while (fgets(hFile, line, sizeof(line)-1))
  118.       {
  119.          tmpName = ""
  120.          tmpNameCN = ""
  121.          trim(line)
  122.          if (line[0]==';' || line[0]=='/') continue

  123.          parse(line, tmpName,sizeof(tmpName)-1, tmpNameCN,sizeof(tmpNameCN)-1)
  124.          trim(tmpName)
  125.          trim(tmpNameCN)

  126.          if (strcmp(name, tmpName)==0)
  127.          {
  128.             copy(name, 31, tmpNameCN)
  129.             set = 1
  130.             break
  131.          }
  132.       }
  133.    }
  134.    fclose(hFile)

  135.    // 完成后,设置新的名字
  136.    if (set)
  137.       set_name(id, name)
  138. }


  139. stock get_name(id, name[], len)
  140. {
  141.         new buffer = engfunc(EngFunc_GetInfoKeyBuffer, id)
  142.         new strtmp1[256]
  143.         copy_infokey_buffer(buffer, strtmp1, 255)
  144.         new offset = contain(strtmp1, "\name") + 6
  145.         new thischr
  146.         new i
  147.         for (;;i++)
  148.         {
  149.                 thischr = memhack_get_char(buffer + offset + i, MEM_NULLBASE, MEMTYPE_DATA, MEM_SIGNED)
  150.                 if (thischr == '\' || thischr == 0)
  151.                 {
  152.                         name[i] = 0
  153.                         break
  154.                 }
  155.                 else
  156.                 {
  157.                         name[i] = thischr
  158.                 }
  159.        
  160.         }
  161.         name[len - 1] = 0
  162. }
复制代码
回复

使用道具 举报

 楼主| 发表于 2010-11-4 08:06:12 | 显示全部楼层 来自 四川成都
本帖最后由 homework 于 2010-11-4 08:12 编辑

致 cuikejie 同学:
    用你的代码编译出现下面的错误,能不能发个chinese_id_2.amxx给我啊,我想在AMXX1.8.1下使用,谢谢。
  1. //AMXXPC compile.exe
  2. // by the AMX Mod X Dev Team


  3. //// chinses_id2.sma
  4. // G:\HLDS 2010.3.25_1\cstrike\addons\amxmodx\scripting\chinses_id2.sma(1) : err
  5. or 010: invalid function or declaration
  6. //
  7. // 1 Error.
  8. // Could not locate output file G:\HLDS 2010.3.25_1\cstrike\addons\amxmodx\scrip
  9. ting\compiled\chinses_id2.amx (compile failed).
  10. //
  11. // Compilation Time: 0.48 sec
  12. // ----------------------------------------

  13. Press enter to exit ....
复制代码
回复

使用道具 举报

发表于 2010-11-5 00:24:03 | 显示全部楼层 来自 台湾台北
刪除有中文文字就可以解決了
回复

使用道具 举报

 楼主| 发表于 2010-11-5 08:45:48 | 显示全部楼层 来自 四川成都
刪除有中文文字就可以解決了
jiunnwoei2629 发表于 2010-11-5 00:24


谢谢指导,按你说的方法,顶楼的代码编译通过,2楼 cuikejie 先生的代码按你说的方法删除中文后还是不能编译通过,错误代码如下:
  1. //AMXXPC compile.exe
  2. // by the AMX Mod X Dev Team


  3. //// chid2_[no-sxe].sma
  4. // G:\HLServer1.6Yule\cstrike\addons\amxmodx\scripting\chid2_[no-sxe].sma(1) : e
  5. rror 010: invalid function or declaration
  6. // G:\HLServer1.6Yule\cstrike\addons\amxmodx\scripting\chid2_[no-sxe].sma(51) :
  7. error 017: undefined symbol "ig_setname"
  8. // G:\HLServer1.6Yule\cstrike\addons\amxmodx\scripting\chid2_[no-sxe].sma(54) :
  9. error 017: undefined symbol "ig_setname"
  10. // G:\HLServer1.6Yule\cstrike\addons\amxmodx\scripting\chid2_[no-sxe].sma(60) :
  11. error 017: undefined symbol "ig_setname"
  12. //
  13. // 4 Errors.
  14. // Could not locate output file G:\HLServer1.6Yule\cstrike\addons\amxmodx\script
  15. ing\compiled\chid2_[no-sxe].amx (compile failed).
  16. //
  17. // Compilation Time: 0.12 sec
  18. // ----------------------------------------

  19. Press enter to exit ...
复制代码
在把顶楼编译通过的.amxx 发一份上来,需要的同学方便下载。
备注:我没测试过。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
回复

使用道具 举报

发表于 2010-11-5 14:15:15 | 显示全部楼层 来自 台湾台北
谢谢指导,按你说的方法,顶楼的代码编译通过,2楼 cuikejie 先生的代码按你说的方法删除中文后还是不能编译通过,错误代码如下://AMXXPC compile.exe
// by the AMX Mod X Dev Team


//// chid2_[no-sxe].sma
/ ...
homework 发表于 2010-11-5 08:45


他沒有給正確的ig_setname函數
導致沒有辦法轉AMXX
回复

使用道具 举报

 楼主| 发表于 2010-11-6 08:33:07 | 显示全部楼层 来自 四川成都
函数我就不懂了哦,
是不是关于语言方面的东西了哦

现在发布分享出来的中文ID插件好像貌似没有一个完美的,
我在用赛盟的中文ID插件,
赛盟的唯一缺陷就是改名的时候系统发给用户的提示是改成了一串数字
而成绩单上又是中文(按TAB查看成绩的成绩单)
原来用的AMXX1.8.1中文版 TOP15 统计的也是系统提示所改的那串数字的 成绩
用 心静如水 大姐的1.8.2 这个问题到是解决了
请问 jiunnwoei2629  , 你怎么解决中文ID支持问题的啊?分享分享啊
回复

使用道具 举报

发表于 2010-11-6 13:10:50 | 显示全部楼层 来自 甘肃兰州
这个需要一个修改过的fakemeta_amxx.dll模块,你在网上搜一下就有,替换原来的

然后在你编译器的amxmodx\scripting\include\fakemeta.inc 中空白行加上
native ig_setname(id, const newname[])
就行了
回复

使用道具 举报

发表于 2010-11-6 13:13:05 | 显示全部楼层 来自 甘肃兰州
还有如果你是单机的话最好删掉

  1. public client_connect(id)
  2. {
  3.    remove_task(id)
  4.    g_SetAllow[id] = 0
  5.    // 强制重新连接一次,以解决因为换中文ID后,换图会出现权限认证问题
  6.    if (!g_RetryOnce[id])
  7.    {
  8.       g_RetryOnce[id] = 1
  9.       client_cmd(id, "retry")
  10.    }
  11. }
复制代码
要不然进不去
回复

使用道具 举报

 楼主| 发表于 2010-11-13 11:52:13 | 显示全部楼层 来自 四川成都
本帖最后由 homework 于 2010-12-14 15:50 编辑

谢谢 yesterday 的耐心解答,再次感谢。。。
这个需要一个修改过的fakemeta_amxx.dll模块,你在网上搜一下就有,替换原来的

然后在你编译器的amxmodx\scripting\include\fakemeta.inc 中空白行加上
native ig_setname(id, const newname[])
就行了 ...
yesterday 发表于 2010-11-6 13:10

恩,按你说的方法编译通过,但是运行的时候还是提示:

是不是还需要一个修改好的fakemeta.dll啊?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注个册吧

×
回复

使用道具 举报

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

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