gameoptionsevent.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/gameoptionsevent.cpp $*
  25. * *
  26. * $Author:: Bhayes $*
  27. * *
  28. * $Modtime:: 3/29/02 4:36p $*
  29. * *
  30. * $Revision:: 24 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "gameoptionsevent.h"
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include "networkobjectfactory.h"
  39. #include "gamemode.h"
  40. #include "cnetwork.h"
  41. #include "gametype.h"
  42. #include "dialogbase.h"
  43. #include "dialogmgr.h"
  44. #include "dlgmpconnect.h"
  45. #include "dialogresource.h"
  46. #include "resource.h"
  47. #include "apppackettypes.h"
  48. #include "modpackagemgr.h"
  49. #include "specialbuilds.h"
  50. #include "dlgmpconnectionrefused.h"
  51. #include "translatedb.h"
  52. #include "string_ids.h"
  53. #include <WWLib\RealCRC.h>
  54. DECLARE_NETWORKOBJECT_FACTORY(cGameOptionsEvent, NETCLASSID_GAMEOPTIONSEVENT);
  55. //-----------------------------------------------------------------------------
  56. cGameOptionsEvent::cGameOptionsEvent(void)
  57. {
  58. Set_App_Packet_Type(APPPACKETTYPE_GAMEOPTIONSEVENT);
  59. HostedGameNumber = -1;
  60. }
  61. //-----------------------------------------------------------------------------
  62. void
  63. cGameOptionsEvent::Init(int client_id)
  64. {
  65. WWASSERT(cNetwork::I_Am_Server());
  66. WWASSERT(The_Game() != NULL);
  67. HostedGameNumber = The_Game()->Get_Hosted_Game_Number();
  68. Set_Object_Dirty_Bit(client_id, BIT_CREATION, true);
  69. }
  70. //-----------------------------------------------------------------------------
  71. void
  72. cGameOptionsEvent::Act(void)
  73. {
  74. WWASSERT(cNetwork::I_Am_Only_Client());
  75. WWASSERT(The_Game() != NULL);
  76. The_Game()->Set_Hosted_Game_Number(HostedGameNumber);
  77. if (!IS_SOLOPLAY) {
  78. DialogBaseClass* dialog = DialogMgrClass::Find_Dialog(IDD_MULTIPLAY_CONNECTING);
  79. if (dialog != NULL) {
  80. ((DlgMPConnect*)dialog)->Connected(The_Game());
  81. }
  82. }
  83. }
  84. //-----------------------------------------------------------------------------
  85. void
  86. cGameOptionsEvent::Export_Creation(BitStreamClass & packet)
  87. {
  88. WWASSERT(cNetwork::I_Am_Server());
  89. cNetEvent::Export_Creation(packet);
  90. WWASSERT(PTheGameData != NULL);
  91. //GAMESPY
  92. //
  93. // Due to gamespy support, we can no longer assume that the client exe
  94. // knows about tier 1 options, so transmit them.
  95. //
  96. The_Game()->Export_Tier_1_Data((cPacket &) packet);
  97. The_Game()->Export_Tier_2_Data((cPacket &) packet);
  98. packet.Add(The_Game()->Get_Time_Remaining_Seconds());
  99. packet.Add(HostedGameNumber);
  100. #ifndef MULTIPLAYERDEMO
  101. packet.Add(CRC_Stringi(The_Game()->Get_Mod_Name()));
  102. packet.Add(CRC_Stringi(The_Game()->Get_Map_Name()));
  103. #endif // MULTIPLAYERDEMO
  104. WWDEBUG_SAY(("cGameOptionsEvent sent\n"));
  105. Set_Delete_Pending();
  106. }
  107. //-----------------------------------------------------------------------------
  108. void
  109. cGameOptionsEvent::Import_Creation(BitStreamClass & packet)
  110. {
  111. cNetEvent::Import_Creation(packet);
  112. WWASSERT(cNetwork::I_Am_Only_Client());
  113. WWASSERT(PTheGameData != NULL);
  114. The_Game()->Import_Tier_1_Data((cPacket &) packet);
  115. The_Game()->Import_Tier_2_Data((cPacket &) packet);
  116. float time_remaining_seconds = packet.Get(time_remaining_seconds);
  117. The_Game()->Set_Time_Remaining_Seconds(time_remaining_seconds);
  118. packet.Get(HostedGameNumber);
  119. bool act = true;
  120. #ifndef MULTIPLAYERDEMO
  121. //
  122. // TSS103001...n.b. need test that Find_Map_Name succeeds...
  123. //
  124. ULONG mod_name_crc = packet.Get(mod_name_crc);
  125. ULONG map_name_crc = packet.Get(map_name_crc);
  126. // Find the mod and map names from their CRC
  127. StringClass mod_name(0, true);
  128. StringClass map_name(0, true);
  129. ModPackageMgrClass::Get_Mod_Map_Name_From_CRC (mod_name_crc, map_name_crc, &mod_name, &map_name);
  130. The_Game()->Set_Mod_Name(mod_name);
  131. The_Game()->Set_Map_Name(map_name);
  132. if (!IS_SOLOPLAY) {
  133. if (!The_Game()->Is_Map_Valid()) {
  134. DialogBaseClass* dialog = DialogMgrClass::Find_Dialog(IDD_MULTIPLAY_CONNECTING);
  135. if (dialog != NULL) {
  136. ((DlgMPConnect*)dialog)->Failed_To_Connect();
  137. act = false;
  138. }
  139. WideStringClass tval;
  140. tval.Format(L"%s %s", TRANSLATE(IDS_MP_CONNECTION_REFUSED_BY_APPLICATION),
  141. TRANSLATE(IDS_MENU_MISSING_MAP));
  142. DlgMPConnectionRefused::DoDialog(tval, false);
  143. }
  144. }
  145. #endif // MULTIPLAYERDEMO
  146. WWDEBUG_SAY(("cGameOptionsEvent recd\n"));
  147. if (act) {
  148. Act();
  149. }
  150. Set_Delete_Pending();
  151. }