00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "nSpamProtection.h"
00029 #include "nConfig.h"
00030 #include "tSysTime.h"
00031
00032 static REAL se_SpamProtection = 4.0f;
00033 static REAL se_SpamPenalty = 10.0f;
00034 static REAL se_SpamAutoKick = 20.0f;
00035 int se_SpamMaxLen = 80;
00036
00037 static tSettingItem<REAL> se_SPR("SPAM_PROTECTION",
00038 se_SpamProtection);
00039 static tSettingItem<REAL> se_SPE("SPAM_PENALTY",
00040 se_SpamPenalty);
00041 static tSettingItem<REAL> se_SAK("SPAM_AUTOKICK",
00042 se_SpamAutoKick);
00043 static nSettingItemWatched<int> se_SML("SPAM_MAXLEN",
00044 se_SpamMaxLen,
00045 nConfItemVersionWatcher::Group_Cheating,
00046 3 );
00047
00048
00049 nSpamProtectionSettings::nSpamProtectionSettings( REAL timeScale, char const * timeScaleConfig, const tOutput& silence )
00050 : timeScale_( timeScale ), silence_( silence ), timeScaleSetting_( timeScaleConfig, timeScale_ )
00051 {
00052 }
00053
00054 nSpamProtection::nSpamProtection( const nSpamProtectionSettings& settings )
00055 : settings_( settings ), spamProtect_( 0.0f ), spamProtectTime_( tSysTimeFloat( ))
00056 {
00057 }
00058
00059 nSpamProtection::~nSpamProtection( void )
00060 {
00061 }
00062
00063 REAL nSpamProtection::BlockTime()
00064 {
00065 REAL timeScale = this->settings_.timeScale_ * se_SpamProtection;
00066 return ( spamProtect_ - 6 ) * timeScale + ( tSysTimeFloat() - spamProtectTime_ );
00067 }
00068
00069 nSpamProtection::Level nSpamProtection::CheckSpam( REAL spamlevel, int userToKick, tOutput const & reason )
00070 {
00071 if ( se_SpamProtection < 0.01f )
00072 {
00073 se_SpamProtection = 0.01f;
00074 }
00075
00076 REAL timeScale = this->settings_.timeScale_ * se_SpamProtection;
00077
00078 spamProtect_ += spamlevel;
00079 spamProtect_ -=( tSysTimeFloat() - spamProtectTime_ ) / timeScale;
00080
00081 spamProtectTime_ = tSysTimeFloat();
00082 if ( spamProtect_ < 0 )
00083 spamProtect_ = 0;
00084
00085 if ( spamProtect_ > 6 ){
00086 tOutput message;
00087 spamProtect_ += se_SpamPenalty;
00088
00089 message.SetTemplateParameter(1, ( spamProtect_ - 6 ) * timeScale );
00090 message.Append( settings_.silence_ );
00091
00092
00093
00094
00095 sn_ConsoleOut(message,userToKick);
00096
00097 if ( spamProtect_ > se_SpamAutoKick )
00098 {
00099 tOutput message( "$network_kill_spamkick" );
00100 message.Append( " " );
00101 message.Append( reason );
00102 sn_KickUser( userToKick, message );
00103
00104 return Level_Hard;
00105 }
00106
00107 return Level_Mild;
00108 }
00109
00110 return Level_Ok;
00111 }