Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 4.66 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <amxmodx>
  2. #include <amxmisc>
  3.  
  4. enum _:MessageData
  5. {
  6.         md_trie,
  7.         md_total
  8. };
  9.  
  10. new Array:g_message_data;
  11. new Trie:g_slash_commands;
  12.  
  13. new Float:g_warning_delay[33];
  14.  
  15. new cvar_enabled;
  16. new cvar_samecount;
  17. new cvar_minlen;
  18. new cvar_warndelay;
  19. new cvar_slash;
  20.  
  21. new g_maxclients;
  22.  
  23. public plugin_init()
  24. {
  25.         register_plugin("Anti-ChatSpam", "0.5", "Exolent");
  26.        
  27.         register_clcmd("say", "CmdSay");
  28.         register_clcmd("say_team", "CmdSayTeam");
  29.        
  30.         cvar_enabled = register_cvar("antispam_enabled", "1");
  31.         cvar_samecount = register_cvar("antispam_samecount", "3");
  32.         cvar_minlen = register_cvar("antispam_minlen", "6");
  33.         cvar_warndelay = register_cvar("antispam_warndelay", "1.5");
  34.         cvar_slash = register_cvar("antispam_slash", "0");
  35.        
  36.         g_maxclients = get_maxplayers();
  37.         g_message_data = ArrayCreate(MessageData);
  38.        
  39.         new data[MessageData];
  40.         ArrayPushArray(g_message_data, data);
  41.        
  42.         for( new client = 1; client <= g_maxclients; client++ )
  43.         {
  44.                 data[md_trie] = _:TrieCreate();
  45.                 ArrayPushArray(g_message_data, data);
  46.         }
  47.        
  48.         g_slash_commands = TrieCreate();
  49.        
  50.         LoadSlashCommands();
  51. }
  52.  
  53. public plugin_end()
  54. {
  55.         new data[MessageData];
  56.         for( new client = 1; client <= g_maxclients; client++ )
  57.         {
  58.                 ArrayGetArray(g_message_data, client, data);
  59.                 TrieDestroy(Trie:data[md_trie]);
  60.         }
  61.         ArrayDestroy(g_message_data);
  62.         TrieDestroy(g_slash_commands);
  63. }
  64.  
  65. public client_disconnect(client)
  66. {
  67.         static data[MessageData];
  68.         ArrayGetArray(g_message_data, client, data);
  69.        
  70.         if( data[md_total] )
  71.         {
  72.                 TrieClear(Trie:data[md_trie]);
  73.                 data[md_total] = 0;
  74.                
  75.                 ArraySetArray(g_message_data, client, data);
  76.         }
  77.        
  78.         g_warning_delay[client] = 0.0;
  79. }
  80.  
  81. public CmdSay(client)
  82. {
  83.         return get_pcvar_num(cvar_enabled) ? CheckSay(client, false) : PLUGIN_CONTINUE;
  84. }
  85.  
  86. public CmdSayTeam(client)
  87. {
  88.         return get_pcvar_num(cvar_enabled) ? CheckSay(client, true) : PLUGIN_CONTINUE;
  89. }
  90.  
  91. LoadSlashCommands()
  92. {
  93.         new filename[64];
  94.         get_configsdir(filename, sizeof(filename) - 1);
  95.         add(filename, sizeof(filename) - 1, "/antispam.ini");
  96.        
  97.         if( !file_exists(filename) ) return;
  98.        
  99.         new f = fopen(filename, "rt");
  100.        
  101.         if( !f ) return;
  102.        
  103.         new data[64], command[64], flag[5];
  104.         while( !feof(f) )
  105.         {
  106.                 fgets(f, data, sizeof(data) - 1);
  107.                
  108.                 if( !data[0]
  109.                 || data[0] == ';'
  110.                 || data[0] == '/' && data[1] == '/' ) continue;
  111.                
  112.                 strbreak(data, command, sizeof(command) - 1, flag, sizeof(flag) - 1);
  113.                 TrieSetCell(g_slash_commands, command, str_to_num(flag));
  114.         }
  115.        
  116.         fclose(f);
  117. }
  118.  
  119. CheckSay(client, bool:say_team)
  120. {
  121.         static message[192];
  122.         read_args(message, sizeof(message) - 1);
  123.         remove_quotes(message);
  124.         trim(message);
  125.         strtolower(message);
  126.        
  127.         if( !message[0] ) return PLUGIN_CONTINUE;
  128.        
  129.         if( !say_team && message[0] == '@' )
  130.         {
  131.                 if( access(client, ADMIN_CHAT) )
  132.                 {
  133.                         new count;
  134.                         for( new i = 1; i <= 4; i++ )
  135.                         {
  136.                                 if( message[i] == '@' ) count++;
  137.                         }
  138.                        
  139.                         if( count < 3 ) return PLUGIN_CONTINUE;
  140.                 }
  141.         }
  142.        
  143.         if( message[0] == '/' )
  144.         {
  145.                 new slash = get_pcvar_num(cvar_slash);
  146.                
  147.                 if( slash && (!say_team || slash == 2) )
  148.                 {
  149.                         static command[64];
  150.                         copy(command, sizeof(command) - 1, message[1]);
  151.                        
  152.                         new len = strlen(command);
  153.                         for( new i = 0; i < len; i++ )
  154.                         {
  155.                                 if( command[i] == ' ' )
  156.                                 {
  157.                                         command[i] = 0;
  158.                                         break;
  159.                                 }
  160.                         }
  161.                        
  162.                         if( TrieKeyExists(g_slash_commands, command)
  163.                         || SayCommandExists(client, command) ) return PLUGIN_CONTINUE;
  164.                 }
  165.         }
  166.        
  167.         if( strlen(message) < get_pcvar_num(cvar_minlen) ) return PLUGIN_CONTINUE;
  168.        
  169.         static data[MessageData];
  170.         ArrayGetArray(g_message_data, client, data);
  171.        
  172.         static count;
  173.         if( !TrieGetCell(Trie:data[md_trie], message, count) )
  174.         {
  175.                 data[md_total]++;
  176.                 count = 0;
  177.         }
  178.        
  179.         TrieSetCell(Trie:data[md_trie], message, ++count);
  180.        
  181.         if( count > get_pcvar_num(cvar_samecount) )
  182.         {
  183.                 new Float:gametime = get_gametime();
  184.                 if( gametime >= g_warning_delay[client] )
  185.                 {
  186.                         client_print(client, print_center, "Stop spamming messages!");
  187.                         g_warning_delay[client] = gametime + get_pcvar_float(cvar_warndelay);
  188.                 }
  189.                
  190.                 return PLUGIN_HANDLED;
  191.         }
  192.        
  193.         return PLUGIN_CONTINUE;
  194. }
  195.  
  196. bool:SayCommandExists(client, const say[])
  197. {
  198.         new flags = get_user_flags(client);
  199.        
  200.         static command[64], cmdflags, cmdinfo[3];
  201.        
  202.         new total = get_concmdsnum(flags, client);
  203.         for( new i = 0; i < total; i++ )
  204.         {
  205.                 get_concmd(i, command, sizeof(command) - 1, cmdflags, cmdinfo, sizeof(cmdinfo) - 1, flags);
  206.                
  207.                 if( equal(say, command[contain(command, "_") + 1]) )
  208.                 {
  209.                         return true;
  210.                 }
  211.         }
  212.        
  213.         return false;
  214. }
  215. /* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
  216. *{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
  217. */