| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : commando *
- * *
- * $Archive:: /Commando/Code/Commando/floodprotectionmgr.cpp $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 2/25/02 1:22p $*
- * *
- * $Revision:: 3 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "floodprotectionmgr.h"
- #include "combat.h"
- #include "messagewindow.h"
- #include "translatedb.h"
- #include "string_ids.h"
- //////////////////////////////////////////////////////////////////////
- // Static member initialization
- //////////////////////////////////////////////////////////////////////
- SimpleDynVecClass<FloodProtectionMgrClass::FLOOD_ENTRY> FloodProtectionMgrClass::FloodList;
- //////////////////////////////////////////////////////////////////////
- //
- // Reset
- //
- //////////////////////////////////////////////////////////////////////
- void
- FloodProtectionMgrClass::Reset (void)
- {
- FloodList.Delete_All ();
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Decay_Old_Entries
- //
- //////////////////////////////////////////////////////////////////////
- void
- FloodProtectionMgrClass::Decay_Old_Entries (void)
- {
- const int DECAY_TIME = 15000;
- uint32 curr_time = ::GetTickCount ();
- //
- // Loop over all the entries in the list
- //
- int count = FloodList.Count ();
- for (int index = 0; index < count; index ++) {
- //
- // Has this entry expired?
- //
- uint32 time = FloodList[index].time;
- if ((curr_time - time) >= DECAY_TIME) {
- FloodList.Delete (index);
- index --;
- count --;
- }
- }
- return ;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Detect_Flooding
- //
- //////////////////////////////////////////////////////////////////////
- bool
- FloodProtectionMgrClass::Detect_Flooding (const WCHAR *text)
- {
- //
- // First, remove any old entries
- //
- Decay_Old_Entries ();
- //
- // The user is "flooding" if they have sent more then
- // 10 messages in the last 15 seconds
- //
- const int FLOOD_THRESHOLD = 5;
- bool retval = (FloodList.Count () >= FLOOD_THRESHOLD);
- //
- // If the user is spamming, then let them know it
- //
- if (retval) {
- Display_Flood_Message ();
- } else {
- //
- // Add a new entry to the list
- //
- FLOOD_ENTRY entry;
- entry.time = ::GetTickCount ();
- entry.text_len = 0;
- FloodList.Add (entry);
- }
- return retval;
- }
- //////////////////////////////////////////////////////////////////////
- //
- // Display_Flood_Message
- //
- //////////////////////////////////////////////////////////////////////
- void
- FloodProtectionMgrClass::Display_Flood_Message (void)
- {
- MessageWindowClass *message_window = CombatManager::Get_Message_Window ();
- if (message_window != NULL) {
- //
- // Display a message letting the user know they've been caught spamming
- //
- message_window->Add_Message (TRANSLATE (IDS_FLOOD_MSG), Vector3 (1.0F, 1.0F, 1.0F));
- }
- return ;
- }
|