DlgMPConnect.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. *
  20. * NAME
  21. * $Archive: /Commando/Code/Commando/DlgMPConnect.cpp $
  22. *
  23. * DESCRIPTION
  24. * Dialog to inform user that we are connecting to a game host.
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Tom_s $
  29. *
  30. * VERSION INFO
  31. * $Revision: 12 $
  32. * $Modtime: 2/25/02 11:29a $
  33. *
  34. ******************************************************************************/
  35. #include "dlgmpconnect.h"
  36. #include "gamedata.h"
  37. #include "gameinitmgr.h"
  38. #include "campaign.h"
  39. #include "cnetwork.h"
  40. #include "resource.h"
  41. #include <wwdebug\wwdebug.h>
  42. #include "dlgmainmenu.h"
  43. #include "gamespyadmin.h"
  44. #include "specialbuilds.h"
  45. #include "dialogtests.h"
  46. #include "dialogmgr.h"
  47. #include "gamemode.h"
  48. #include "langmode.h"
  49. #include "wolgmode.h"
  50. /******************************************************************************
  51. *
  52. * NAME
  53. * DlgMPConnect::DoDialog
  54. *
  55. * DESCRIPTION
  56. *
  57. * INPUTS
  58. * NONE
  59. *
  60. * RESULT
  61. * True if dialog created successfully.
  62. *
  63. ******************************************************************************/
  64. bool DlgMPConnect::DoDialog(int teamChoice, unsigned long clanID)
  65. {
  66. DlgMPConnect* popup = new DlgMPConnect(teamChoice, clanID);
  67. if (popup)
  68. {
  69. popup->Start_Dialog();
  70. popup->Release_Ref();
  71. }
  72. return (popup != NULL);
  73. }
  74. /******************************************************************************
  75. *
  76. * NAME
  77. * DlgMPConnect::DlgMPConnect
  78. *
  79. * DESCRIPTION
  80. * Constructor
  81. *
  82. * INPUTS
  83. * NONE
  84. *
  85. * RESULT
  86. * NONE
  87. *
  88. ******************************************************************************/
  89. DlgMPConnect::DlgMPConnect(int teamChoice, unsigned long clanID) :
  90. PopupDialogClass(IDD_MULTIPLAY_CONNECTING),
  91. mTeamChoice(teamChoice),
  92. mClanID(clanID),
  93. mTheGame(NULL),
  94. mFailed(false)
  95. {
  96. WWDEBUG_SAY(("DlgMPConnect: Instantiated\n"));
  97. }
  98. /******************************************************************************
  99. *
  100. * NAME
  101. * DlgMPConnect::~DlgMPConnect
  102. *
  103. * DESCRIPTION
  104. * Destructor
  105. *
  106. * INPUTS
  107. * NONE
  108. *
  109. * RESULT
  110. * NONE
  111. *
  112. ******************************************************************************/
  113. DlgMPConnect::~DlgMPConnect()
  114. {
  115. WWDEBUG_SAY(("DlgMPConnect: Destructing\n"));
  116. }
  117. /******************************************************************************
  118. *
  119. * NAME
  120. * DlgMPConnect::Connected
  121. *
  122. * DESCRIPTION
  123. * Handle connection.
  124. *
  125. * INPUTS
  126. * GameData - Pointer to game data instance
  127. *
  128. * RESULT
  129. * NONE
  130. *
  131. ******************************************************************************/
  132. void DlgMPConnect::Connected(cGameData* theGame)
  133. {
  134. mTheGame = theGame;
  135. }
  136. /******************************************************************************
  137. *
  138. * NAME
  139. * DlgMPConnect::Connected
  140. *
  141. * DESCRIPTION
  142. * Handle connection.
  143. *
  144. * INPUTS
  145. * GameData - Pointer to game data instance
  146. *
  147. * RESULT
  148. * NONE
  149. *
  150. ******************************************************************************/
  151. void DlgMPConnect::Failed_To_Connect(void)
  152. {
  153. mFailed = true;
  154. }
  155. /******************************************************************************
  156. *
  157. * NAME
  158. * DlgMPConnect::On_Command
  159. *
  160. * DESCRIPTION
  161. * Process command messages from controls
  162. *
  163. * INPUTS
  164. * Ctrl - ID of control
  165. * Message -
  166. * Param - 0 = User invoked abort. 1 = Connection refused by server.
  167. *
  168. * RESULT
  169. * NONE
  170. *
  171. ******************************************************************************/
  172. void DlgMPConnect::On_Command(int ctrlID, int message, DWORD param)
  173. {
  174. if ((IDCANCEL == ctrlID) && (1 != param))
  175. {
  176. if (cNetwork::I_Am_Client())
  177. {
  178. cNetwork::Cleanup_Client();
  179. }
  180. if (cGameSpyAdmin::Get_Is_Launched_From_Gamespy())
  181. {
  182. extern void Stop_Main_Loop (int);
  183. Stop_Main_Loop(EXIT_SUCCESS);
  184. }
  185. else if (DialogMgrClass::Get_Dialog_Count () == 1)
  186. {
  187. START_DIALOG (MainMenuDialogClass);
  188. }
  189. }
  190. PopupDialogClass::On_Command(ctrlID, message, param);
  191. }
  192. /******************************************************************************
  193. *
  194. * NAME
  195. * DlgMPConnect::On_Periodic
  196. *
  197. * DESCRIPTION
  198. *
  199. * INPUTS
  200. * NONE
  201. *
  202. * RESULT
  203. * NONE
  204. *
  205. ******************************************************************************/
  206. void DlgMPConnect::On_Periodic(void)
  207. {
  208. PopupDialogClass::On_Periodic();
  209. if (mTheGame != NULL)
  210. {
  211. // Add a reference to keep us alive while we process the game start
  212. Add_Ref();
  213. // Remove the dialog from menuing system
  214. End_Dialog();
  215. // Check to ensure the settings are playable
  216. WideStringClass outMsg;
  217. if (mTheGame->Is_Valid_Settings(outMsg))
  218. {
  219. WWDEBUG_SAY(("DlgMPConnect: Starting the game.\n"));
  220. CampaignManager::Select_Backdrop_Number_By_MP_Type(mTheGame->Get_Game_Type());
  221. // Start the game!
  222. GameInitMgrClass::Set_Is_Client_Required(true);
  223. GameInitMgrClass::Set_Is_Server_Required(false);
  224. GameInitMgrClass::Start_Game(mTheGame->Get_Map_Name(), mTeamChoice, mClanID);
  225. }
  226. else
  227. {
  228. WWDEBUG_SAY(("ERROR: %s\n", (const WCHAR*)outMsg));
  229. }
  230. // Release the keep alive reference (this will delete this object)
  231. Release_Ref();
  232. }
  233. else
  234. {
  235. if (mFailed)
  236. {
  237. Add_Ref();
  238. // Remove the dialog from menuing system
  239. End_Dialog();
  240. if (GameModeManager::Find("LAN")->Is_Active())
  241. {
  242. PLC->Refusal_Actions();
  243. }
  244. else
  245. {
  246. GameModeClass* gameMode = GameModeManager::Find("WOL");
  247. if (gameMode && gameMode->Is_Active())
  248. {
  249. WolGameModeClass* wolGame = static_cast<WolGameModeClass*>(gameMode);
  250. WWASSERT(wolGame);
  251. wolGame->Refusal_Actions();
  252. }
  253. }
  254. Release_Ref();
  255. }
  256. }
  257. }