搜索
查看: 5425|回复: 8

[AMXX 带源码] 集成SXE截图封禁机器码数据库保存

[复制链接]
发表于 2011-1-17 15:09:20 | 显示全部楼层 |阅读模式 来自 内蒙古呼和浩特
本帖最后由 Village 于 2011-1-17 15:26 编辑

找到这样的一个插件,但是不能正常运行!希望广大高手可以修改此问题!
      明明连接到数据库了,数据库已经自动创建了表格,但是只要封禁玩家就使服务器挂掉!提示不能连接到数据库!
       请看下面重启服务器时的错误日子:Start of error session.
L 01/17/2011 - 02:45:50: Info (map "de_dust2") (logfile "error_011711.log")
L 01/17/2011 - 02:45:50: [AMXX] Plugin ("sxe.amxx") is setting itself as failed.
L 01/17/2011 - 02:45:50: [AMXX] Plugin says: Could not connect to SQL database.
L 01/17/2011 - 02:45:50: [AMXX] Displaying debug trace (plugin "sxe.amxx")
L 01/17/2011 - 02:45:50: [AMXX] Run time error 1: forced exit
L 01/17/2011 - 02:45:50: [AMXX]    [0] sxe.sma::SQL_QueryHandle (line 283)
           
          翻译中文为:开始的误差会议。

我01/17/2011 - 02:45:50 Info(地图””)(de_dust2日志文件中“error_011711.log”)

我01/17/2011 - 02:45:50:[AMXX]的插件(“sxe.amxx”)是建立本身就失败了。

我01/17/2011 - 02:45:50:[AMXX]插件说:不可以连接到的SQL数据库。

我01/17/2011 - 02:45:50:[AMXX]显示调试跟踪sxe.amxx”)插件”

我01/17/2011 - 02:45:50:[AMXX]运行时错误1:被迫退出

我01/17/2011 - 02:45:50:[AMXX][0]sxe.sma:SQL_QueryHandle(第283)

顺便问问怎么修改权限
  1. sXe Bans 3.0 [MySQL Orpheu]
  2. Dejo la última versión del sXe Bans que utilizo en mis servidores la cual contiene:

  3. sXe Screenshot: Le saca una screenshot al usuario.
  4. - amx_sxe_screen "nick"

  5. sXe Ban: Bannea a un usuario, se puede especificar o no una razón.
  6. - amx_sxe_ban "nick" "razon"
  7. - amx_sxe_menu

  8. sXe UnBan: Permite sacar un ban sin la necesidad de ingresar al FTP del servidor.
  9. - amx_sxe_unban num (ej en amx_sxe_banlist)

  10. sXe BanList: Muestra la cantidad de usuarios banneados por sXe Injected y la razón si es que existe.
  11. - amx_sxe_banlist

  12. El plugin para funcionar necesita una base de datos y tener instalado el Orpheu (viene incluído en el ZIP).

  13. Para configurar la base de datos ingresen a addons/amxmodx/configs/sql.cfg y completan los datos que se piden y el plugin crea automáticamente la tabla con sus respectivas columnas.

复制代码
急等修复此问题!RMB答谢解决问题者!

本帖子中包含更多资源

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

×
 楼主| 发表于 2011-1-17 15:15:40 | 显示全部楼层 来自 内蒙古呼和浩特
源码
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <orpheu>
  4. #include <sqlx>

  5. #pragma semicolon 1;

  6. #define PLUGIN "sXeI Ban Local"
  7. #define VERSION "3.0"
  8. #define AUTHOR "ILUSION"

  9. #define FLAG_SCREEN ADMIN_KICK // Acceso requerido para sacar una screenshot en algun usuario. No es importan tener tanto acceso ya que no podra hacer nada malo
  10. #define FLAG_BAN ADMIN_LEVEL_H // Acceso requerido para los usuarios que poseen acceso al sXe Ban
  11. #define MASTER_BAN ADMIN_RCON // Acceso requerido para los usuarios que poseen permiso para bannear otros administradores (inclusive con inmunidad)

  12. #define sxe_file "sxe_local_ban.cfg"

  13. new MenuCallback, pointer;
  14. new sXeHID[72];

  15. new Handle:g_SqlTuple;

  16. new cvar_host, cvar_db, cvar_user, cvar_pass;

  17. public plugin_init()
  18. {
  19.         register_plugin(PLUGIN, VERSION, AUTHOR);
  20.        
  21.         register_concmd("amx_sxe_ban", "cmdBan", FLAG_BAN, "<nick> <razon>");
  22.         register_concmd("amx_sxe_menu", "cmdBanMenu", FLAG_BAN);
  23.         register_concmd("amx_sxe_screen", "cmdScreen", FLAG_SCREEN, "<nick>");
  24.         register_concmd("amx_sxe_banlist", "cmdBanList", FLAG_SCREEN);
  25.         register_concmd("amx_sxe_unban", "cmdUnBan", MASTER_BAN, "<id>");
  26.        
  27.         register_cvar("amx_sxe_bans", VERSION, FCVAR_SERVER); // CVAR GLOBAL - NO TOCAR!
  28.        
  29.         cvar_host = get_cvar_pointer("amx_sql_host");
  30.         cvar_db = get_cvar_pointer("amx_sql_db");
  31.         cvar_user = get_cvar_pointer("amx_sql_user");
  32.         cvar_pass = get_cvar_pointer("amx_sql_pass");
  33.        
  34.         new Host[32], Db[32], User[32], Pass[32];
  35.         get_pcvar_string(cvar_host, Host, charsmax(Host));
  36.         get_pcvar_string(cvar_db, Db, charsmax(Db));
  37.         get_pcvar_string(cvar_user, User, charsmax(User));
  38.         get_pcvar_string(cvar_pass, Pass, charsmax(Pass));
  39.                
  40.         g_SqlTuple = SQL_MakeDbTuple(Host, User, Pass, Db);
  41.         SQL_ThreadQuery(g_SqlTuple, "SQL_QueryHandle", "CREATE TABLE IF NOT EXISTS `sxebans` ( `id` INT( 32 ) NOT NULL AUTO_INCREMENT, `nick` VARCHAR( 32 ) NOT NULL, `ip` VARCHAR( 18 ) NOT NULL, `hid` VARCHAR( 34 ) NOT NULL, `admin` VARCHAR( 64 ) NOT NULL, `razon` VARCHAR( 250 ) NOT NULL default '-', PRIMARY KEY (`id`) ) COMMENT = 'sXe Bans'");
  42.        
  43.         pointer = get_cvar_pointer("__sxei_required");
  44. }

  45. public plugin_cfg()
  46.         server_cmd("amx_pausecfg add ^"%s^"", PLUGIN);

  47. public cmdBan(id, level, cid)
  48. {
  49.         if (!cmd_access(id, level, cid, 2) || !get_pcvar_num(pointer))
  50.                 return PLUGIN_HANDLED;
  51.        
  52.         new arg[32], razon[64];
  53.        
  54.         read_argv(1, arg, charsmax(arg));
  55.         read_argv(2, razon, charsmax(razon));
  56.                
  57.         new target;
  58.        
  59.         if (get_user_flags(id) & MASTER_BAN)
  60.                 target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF);
  61.         else
  62.                 target = cmd_target(id, arg, CMDTARGET_OBEY_IMMUNITY);
  63.                
  64.         if (!target)
  65.                 return PLUGIN_HANDLED;
  66.                                                
  67.         remove_quotes(razon);
  68.         funcion(id, target, razon);
  69.        
  70.         return PLUGIN_HANDLED;
  71. }

  72. public cmdBanMenu(id, level, cid)
  73. {
  74.         new name[32];
  75.         get_user_name(id, name, charsmax(name));
  76.        
  77.         if (!cmd_access(id, level, cid, 1) || !get_pcvar_num(pointer))
  78.                 return PLUGIN_HANDLED;
  79.        
  80.         new menu = menu_create("\wsXe Ban Menu", "menu_handler");
  81.        
  82.         new players[32], pnum, tempid;
  83.        
  84.         new szName[32], szTempid[10];
  85.        
  86.         get_players(players, pnum);
  87.        
  88.         MenuCallback = menu_makecallback("callback");
  89.        
  90.         new items[32];
  91.        
  92.         for (new i; i < pnum; i++)
  93.         {
  94.                 tempid = players[i];

  95.                 get_user_name(tempid, szName, 31);
  96.                 num_to_str(tempid, szTempid, 9);

  97.                 formatex(items, charsmax(items), "%s%s", szName, is_user_admin(tempid) ? "\r *" : "");
  98.                
  99.                 if (get_user_flags(tempid) & ADMIN_IMMUNITY && !(get_user_flags(id) & MASTER_BAN) || get_user_flags(tempid) & MASTER_BAN)
  100.                         menu_additem(menu, items, szTempid, 0, MenuCallback);
  101.                 else
  102.                         menu_additem(menu, items, szTempid, 0);
  103.         }

  104.         menu_setprop(menu, MPROP_BACKNAME, "Atras");
  105.         menu_setprop(menu, MPROP_NEXTNAME, "Siguiente");
  106.         menu_setprop(menu, MPROP_EXITNAME, "Salir");
  107.        
  108.         menu_display(id, menu, 0);
  109.        
  110.         return PLUGIN_HANDLED;
  111. }

  112. public cmdScreen(id, level, cid)
  113. {
  114.         if (!cmd_access(id, level, cid, 2) || !get_pcvar_num(pointer))
  115.                 return PLUGIN_HANDLED;
  116.                
  117.         new arg[32];
  118.         read_argv(1, arg, charsmax(arg));
  119.        
  120.         new target = cmd_target(id, arg, CMDTARGET_ALLOW_SELF);
  121.        
  122.         if (!target)
  123.                 return PLUGIN_HANDLED;
  124.                
  125.         new name[32];
  126.         get_user_name(target, name, charsmax(name));
  127.        
  128.         if (is_user_bot(target) || is_user_hltv(target))
  129.         {
  130.                 console_print(id, "No se le puede sacar una screenshot a %s debido a que es un %s", name, is_user_bot(id) ? "bot" : "HLTV");
  131.                 return PLUGIN_HANDLED;
  132.         }
  133.        
  134.         server_cmd("sxe_screen #%d #%d", get_user_userid(target), get_user_userid(id));
  135.         console_print(id, "Comenzo la transferencia de la screenshot de %s", name);

  136.         return PLUGIN_HANDLED;
  137. }

  138. public cmdBanList(id, level, cid)
  139. {
  140.         if (!cmd_access(id, level, cid, 1))
  141.                 return PLUGIN_HANDLED;
  142.        
  143.         new data[1];        data[0] = id;
  144.         SQL_ThreadQuery(g_SqlTuple, "SQL_BanList", "SELECT id, nick, ip, admin, razon FROM sxebans", data, 1);
  145.        
  146.         return PLUGIN_HANDLED;
  147. }

  148. public cmdUnBan(id, level, cid)
  149. {
  150.         if (!cmd_access(id, level, cid, 2))
  151.                 return PLUGIN_HANDLED;
  152.                
  153.         new arg[4];
  154.         read_argv(1, arg, charsmax(arg));
  155.        
  156.         new Query[72], data[1];
  157.         data[0] = id;
  158.        
  159.         formatex(Query, charsmax(Query), "SELECT id, nick, hid FROM sxebans WHERE id = %s", arg);
  160.        
  161.         SQL_ThreadQuery(g_SqlTuple, "SQL_UnBan", Query, data, 1);
  162.        
  163.         return PLUGIN_HANDLED;
  164. }       

  165. public callback(id, menu, item)
  166.         return ITEM_DISABLED;

  167. public menu_handler(id, menu, item)
  168. {
  169.         if (item == MENU_EXIT)
  170.         {
  171.                 menu_destroy(menu);
  172.                 return PLUGIN_HANDLED;
  173.         }

  174.         new data[6], iName[64];
  175.         new mnw, callback;
  176.         menu_item_getinfo(menu, item, mnw, data,5, iName, 63, callback);
  177.        
  178.         new target = str_to_num(data);
  179.        
  180.         if (is_user_connected(target))
  181.                 funcion(id, target);

  182.         return PLUGIN_HANDLED;
  183. }

  184. funcion(id, target, const razon[] = "")
  185. {
  186.         new nuser[32], nadmin[64], ip[32];
  187.        
  188.         get_user_name(id, nadmin, charsmax(nadmin));
  189.         get_user_name(target, nuser, charsmax(nuser));
  190.         get_user_ip(target, ip, charsmax(ip), 1);
  191.        
  192.         if (is_user_bot(target) || is_user_hltv(target))
  193.         {
  194.                 new msg[192];
  195.                 formatex(msg, charsmax(msg), "%s no puede ser banneado debido a que es un %s", nuser, is_user_bot(id) ? "bot" : "HLTV");
  196.                
  197.                 console_print(id, msg);
  198.                        
  199.                 return PLUGIN_HANDLED;
  200.         }
  201.        
  202.         new OrpheuHook:handlePrintf = OrpheuRegisterHook(OrpheuGetFunction("Con_Printf"), "Con_Printf");
  203.        
  204.         server_cmd("sxe_userhid #%d", get_user_userid(target));
  205.         server_exec();
  206.        
  207.         OrpheuUnregisterHook(handlePrintf);

  208.         // mensaje: sxei_userhid: [XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX]
  209.         replace(sXeHID, charsmax(sXeHID), "sxei_userhid: ", "");
  210.         replace(sXeHID, charsmax(sXeHID), "[", "");
  211.         replace(sXeHID, charsmax(sXeHID), "]", "");
复制代码
回复

使用道具 举报

 楼主| 发表于 2011-1-17 15:17:32 | 显示全部楼层 来自 内蒙古呼和浩特
接上面的第236行开始
  1. trim(sXeHID);
  2.                        
  3.         client_cmd(0, "spk ^"vox/hello and die^"");
  4.         client_print(0, print_chat, "<< sXe Injected >>");
  5.         client_print(0, print_chat, "NICK: %s || IP: %s", nuser, ip);
  6.         client_print(0, print_chat, "CASTIGO: Ban Local");
  7.        
  8.         log_amx("ADMIN: %s banneo a %s via sXe Injected", nadmin, nuser);
  9.        
  10.         replace_all(nuser, charsmax(nuser), "'", "''");
  11.         replace_all(nadmin, charsmax(nadmin), "'", "''");
  12.        
  13.         new g_query[512], data[1];
  14.        
  15.         data[0] = id;
  16.                
  17.         if (razon[0])
  18.         {
  19.                 client_print(0, print_chat, "RAZON: %s", razon);
  20.                 client_print(target, print_console, "Fuiste banneado del servidor via sXe Injected");
  21.                 client_print(target, print_console, "La razon de tu ban fue: %s", razon);
  22.                        
  23.                 formatex(g_query, charsmax(g_query), "INSERT INTO sxebans (nick, ip, hid, admin, razon) VALUES ('%s', '%s', '%s', '%s', '%s', %s)", nuser, ip, sXeHID, nadmin, razon);
  24.         }
  25.         else
  26.         {
  27.                 client_print(target, print_console, "Fuiste banneado del servidor via sXe Injected");
  28.                 client_print(target, print_console, "La razon de tu ban fue: -");
  29.                 formatex(g_query, charsmax(g_query), "INSERT INTO sxebans (nick, ip, hid, admin, server) VALUES ('%s', '%s', '%s', '%s')", nuser, ip, sXeHID, nadmin);
  30.         }
  31.        
  32.         server_cmd("sxe_ban ^"#%d^"", get_user_userid(target));
  33.        
  34.         SQL_ThreadQuery(g_SqlTuple, "SQL_QueryHandle", g_query, data, 1);
  35.        
  36.         return PLUGIN_HANDLED;
  37. }

  38. public OrpheuHookReturn:Con_Printf(const a[], const message[])
  39. {
  40.         copy(sXeHID, charsmax(sXeHID), message);
  41.         return OrpheuSupercede;
  42. }

  43. public SQL_QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
  44. {
  45.         if(FailState == TQUERY_CONNECT_FAILED)
  46.                 return set_fail_state("Could not connect to SQL database.");
  47.         else if(FailState == TQUERY_QUERY_FAILED)
  48.                 return set_fail_state("Query failed.");
  49.    
  50.         if(Errcode)
  51.                 return log_amx("Error on query: %s",Error);
  52.    
  53.         return PLUGIN_CONTINUE;
  54. }

  55. public SQL_BanList(FailState, Handle:Query, Error[], Errcode, Data[], DataSize[])
  56. {
  57.         if(FailState == TQUERY_CONNECT_FAILED)
  58.                 return set_fail_state("Could not connect to SQL database.");
  59.         else if(FailState == TQUERY_QUERY_FAILED)
  60.                 return set_fail_state("Query failed.");
  61.    
  62.         if(Errcode)
  63.                 return log_amx("Error on query: %s",Error);
  64.        
  65.         new id = Data[0];
  66.                
  67.         if (!SQL_NumResults(Query))
  68.         {
  69.                 console_print(id, "No hay usuarios banneados.");
  70.                        
  71.                 return PLUGIN_CONTINUE;
  72.         }       
  73.                
  74.         new qID = SQL_FieldNameToNum(Query, "id");
  75.         new qName = SQL_FieldNameToNum(Query, "nick");
  76.         new qAdmin = SQL_FieldNameToNum(Query, "admin");
  77.         new qRazon = SQL_FieldNameToNum(Query, "razon");
  78.         new qIP = SQL_FieldNameToNum(Query, "ip");
  79.        
  80.         new uID[32], uName[32], uIP[32], uAdmin[64], uRazon[255];
  81.         new bans;
  82.        
  83.         while(SQL_MoreResults(Query))
  84.         {
  85.                 SQL_ReadResult(Query, qID, uID, charsmax(uID));
  86.                 SQL_ReadResult(Query, qName, uName, charsmax(uName));
  87.                 SQL_ReadResult(Query, qIP, uIP, charsmax(uIP));
  88.                 SQL_ReadResult(Query, qAdmin, uAdmin, charsmax(uAdmin));
  89.                 SQL_ReadResult(Query, qRazon, uRazon, charsmax(uRazon));
  90.                
  91.                 console_print(id, "#%s.  NICK: %s - IP: %s - ADMIN: %s - RAZON: %s", uID, uName, uIP, uAdmin, uRazon);
  92.                
  93.                 ++bans;
  94.                
  95.                 SQL_NextRow(Query);
  96.         }
  97.        
  98.         console_print(id, "^nsXe Bans: %d - Para remover un ban usar amx_sxe_unban < id >", bans);
  99.        
  100.         return PLUGIN_CONTINUE;
  101. }

  102. public SQL_UnBan(FailState,Handle:Query,Error[],Errcode,Data[],DataSize)
  103. {
  104.         if(FailState == TQUERY_CONNECT_FAILED)
  105.                 return set_fail_state("Could not connect to SQL database.");
  106.         else if(FailState == TQUERY_QUERY_FAILED)
  107.                 return set_fail_state("Query failed.");
  108.    
  109.         if(Errcode)
  110.                 return log_amx("Error on query: %s",Error);
  111.                
  112.         new id = Data[0];
  113.        
  114.         if (!SQL_NumResults(Query))
  115.         {
  116.                 console_print(id, "ID invalido.");
  117.                 return PLUGIN_CONTINUE;
  118.         }       
  119.        
  120.         new name[64];
  121.         get_user_name(id, name, charsmax(name));

  122.         new qID = SQL_FieldNameToNum(Query, "id");
  123.         new qName = SQL_FieldNameToNum(Query, "nick");
  124.         new qHID = SQL_FieldNameToNum(Query, "hid");

  125.         new uID[5], uName[32], uHID[40];
  126.        
  127.         while(SQL_MoreResults(Query))
  128.         {
  129.                 SQL_ReadResult(Query, qID, uID, charsmax(uID));
  130.                 SQL_ReadResult(Query, qName, uName, charsmax(uName));
  131.                 SQL_ReadResult(Query, qHID, uHID, charsmax(uHID));
  132.                
  133.                 log_amx("ADMIN %s: le saco el ban a %s (N. #%s)", name, uName, uID);
  134.                 console_print(id, "[AMXX] Le sacaste el ban a %s (N. #%s)", uName, uID);
  135.                
  136.                 SQL_NextRow(Query);
  137.         }
  138.        
  139.         new error[512], errno;
  140.         new Handle:Remove = SQL_Connect(g_SqlTuple, errno, error, charsmax(error));
  141.        
  142.         SQL_QueryAndIgnore(Remove, "DELETE FROM sxebans WHERE id = %s", uID);
  143.         SQL_FreeHandle(Remove);
  144.        
  145.         new file = fopen(sxe_file, "rt");
  146.         new szLine[40], linea;

  147.         while(!feof(file))
  148.         {       
  149.                 fgets(file, szLine, charsmax(szLine));
  150.                 trim(szLine);
  151.                
  152.                 if (equal(szLine, uHID))
  153.                 {
  154.                         write_file(sxe_file, "", linea);
  155.                         delete_empty_lines(sxe_file);
  156.                         break;
  157.                 }
  158.                
  159.                 linea++;
  160.         }
  161.        
  162.         fclose(file);
  163.                
  164.         return PLUGIN_CONTINUE;
  165. }

  166. /* Exolent */
  167. delete_empty_lines(const filename[])
  168. {
  169.         static const temp_filename[] = "tempfile.txt";
  170.    
  171.         new f = fopen(filename, "rt");
  172.    
  173.         if (!f) return -1;
  174.    
  175.         new lines = 0;
  176.         new t = fopen(temp_filename, "wt");
  177.    
  178.         static data[512];
  179.        
  180.         while (!feof(f))
  181.         {
  182.                 fgets(f, data, sizeof(data) - 1);
  183.                 if( data[0] && data[0] != '^n' )
  184.                 {
  185.                         fputs(t, data);
  186.                 }
  187.                 else
  188.                 {
  189.                         lines++;
  190.                 }
  191.         }
  192.    
  193.         fclose(f);
  194.         fclose(t);
  195.    
  196.         delete_file(filename);
  197.    
  198.         rename_file(temp_filename, filename, 1);
  199.    
  200.         return lines;
  201. }
  202. /* Exolent */

  203. public plugin_end()
  204.     SQL_FreeHandle(g_SqlTuple);
复制代码
回复

使用道具 举报

 楼主| 发表于 2011-1-17 15:44:45 | 显示全部楼层 来自 内蒙古呼和浩特
如果有意者不愿意分享修改好的可以加我QQ私聊:1178158588
回复

使用道具 举报

 楼主| 发表于 2011-1-18 15:47:28 | 显示全部楼层 来自 内蒙古呼和浩特
急等解决!顶起来!
回复

使用道具 举报

 楼主| 发表于 2011-1-19 00:39:02 | 显示全部楼层 来自 内蒙古呼和浩特
再次顶起!
回复

使用道具 举报

 楼主| 发表于 2011-1-25 22:26:57 | 显示全部楼层 来自 内蒙古
急等高手解决!以RMB回报!
回复

使用道具 举报

发表于 2011-1-26 12:30:57 | 显示全部楼层 来自 广西南宁
本帖最后由 lovehuai 于 2011-1-26 13:28 编辑

trim(sXeHID);
这个是特征码吧
封成模块要么

粗略看了下代码
Sxe的Ban跟HLDS的一样是写Cfg的
Ban的时候 Sxe的模块会写入Cfg 然后插件写到数据库
UnBan把被封的从Cfg中删除
这玩意你用不用数据库都行啊
难道Sxe会删除那个Cfg?
除非你是多个服务器同步Bans列表否者完全用不上啊
回复

使用道具 举报

发表于 2011-1-26 14:39:13 | 显示全部楼层 来自 广东惠州
这个插件用的是异步线程来连接数据库的,每次执行查询都要重新连接MYSQL。
不过从代码看似乎没什么问题.
回复

使用道具 举报

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

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