src/network/nSpamProtection.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
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;   // degree of spam protection
00033 static REAL se_SpamPenalty        = 10.0f;      // silence penalty when found guilty of spamming
00034 static REAL se_SpamAutoKick       = 20.0f;      // spam value that causes someone to get instantly kicked.
00035 int                     se_SpamMaxLen     = 80;         // maximal length of chat message
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()                                    // time left in silenced mode
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 )    // check if someone is spamming
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         //              message << ColorString (1,1,0);
00093         //              message << "$spam_protection";
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 }

Generated on Sat Mar 15 22:55:52 2008 for Armagetron Advanced by  doxygen 1.5.4