floodprotectionmgr.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/floodprotectionmgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/25/02 1:22p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "floodprotectionmgr.h"
  36. #include "combat.h"
  37. #include "messagewindow.h"
  38. #include "translatedb.h"
  39. #include "string_ids.h"
  40. //////////////////////////////////////////////////////////////////////
  41. // Static member initialization
  42. //////////////////////////////////////////////////////////////////////
  43. SimpleDynVecClass<FloodProtectionMgrClass::FLOOD_ENTRY> FloodProtectionMgrClass::FloodList;
  44. //////////////////////////////////////////////////////////////////////
  45. //
  46. // Reset
  47. //
  48. //////////////////////////////////////////////////////////////////////
  49. void
  50. FloodProtectionMgrClass::Reset (void)
  51. {
  52. FloodList.Delete_All ();
  53. return ;
  54. }
  55. //////////////////////////////////////////////////////////////////////
  56. //
  57. // Decay_Old_Entries
  58. //
  59. //////////////////////////////////////////////////////////////////////
  60. void
  61. FloodProtectionMgrClass::Decay_Old_Entries (void)
  62. {
  63. const int DECAY_TIME = 15000;
  64. uint32 curr_time = ::GetTickCount ();
  65. //
  66. // Loop over all the entries in the list
  67. //
  68. int count = FloodList.Count ();
  69. for (int index = 0; index < count; index ++) {
  70. //
  71. // Has this entry expired?
  72. //
  73. uint32 time = FloodList[index].time;
  74. if ((curr_time - time) >= DECAY_TIME) {
  75. FloodList.Delete (index);
  76. index --;
  77. count --;
  78. }
  79. }
  80. return ;
  81. }
  82. //////////////////////////////////////////////////////////////////////
  83. //
  84. // Detect_Flooding
  85. //
  86. //////////////////////////////////////////////////////////////////////
  87. bool
  88. FloodProtectionMgrClass::Detect_Flooding (const WCHAR *text)
  89. {
  90. //
  91. // First, remove any old entries
  92. //
  93. Decay_Old_Entries ();
  94. //
  95. // The user is "flooding" if they have sent more then
  96. // 10 messages in the last 15 seconds
  97. //
  98. const int FLOOD_THRESHOLD = 5;
  99. bool retval = (FloodList.Count () >= FLOOD_THRESHOLD);
  100. //
  101. // If the user is spamming, then let them know it
  102. //
  103. if (retval) {
  104. Display_Flood_Message ();
  105. } else {
  106. //
  107. // Add a new entry to the list
  108. //
  109. FLOOD_ENTRY entry;
  110. entry.time = ::GetTickCount ();
  111. entry.text_len = 0;
  112. FloodList.Add (entry);
  113. }
  114. return retval;
  115. }
  116. //////////////////////////////////////////////////////////////////////
  117. //
  118. // Display_Flood_Message
  119. //
  120. //////////////////////////////////////////////////////////////////////
  121. void
  122. FloodProtectionMgrClass::Display_Flood_Message (void)
  123. {
  124. MessageWindowClass *message_window = CombatManager::Get_Message_Window ();
  125. if (message_window != NULL) {
  126. //
  127. // Display a message letting the user know they've been caught spamming
  128. //
  129. message_window->Add_Message (TRANSLATE (IDS_FLOOD_MSG), Vector3 (1.0F, 1.0F, 1.0F));
  130. }
  131. return ;
  132. }