HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. CheatKey Detector
  3. v1.2 by mforce
  4.  
  5. Changes:
  6.  
  7. v1.1 - Removed hardcoded things, added stock for sendcmd, not connected bug fixed.
  8. v1.2 - Cvars moved to the file for settings.
  9. */
  10.  
  11. #include <amxmodx>
  12.  
  13. new const PLUGIN[] = "CheatKey Detector";
  14. new const VERSION[] = "1.2";
  15. new const AUTHOR[] = "mforce";
  16.  
  17.  
  18. #if AMXX_VERSION_NUM < 183
  19. const MAX_PLAYERS = 32;
  20. #endif
  21. const SVC_DIRECTOR_STUFFTEXT = 10;
  22.  
  23. enum _:PCVARS{iKickLimit, iIsQuit};
  24. new g_iCvars[PCVARS], g_iCheatKeysSize, g_iKickLimit[MAX_PLAYERS+1];
  25. new Array:g_aCheatKeys;
  26.  
  27. public plugin_init() {
  28. register_plugin(PLUGIN, VERSION, AUTHOR);
  29.  
  30. register_cvar("cheatkey_detector", VERSION, FCVAR_SERVER | FCVAR_SPONLY);
  31. register_clcmd("CKD", "CheatKey_Detected");
  32. g_aCheatKeys = ArrayCreate(32);
  33. }
  34.  
  35. public plugin_cfg() {
  36. new szLine[64], szFileName[128], iFilePointer;
  37. get_localinfo("amxx_configsdir", szFileName, charsmax(szFileName));
  38. add(szFileName, charsmax(szFileName), "/CheatKeys.ini");
  39.  
  40. iFilePointer = fopen(szFileName, "rt");
  41. if(!iFilePointer) set_fail_state("Can't read config file for CheatKeys.");
  42.  
  43. new iSection;
  44. new szKey[32], szSign[3], szValue[3];
  45. while(!feof(iFilePointer)) {
  46. fgets(iFilePointer, szLine, charsmax(szLine)); trim(szLine);
  47. if(!szLine[0] || szLine[0] == ';' || szLine[0] == '#') continue;
  48.  
  49. if(szLine[0] == '[') {
  50. if(equali(szLine, "[settings]")) iSection = 1;
  51. else if(equali(szLine, "[keys]")) iSection = 2;
  52. else iSection = 0;
  53.  
  54. continue;
  55. }
  56.  
  57. if(iSection == 1 && parse(szLine, szKey, charsmax(szKey), szSign, charsmax(szSign), szValue, charsmax(szValue))) {
  58. if(equali(szKey, "ckd_kicklimit"))
  59. g_iCvars[iKickLimit] = str_to_num(szValue);
  60. else if(equali(szKey, "ckd_quit"))
  61. g_iCvars[iIsQuit] = str_to_num(szValue);
  62. }
  63. else if(iSection == 2 && parse(szLine, szKey, charsmax(szKey)))
  64. ArrayPushString(g_aCheatKeys, szKey);
  65. }
  66. fclose(iFilePointer);
  67.  
  68. g_iCheatKeysSize = ArraySize(g_aCheatKeys);
  69. if(!g_iCheatKeysSize) set_fail_state("Error! The array doesn't contain any CheatKeys.");
  70. }
  71.  
  72.  
  73. public client_authorized(id) {
  74. if(is_user_bot(id) || is_user_hltv(id)) return;
  75.  
  76. new szCheatKey[32];
  77. for(new i; i < g_iCheatKeysSize; i++) {
  78. ArrayGetString(g_aCheatKeys, i, szCheatKey, charsmax(szCheatKey));
  79. SendCmd(id, "bind ^"%s^" ^"CKD %s^"", szCheatKey, szCheatKey);
  80. }
  81. }
  82.  
  83. public CheatKey_Detected(id) {
  84. if(!is_user_connected(id)) return PLUGIN_HANDLED;
  85.  
  86. new szKey[32]; read_args(szKey, charsmax(szKey));
  87. new szName[32]; get_user_name(id, szName, charsmax(szName));
  88. new szIP[32]; get_user_ip(id, szIP, charsmax(szIP), 1);
  89. new szSteamId[32]; get_user_authid(id, szSteamId, charsmax(szSteamId));
  90.  
  91. log_to_file("CheatKeyLog.log", "^n[DETECTED]: ^"%s^" used key '%s' (IP: '%s', STEAMID: '%s').", szName, szKey, szIP, szSteamId);
  92.  
  93. if(g_iCvars[iKickLimit] > 0) {
  94. if(++g_iKickLimit[id] >= g_iCvars[iKickLimit]) {
  95. if(g_iCvars[iIsQuit] == 1)
  96. SendCmd(id, "quit");
  97. else
  98. server_cmd("kick #%d ^"Too much CheatKeys pressed.^"", get_user_userid(id));
  99. }
  100. }
  101.  
  102. return PLUGIN_HANDLED;
  103. }
  104.  
  105. public client_disconnect(id) {
  106. g_iKickLimit[id] = 0;
  107. }
  108.  
  109. public plugin_end() {
  110. ArrayDestroy(g_aCheatKeys);
  111. }
  112.  
  113. stock SendCmd(id, const szText[], any:...) {
  114. static szCmd[128]; vformat(szCmd, charsmax(szCmd), szText, 3);
  115. message_begin(MSG_ONE, SVC_DIRECTOR, _, id);
  116. write_byte(strlen(szCmd) + 2);
  117. write_byte(SVC_DIRECTOR_STUFFTEXT);
  118. write_string(szCmd);
  119. message_end();
  120. }