bioevent.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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/bioevent.cpp $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 2/20/02 11:01p $*
  29. * *
  30. * $Revision:: 26 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "bioevent.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "cnetwork.h"
  40. #include "networkobjectmgr.h"
  41. #include "evictionevent.h"
  42. #include "playermanager.h"
  43. #include "god.h"
  44. #include "gametype.h"
  45. #include "apppackettypes.h"
  46. #include "gamedataupdateevent.h"
  47. #include "consolemode.h"
  48. #include "winevent.h"
  49. #include "gamespyadmin.h"
  50. DECLARE_NETWORKOBJECT_FACTORY(cBioEvent, NETCLASSID_BIOEVENT);
  51. //-----------------------------------------------------------------------------
  52. cBioEvent::cBioEvent(void) :
  53. SenderId(0),
  54. TeamChoice(-1),
  55. ClanID(0)
  56. {
  57. Set_App_Packet_Type(APPPACKETTYPE_BIOEVENT);
  58. }
  59. //-----------------------------------------------------------------------------
  60. void
  61. cBioEvent::Init(int teamChoice, unsigned long clanID)
  62. {
  63. WWASSERT(cNetwork::I_Am_Client());
  64. SenderId = cNetwork::Get_My_Id();
  65. Nickname = cNetInterface::Get_Nickname();
  66. TeamChoice = teamChoice;
  67. ClanID = clanID;
  68. strcpy(MapName, The_Game()->Get_Map_Name().Peek_Buffer());
  69. Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
  70. if (cNetwork::I_Am_Server()) {
  71. Act();
  72. } else {
  73. Set_Object_Dirty_Bit(0, BIT_CREATION, true);
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. void
  78. cBioEvent::Act(void)
  79. {
  80. WWASSERT(cNetwork::I_Am_Server());
  81. //
  82. // This is where we validate a player. If we don't want him to play,
  83. // for whichever reason, after learning all about him, evict him here.
  84. // Note that the server has already seen the player name in
  85. // cNetwork::Application_Acceptance_Handler.
  86. // Now the server will see additional data.
  87. //
  88. bool is_accepted = true;
  89. EvictionCodeEnum eviction_code = EVICTION_POOR_BANDWIDTH;
  90. if (is_accepted) {
  91. //
  92. // Tell the new guy about all existing players
  93. //
  94. for (SLNode<cPlayer> * player_node = cPlayerManager::Get_Player_Object_List()->Head();
  95. player_node;
  96. player_node = player_node->Next()) {
  97. cPlayer * p_player = player_node->Data();
  98. WWASSERT(p_player != NULL);
  99. cNetwork::Send_Object_Update(p_player, SenderId);
  100. }
  101. //GAMESPY
  102. if (cGameSpyAdmin::Is_Gamespy_Game() &&
  103. cGameSpyAdmin::Is_Nickname_Collision(Nickname)) {
  104. WideStringClass new_nickname;
  105. int count = 1;
  106. do {
  107. new_nickname.Format(L"%s(%d)", Nickname, count++);
  108. } while (cGameSpyAdmin::Is_Nickname_Collision(new_nickname));
  109. Nickname = new_nickname;
  110. }
  111. cPlayer * p_player = cGod::Create_Player(SenderId, Nickname, TeamChoice, ClanID);
  112. WWASSERT(p_player != NULL);
  113. if (!IS_SOLOPLAY) {
  114. //
  115. // Record his IP address for diagnostic purposes
  116. //
  117. WWASSERT(cNetwork::Get_Server_Rhost(SenderId) != NULL);
  118. SOCKADDR_IN & address = cNetwork::Get_Server_Rhost(SenderId)->Get_Address();
  119. p_player->Set_Ip_Address(address.sin_addr.s_addr);
  120. //
  121. // Tell the remote host object to expect a lot of temporary extra bandwidth.
  122. //
  123. if (cNetwork::PServerConnection != NULL) {
  124. cNetwork::PServerConnection->Set_Rhost_Expect_Packet_Flood(p_player->Get_Id(), true);
  125. }
  126. //
  127. // Update him about any dynamic game data parameters.
  128. //
  129. WWDEBUG_SAY(("BioEvent acting\n"));
  130. cGameDataUpdateEvent * p_event = new cGameDataUpdateEvent();
  131. p_event->Init(p_player->Get_Id());
  132. StringClass str(128, true);
  133. Nickname.Convert_To(str);
  134. ConsoleBox.Print_Maybe("Player %s joined the game\n", str.Peek_Buffer());
  135. //
  136. // If we (the server) are already in intermission mode then deactivate the player until the next map starts. The player
  137. // will have already loaded the next map. ST - 1/17/2002 7:43PM
  138. //
  139. if (The_Game()->IsIntermission.Is_True()) {
  140. //
  141. // If the new player has the old map loaded (which can happen if the intermission starts after the client has
  142. // started loading the old map) then send him a wineven so he knows to load the next map.
  143. //
  144. if (stricmp(MapName, The_Game()->Get_Map_Name().Peek_Buffer()) != 0) {
  145. cWinEvent * p_win = new cWinEvent;
  146. p_win->Init(The_Game()->Get_Winner_ID(), SenderId, The_Game()->Is_Map_Cycle_Over());
  147. cNetwork::Send_Object_Update(p_win, SenderId);
  148. } else {
  149. p_player->Set_Is_In_Game(false);
  150. p_player->Set_Is_Waiting_For_Intermission(true);
  151. }
  152. }
  153. }
  154. } else {
  155. cEvictionEvent * p_event = new cEvictionEvent;
  156. p_event->Init(SenderId, eviction_code);
  157. cNetwork::Flush();
  158. cNetwork::Server_Kill_Connection(SenderId);
  159. }
  160. Set_Delete_Pending();
  161. }
  162. //-----------------------------------------------------------------------------
  163. void
  164. cBioEvent::Export_Creation(BitStreamClass & packet)
  165. {
  166. cNetEvent::Export_Creation(packet);
  167. WWASSERT(cNetwork::I_Am_Only_Client());
  168. WWASSERT(SenderId > 0);
  169. packet.Add(SenderId);
  170. packet.Add_Wide_Terminated_String(Nickname);
  171. packet.Add(TeamChoice);
  172. packet.Add(ClanID);
  173. packet.Add_Terminated_String(MapName, false);
  174. WWDEBUG_SAY(("cBioEvent sent\n"));
  175. Set_Delete_Pending();
  176. }
  177. //-----------------------------------------------------------------------------
  178. void
  179. cBioEvent::Import_Creation(BitStreamClass & packet)
  180. {
  181. cNetEvent::Import_Creation(packet);
  182. WWASSERT(cNetwork::I_Am_Server());
  183. packet.Get(SenderId);
  184. packet.Get_Wide_Terminated_String(Nickname.Get_Buffer(256), 256, true);
  185. packet.Get(TeamChoice);
  186. packet.Get(ClanID);
  187. packet.Get_Terminated_String(MapName, sizeof(MapName), false);
  188. WWASSERT(SenderId > 0);
  189. WWDEBUG_SAY(("cBioEvent recd\n"));
  190. Act();
  191. }