1 /*
2
3 *************************************************************************
4
5 ArmageTron -- Just another Tron Lightcycle Game in 3D.
6 Copyright (C) 2000 Manuel Moos (manuel@moosnet.de)
7
8 **************************************************************************
9
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 ***************************************************************************
25
26 */
27
28 #include "nSpamProtection.h"
29 #include "nConfig.h"
30 #include "tSysTime.h"
31
32 static REAL se_SpamProtection = 4.0f; // degree of spam protection
33 static REAL se_SpamPenalty = 0.0f; // silence penalty when found guilty of spamming
34 static int se_SpamAutoKickCount = 3; // minimal number of
35 static REAL se_SpamAutoKick = 20.0f; // spam value that causes someone to get instantly kicked.
36 int se_SpamMaxLen = 80; // maximal length of chat message
37
38 static tSettingItem<REAL> se_SPR("SPAM_PROTECTION",
39 se_SpamProtection);
40 static tSettingItem<REAL> se_SPE("SPAM_PENALTY",
41 se_SpamPenalty);
42 static tSettingItem<REAL> se_SAK("SPAM_AUTOKICK",
43 se_SpamAutoKick);
44 static tSettingItem<int> se_SAKC("SPAM_AUTOKICK_COUNT",
45 se_SpamAutoKickCount);
46 static nSettingItemWatched<int> se_SML("SPAM_MAXLEN",
47 se_SpamMaxLen,
48 nConfItemVersionWatcher::Group_Cheating,
49 3 );
50 static tAccessLevelSetter se_SMLAL( se_SML.GetSetting(), tAccessLevel_Owner );
51
52
nSpamProtectionSettings(REAL timeScale,char const * timeScaleConfig,const tOutput & silence)53 nSpamProtectionSettings::nSpamProtectionSettings( REAL timeScale, char const * timeScaleConfig, const tOutput& silence )
54 : timeScale_( timeScale ), silence_( silence ), timeScaleSetting_( timeScaleConfig, timeScale_ )
55 {
56 }
57
nSpamProtection(const nSpamProtectionSettings & settings)58 nSpamProtection::nSpamProtection( const nSpamProtectionSettings& settings )
59 : settings_( settings ), spamProtect_( 0.0f ), spamProtectTime_( tSysTimeFloat( )), numWarnings_( 0 )
60 {
61 }
62
~nSpamProtection(void)63 nSpamProtection::~nSpamProtection( void )
64 {
65 }
66
BlockTime()67 REAL nSpamProtection::BlockTime() // time left in silenced mode
68 {
69 REAL timeScale = this->settings_.timeScale_ * se_SpamProtection;
70 return ( spamProtect_ - 6 ) * timeScale + ( tSysTimeFloat() - spamProtectTime_ );
71 }
72
CheckSpam(REAL spamlevel,int userToKick,tOutput const & reason)73 nSpamProtection::Level nSpamProtection::CheckSpam( REAL spamlevel, int userToKick, tOutput const & reason ) // check if someone is spamming
74 {
75 if ( se_SpamProtection < 0.01f )
76 {
77 se_SpamProtection = 0.01f;
78 }
79
80 REAL timeScale = this->settings_.timeScale_ * se_SpamProtection;
81
82 spamProtect_ += spamlevel;
83 spamProtect_ -=( tSysTimeFloat() - spamProtectTime_ ) / timeScale;
84
85 spamProtectTime_ = tSysTimeFloat();
86 if ( spamProtect_ < 0 )
87 spamProtect_ = 0;
88
89 if ( spamProtect_ > 6 ){
90 tOutput message;
91 spamProtect_ += se_SpamPenalty;
92
93 message.SetTemplateParameter(1, ( spamProtect_ - 6 ) * timeScale );
94 message.Append( settings_.silence_ );
95
96 // message << ColorString (1,1,0);
97 // message << "$spam_protection";
98
99 sn_ConsoleOut(message,userToKick);
100
101 if ( spamProtect_ > se_SpamAutoKick && numWarnings_ >= se_SpamAutoKickCount )
102 {
103 tOutput message( "$network_kill_spamkick" );
104 message.Append( " " );
105 message.Append( reason );
106 sn_KickUser( userToKick, message );
107
108 return Level_Hard;
109 }
110
111 ++numWarnings_;
112 return Level_Mild;
113 }
114
115 numWarnings_ = 0;
116 return Level_Ok;
117 }
118