cstextobj.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. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/commando/cstextobj.cpp $*
  25. * *
  26. * $Author:: Patrick $*
  27. * *
  28. * $Modtime:: 1/10/02 11:13a $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "cstextobj.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "debug.h"
  39. #include "networkobjectfactory.h"
  40. #include "gamemode.h"
  41. #include "cnetwork.h"
  42. #include "networkobjectmgr.h"
  43. #include "apppackettypes.h"
  44. #include "floodprotectionmgr.h"
  45. DECLARE_NETWORKOBJECT_FACTORY(cCsTextObj, NETCLASSID_CSTEXTOBJ);
  46. //-----------------------------------------------------------------------------
  47. cCsTextObj::cCsTextObj(void)
  48. {
  49. SenderId = HOST_TEXT_SENDER;
  50. Type = TEXT_MESSAGE_PUBLIC;
  51. Recipient = HOST_TEXT_SENDER;
  52. Set_App_Packet_Type(APPPACKETTYPE_CSTEXTOBJ);
  53. }
  54. //-----------------------------------------------------------------------------
  55. void
  56. cCsTextObj::Init(WideStringClass & text, TextMessageEnum type, int sender_id, int recipient)
  57. {
  58. WWASSERT(sender_id >= 0);
  59. WWASSERT(cNetwork::I_Am_Client());
  60. /*
  61. if (type == TEXT_MESSAGE_PRIVATE) {
  62. WWASSERT(recipient != -1);
  63. }
  64. */
  65. Text = text;
  66. Type = type;
  67. SenderId = sender_id;
  68. Recipient = recipient;
  69. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  70. //
  71. // Is this user "flooding" the server with text?
  72. //
  73. if (FloodProtectionMgrClass::Detect_Flooding (text) == false) {
  74. //
  75. // Not flooding, so proceed as normal
  76. //
  77. if (cNetwork::I_Am_Server()) {
  78. Act();
  79. } else {
  80. Set_Object_Dirty_Bit(0, BIT_CREATION, true);
  81. }
  82. } else {
  83. //
  84. // Flooding detected -- don't send the message
  85. //
  86. Set_Delete_Pending();
  87. }
  88. return ;
  89. }
  90. //-----------------------------------------------------------------------------
  91. void
  92. cCsTextObj::Act(void)
  93. {
  94. WWASSERT(cNetwork::I_Am_Server());
  95. if (GameModeManager::Find("Combat")->Is_Active()) {
  96. cScTextObj * p_test_obj = new cScTextObj;
  97. p_test_obj->Init(Text, Type, false, SenderId, Recipient);
  98. }
  99. Set_Delete_Pending();
  100. }
  101. //-----------------------------------------------------------------------------
  102. void
  103. cCsTextObj::Export_Creation(BitStreamClass & packet)
  104. {
  105. WWASSERT(cNetwork::I_Am_Only_Client());
  106. cNetEvent::Export_Creation(packet);
  107. packet.Add(SenderId);
  108. packet.Add((BYTE) Type);
  109. packet.Add_Wide_Terminated_String(Text);
  110. packet.Add(Recipient);
  111. Set_Delete_Pending();
  112. }
  113. //-----------------------------------------------------------------------------
  114. void
  115. cCsTextObj::Import_Creation(BitStreamClass & packet)
  116. {
  117. WWASSERT(cNetwork::I_Am_Server());
  118. cNetEvent::Import_Creation(packet);
  119. packet.Get(SenderId);
  120. BYTE type = packet.Get(type);
  121. Type = (TextMessageEnum) type;
  122. packet.Get_Wide_Terminated_String(Text.Get_Buffer(256), 256);
  123. packet.Get(Recipient);
  124. Act();
  125. }