ItsMods

Full Version: Anti Flood plugin
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
This plugins basicly protects your server from spammers.

You can change some settings in the sv_config.ini:
Code:
[ANTIFLOOD]
warnings=3 //how much warnings will a player get
time=2 //the time in seconds that a player has to wait untill he can chat again
punish=true //true will kick the player after he has ignored his warnings, false will only hide the message

Source:
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using Addon;
  5.  
  6. namespace Anti_Flood
  7. {
  8. public class Anti_Flood : CPlugin
  9. {
  10. List<AntiFlood> Floodlist = new List<AntiFlood>();
  11. int MaxWarnings;
  12. int Time;
  13. bool Punish;
  14.  
  15. public override void OnServerLoad()
  16. {
  17. ServerPrint( "Anti-Flood plugin. Author: iAegle. Version: 1.0" );
  18. Time = Convert.ToInt32( Convert.ToDecimal( GetServerCFG( "ANTIFLOOD", "time", "2" ) ) * 50 );
  19. MaxWarnings = Convert.ToInt32( GetServerCFG( "ANTIFLOOD", "warnings", "3" ) );
  20. Punish = ( GetServerCFG( "ANTIFLOOD", "punish", "true" ) == "true" );
  21. }
  22.  
  23. public override void OnServerFrame()
  24. {
  25. foreach ( AntiFlood player in Floodlist )
  26. {
  27. player.Waittime--;
  28.  
  29. if ( player.Waittime == 0 )
  30. Floodlist.Remove( player );
  31. }
  32. }
  33.  
  34. public override ChatType OnSay( string Message, ServerClient Client )
  35. {
  36. foreach ( AntiFlood player in Floodlist )
  37. {
  38. if ( player.Client == Client )
  39. {
  40. if ( !Punish )
  41. return ChatType.ChatNone;
  42.  
  43. iPrintLnBold( ( player.Warnings <= 2 ) ? "Stop spamming! [^1Warnings Left" + ( 2 - player.Warnings ).ToString() + "^7]" : "^1You better pay attention the the warnings next time.", Client );
  44. if ( player.Warnings >= 3 )
  45. new Thread( new ParameterizedThreadStart( PunishThread ) ).Start( Client );
  46. else
  47. player.Warnings++;
  48.  
  49. return ChatType.ChatNone;
  50. }
  51. }
  52.  
  53. Floodlist.Add( new AntiFlood( Client, Time, MaxWarnings ) );
  54. return ChatType.ChatAll;
  55. }
  56.  
  57. public void PunishThread( object Client )
  58. {
  59. ServerClient client = ( ServerClient )Client;
  60. Thread.Sleep( 2500 );
  61. iPrintLnBold( "Bye bye spammer. :)", client );
  62. Thread.Sleep( 1000 );
  63. ServerCommand( "kickclient " + client.ClientNum );
  64. iPrintLn( client.Name + " got kicked for spamming.", null );
  65. }
  66.  
  67. public class AntiFlood
  68. {
  69. public int Waittime;
  70. public ServerClient Client;
  71. public int Warnings;
  72. public AntiFlood( ServerClient client, int time, int warnings )
  73. {
  74. Client = client;
  75. Waittime = time;
  76. Warnings = warnings;
  77. }
  78. }
  79. }
  80. }


Plugin:
[attachment=1395]

I didn't test it, but if something doesn't work properly please post the problem here.
(01-08-2012, 21:07)iAegle Wrote: [ -> ]I didn't test it, but if something doesn't work properly please post the problem here.

Code:
return ChatType.ChatAll;

should be (unless you want to break all other plugins):

Code:
return ChatType.ChatContinue;


Still, nice work
(01-08-2012, 21:09)Nukem Wrote: [ -> ]
(01-08-2012, 21:07)iAegle Wrote: [ -> ]I didn't test it, but if something doesn't work properly please post the problem here.

Code:
return ChatType.ChatAll;

should be (unless you want to break all other plugins):

Code:
return ChatType.ChatContinue;


Still, nice work

Why did you even include ChatType.ChatNone if you tell everyone to use ChatContinue :p?
Why do you never test your plugins
(01-08-2012, 21:12)Pozzuh Wrote: [ -> ]Why do you never test your plugins

Ohh thats simple, because I can't :p
(01-08-2012, 21:12)iAegle Wrote: [ -> ]
(01-08-2012, 21:12)Pozzuh Wrote: [ -> ]Why do you never test your plugins

Ohh thats simple, because I can't :p

why cant you
lol @ 6 reactions and 0 downloads Troll
(01-08-2012, 21:17)Pozzuh Wrote: [ -> ]
(01-08-2012, 21:12)iAegle Wrote: [ -> ]
(01-08-2012, 21:12)Pozzuh Wrote: [ -> ]Why do you never test your plugins

Ohh thats simple, because I can't :p

why cant you

No game/server
(01-08-2012, 21:27)iAegle Wrote: [ -> ]
(01-08-2012, 21:17)Pozzuh Wrote: [ -> ]
(01-08-2012, 21:12)iAegle Wrote: [ -> ]
(01-08-2012, 21:12)Pozzuh Wrote: [ -> ]Why do you never test your plugins

Ohh thats simple, because I can't :p

why cant you

No game/server

Why don't you install it
This anti flood thingy was always pissing me off, but still nice work.
This anti flood thingy was always pissing me off, but still nice work.
Pages: 1 2