PopupHostGame.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: PopupHostGame.cpp /////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Electronic Arts Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2002 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // created: Jul 2002
  34. //
  35. // Filename: PopupHostGame.cpp
  36. //
  37. // author: Chris Huybregts
  38. //
  39. // purpose: Contains the Callbacks for the Host Game Popus
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. //-----------------------------------------------------------------------------
  44. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  45. //-----------------------------------------------------------------------------
  46. //-----------------------------------------------------------------------------
  47. // USER INCLUDES //////////////////////////////////////////////////////////////
  48. //-----------------------------------------------------------------------------
  49. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  50. #include "Common/GlobalData.h"
  51. #include "Common/NameKeyGenerator.h"
  52. #include "Common/Version.h"
  53. #include "GameClient/WindowLayout.h"
  54. #include "GameClient/Gadget.h"
  55. #include "GameClient/GameText.h"
  56. #include "GameClient/KeyDefs.h"
  57. #include "GameClient/GadgetTextEntry.h"
  58. #include "GameClient/GadgetCheckBox.h"
  59. #include "GameClient/GadgetComboBox.h"
  60. #include "GameClient/GadgetListBox.h"
  61. #include "GameNetwork/GameSpy/GSConfig.h"
  62. #include "GameNetwork/GameSpy/Peerdefs.h"
  63. #include "GameNetwork/GameSpy/PeerThread.h"
  64. #include "GameNetwork/GameSpyOverlay.h"
  65. #include "GameNetwork/GameSpy/LadderDefs.h"
  66. #include "Common/CustomMatchPreferences.h"
  67. #include "Common/LadderPreferences.h"
  68. //-----------------------------------------------------------------------------
  69. // DEFINES ////////////////////////////////////////////////////////////////////
  70. //-----------------------------------------------------------------------------
  71. static NameKeyType parentPopupID = NAMEKEY_INVALID;
  72. static NameKeyType textEntryGameNameID = NAMEKEY_INVALID;
  73. static NameKeyType buttonCreateGameID = NAMEKEY_INVALID;
  74. static NameKeyType checkBoxAllowObserversID = NAMEKEY_INVALID;
  75. static NameKeyType textEntryGameDescriptionID = NAMEKEY_INVALID;
  76. static NameKeyType buttonCancelID = NAMEKEY_INVALID;
  77. static NameKeyType textEntryLadderPasswordID = NAMEKEY_INVALID;
  78. static NameKeyType comboBoxLadderNameID = NAMEKEY_INVALID;
  79. static NameKeyType textEntryGamePasswordID = NAMEKEY_INVALID;
  80. static NameKeyType checkBoxLimitArmiesID = NAMEKEY_INVALID;
  81. static NameKeyType checkBoxUseStatsID = NAMEKEY_INVALID;
  82. static GameWindow *parentPopup = NULL;
  83. static GameWindow *textEntryGameName = NULL;
  84. static GameWindow *buttonCreateGame = NULL;
  85. static GameWindow *checkBoxAllowObservers = NULL;
  86. static GameWindow *textEntryGameDescription = NULL;
  87. static GameWindow *buttonCancel = NULL;
  88. static GameWindow *comboBoxLadderName = NULL;
  89. static GameWindow *textEntryLadderPassword = NULL;
  90. static GameWindow *textEntryGamePassword = NULL;
  91. static GameWindow *checkBoxLimitArmies = NULL;
  92. static GameWindow *checkBoxUseStats = NULL;
  93. #ifdef _INTERNAL
  94. // for occasional debugging...
  95. //#pragma optimize("", off)
  96. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  97. #endif
  98. void createGame( void );
  99. //-----------------------------------------------------------------------------
  100. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
  101. //-----------------------------------------------------------------------------
  102. // Ladders --------------------------------------------------------------------------------
  103. static bool isPopulatingLadderBox = false;
  104. void CustomMatchHideHostPopup(Bool hide)
  105. {
  106. if (!parentPopup)
  107. return;
  108. parentPopup->winHide( hide );
  109. }
  110. void HandleCustomLadderSelection(Int ladderID)
  111. {
  112. if (!parentPopup)
  113. return;
  114. CustomMatchPreferences pref;
  115. if (ladderID == 0)
  116. {
  117. pref.setLastLadder(AsciiString::TheEmptyString, 0);
  118. pref.write();
  119. return;
  120. }
  121. const LadderInfo *info = TheLadderList->findLadderByIndex(ladderID);
  122. if (!info)
  123. {
  124. pref.setLastLadder(AsciiString::TheEmptyString, 0);
  125. }
  126. else
  127. {
  128. pref.setLastLadder(info->address, info->port);
  129. }
  130. pref.write();
  131. }
  132. void PopulateCustomLadderListBox( GameWindow *win )
  133. {
  134. if (!parentPopup || !win)
  135. return;
  136. isPopulatingLadderBox = true;
  137. CustomMatchPreferences pref;
  138. Color specialColor = GameSpyColor[GSCOLOR_MAP_SELECTED];
  139. Color normalColor = GameSpyColor[GSCOLOR_MAP_UNSELECTED];
  140. Color favoriteColor = GameSpyColor[GSCOLOR_MAP_UNSELECTED];
  141. Color localColor = GameSpyColor[GSCOLOR_MAP_UNSELECTED];
  142. Int index;
  143. GadgetListBoxReset( win );
  144. std::set<const LadderInfo *> usedLadders;
  145. // start with "No Ladder"
  146. index = GadgetListBoxAddEntryText( win, TheGameText->fetch("GUI:NoLadder"), normalColor, -1 );
  147. GadgetListBoxSetItemData( win, 0, index );
  148. // add the last ladder
  149. Int selectedPos = 0;
  150. AsciiString lastLadderAddr = pref.getLastLadderAddr();
  151. UnsignedShort lastLadderPort = pref.getLastLadderPort();
  152. const LadderInfo *info = TheLadderList->findLadder( lastLadderAddr, lastLadderPort );
  153. if (info && info->index > 0 && info->validCustom)
  154. {
  155. usedLadders.insert(info);
  156. index = GadgetListBoxAddEntryText( win, info->name, favoriteColor, -1 );
  157. GadgetListBoxSetItemData( win, (void *)(info->index), index );
  158. selectedPos = index;
  159. }
  160. // our recent ladders
  161. LadderPreferences ladPref;
  162. ladPref.loadProfile( TheGameSpyInfo->getLocalProfileID() );
  163. const LadderPrefMap recentLadders = ladPref.getRecentLadders();
  164. for (LadderPrefMap::const_iterator cit = recentLadders.begin(); cit != recentLadders.end(); ++cit)
  165. {
  166. AsciiString addr = cit->second.address;
  167. UnsignedShort port = cit->second.port;
  168. if (addr == lastLadderAddr && port == lastLadderPort)
  169. continue;
  170. const LadderInfo *info = TheLadderList->findLadder( addr, port );
  171. if (info && info->index > 0 && info->validCustom && usedLadders.find(info) == usedLadders.end())
  172. {
  173. usedLadders.insert(info);
  174. index = GadgetListBoxAddEntryText( win, info->name, favoriteColor, -1 );
  175. GadgetListBoxSetItemData( win, (void *)(info->index), index );
  176. }
  177. }
  178. // local ladders
  179. const LadderInfoList *lil = TheLadderList->getLocalLadders();
  180. LadderInfoList::const_iterator lit;
  181. for (lit = lil->begin(); lit != lil->end(); ++lit)
  182. {
  183. const LadderInfo *info = *lit;
  184. if (info && info->index < 0 && info->validCustom && usedLadders.find(info) == usedLadders.end())
  185. {
  186. usedLadders.insert(info);
  187. index = GadgetListBoxAddEntryText( win, info->name, localColor, -1 );
  188. GadgetListBoxSetItemData( win, (void *)(info->index), index );
  189. }
  190. }
  191. // special ladders
  192. lil = TheLadderList->getSpecialLadders();
  193. for (lit = lil->begin(); lit != lil->end(); ++lit)
  194. {
  195. const LadderInfo *info = *lit;
  196. if (info && info->index > 0 && info->validCustom && usedLadders.find(info) == usedLadders.end())
  197. {
  198. usedLadders.insert(info);
  199. index = GadgetListBoxAddEntryText( win, info->name, specialColor, -1 );
  200. GadgetListBoxSetItemData( win, (void *)(info->index), index );
  201. }
  202. }
  203. // standard ladders
  204. lil = TheLadderList->getStandardLadders();
  205. for (lit = lil->begin(); lit != lil->end(); ++lit)
  206. {
  207. const LadderInfo *info = *lit;
  208. if (info && info->index > 0 && info->validCustom && usedLadders.find(info) == usedLadders.end())
  209. {
  210. usedLadders.insert(info);
  211. index = GadgetListBoxAddEntryText( win, info->name, normalColor, -1 );
  212. GadgetListBoxSetItemData( win, (void *)(info->index), index );
  213. }
  214. }
  215. GadgetListBoxSetSelected( win, selectedPos );
  216. isPopulatingLadderBox = false;
  217. }
  218. void PopulateCustomLadderComboBox( void )
  219. {
  220. if (!parentPopup || !comboBoxLadderName)
  221. return;
  222. isPopulatingLadderBox = true;
  223. CustomMatchPreferences pref;
  224. AsciiString userPrefFilename;
  225. Int localProfile = TheGameSpyInfo->getLocalProfileID();
  226. userPrefFilename.format("GeneralsOnline\\CustomPref%d.ini", localProfile);
  227. pref.load(userPrefFilename);
  228. std::set<const LadderInfo *> usedLadders;
  229. Color specialColor = GameSpyColor[GSCOLOR_MAP_SELECTED];
  230. Color normalColor = GameSpyColor[GSCOLOR_MAP_UNSELECTED];
  231. Int index;
  232. GadgetComboBoxReset( comboBoxLadderName );
  233. index = GadgetComboBoxAddEntry( comboBoxLadderName, TheGameText->fetch("GUI:NoLadder"), normalColor );
  234. GadgetComboBoxSetItemData( comboBoxLadderName, index, 0 );
  235. Int selectedPos = 0;
  236. AsciiString lastLadderAddr = pref.getLastLadderAddr();
  237. UnsignedShort lastLadderPort = pref.getLastLadderPort();
  238. const LadderInfo *info = TheLadderList->findLadder( lastLadderAddr, lastLadderPort );
  239. if (info && info->validCustom)
  240. {
  241. usedLadders.insert(info);
  242. index = GadgetComboBoxAddEntry( comboBoxLadderName, info->name, specialColor );
  243. GadgetComboBoxSetItemData( comboBoxLadderName, index, (void *)(info->index) );
  244. selectedPos = index;
  245. }
  246. LadderPreferences ladPref;
  247. ladPref.loadProfile( localProfile );
  248. const LadderPrefMap recentLadders = ladPref.getRecentLadders();
  249. for (LadderPrefMap::const_iterator cit = recentLadders.begin(); cit != recentLadders.end(); ++cit)
  250. {
  251. AsciiString addr = cit->second.address;
  252. UnsignedShort port = cit->second.port;
  253. if (addr == lastLadderAddr && port == lastLadderPort)
  254. continue;
  255. const LadderInfo *info = TheLadderList->findLadder( addr, port );
  256. if (info && info->validCustom && usedLadders.find(info) == usedLadders.end())
  257. {
  258. usedLadders.insert(info);
  259. index = GadgetComboBoxAddEntry( comboBoxLadderName, info->name, normalColor );
  260. GadgetComboBoxSetItemData( comboBoxLadderName, index, (void *)(info->index) );
  261. }
  262. }
  263. index = GadgetComboBoxAddEntry( comboBoxLadderName, TheGameText->fetch("GUI:ChooseLadder"), normalColor );
  264. GadgetComboBoxSetItemData( comboBoxLadderName, index, (void *)-1 );
  265. GadgetComboBoxSetSelectedPos( comboBoxLadderName, selectedPos );
  266. isPopulatingLadderBox = false;
  267. }
  268. // Window Functions -----------------------------------------------------------------------
  269. //-------------------------------------------------------------------------------------------------
  270. /** Initialize the PopupHostGameInit menu */
  271. //-------------------------------------------------------------------------------------------------
  272. void PopupHostGameInit( WindowLayout *layout, void *userData )
  273. {
  274. parentPopupID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:ParentHostPopUp"));
  275. parentPopup = TheWindowManager->winGetWindowFromId(NULL, parentPopupID);
  276. textEntryGameNameID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:TextEntryGameName"));
  277. textEntryGameName = TheWindowManager->winGetWindowFromId(parentPopup, textEntryGameNameID);
  278. UnicodeString name;
  279. name.translate(TheGameSpyInfo->getLocalName());
  280. GadgetTextEntrySetText(textEntryGameName, name);
  281. textEntryGameDescriptionID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:TextEntryGameDescription"));
  282. textEntryGameDescription = TheWindowManager->winGetWindowFromId(parentPopup, textEntryGameDescriptionID);
  283. GadgetTextEntrySetText(textEntryGameDescription, UnicodeString::TheEmptyString);
  284. textEntryLadderPasswordID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:TextEntryLadderPassword"));
  285. textEntryLadderPassword = TheWindowManager->winGetWindowFromId(parentPopup, textEntryLadderPasswordID);
  286. GadgetTextEntrySetText(textEntryLadderPassword, UnicodeString::TheEmptyString);
  287. textEntryGamePasswordID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:TextEntryGamePassword"));
  288. textEntryGamePassword = TheWindowManager->winGetWindowFromId(parentPopup, textEntryGamePasswordID);
  289. GadgetTextEntrySetText(textEntryGamePassword, UnicodeString::TheEmptyString);
  290. buttonCreateGameID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:ButtonCreateGame"));
  291. buttonCreateGame = TheWindowManager->winGetWindowFromId(parentPopup, buttonCreateGameID);
  292. buttonCancelID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:ButtonCancel"));
  293. buttonCancel = TheWindowManager->winGetWindowFromId(parentPopup, buttonCancelID);
  294. checkBoxAllowObserversID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:CheckBoxAllowObservers"));
  295. checkBoxAllowObservers = TheWindowManager->winGetWindowFromId(parentPopup, checkBoxAllowObserversID);
  296. CustomMatchPreferences customPref;
  297. GadgetCheckBoxSetChecked(checkBoxAllowObservers, customPref.allowsObservers());
  298. comboBoxLadderNameID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:ComboBoxLadderName"));
  299. comboBoxLadderName = TheWindowManager->winGetWindowFromId(parentPopup, comboBoxLadderNameID);
  300. if (comboBoxLadderName)
  301. GadgetComboBoxReset(comboBoxLadderName);
  302. PopulateCustomLadderComboBox();
  303. checkBoxUseStatsID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:CheckBoxUseStats"));
  304. checkBoxUseStats = TheWindowManager->winGetWindowFromId(parentPopup, checkBoxUseStatsID);
  305. Bool usingStats = customPref.getUseStats();
  306. GadgetCheckBoxSetChecked( checkBoxUseStats, usingStats );
  307. // limit armies is disallowed in "use stats" games
  308. checkBoxLimitArmiesID = TheNameKeyGenerator->nameToKey(AsciiString("PopupHostGame.wnd:CheckBoxLimitArmies"));
  309. checkBoxLimitArmies = TheWindowManager->winGetWindowFromId(parentPopup, checkBoxLimitArmiesID);
  310. checkBoxLimitArmies->winEnable(! usingStats );
  311. GadgetCheckBoxSetChecked( checkBoxLimitArmies, usingStats? FALSE : customPref.getFactionsLimited() );
  312. TheWindowManager->winSetFocus( parentPopup );
  313. TheWindowManager->winSetModal( parentPopup );
  314. }
  315. //-------------------------------------------------------------------------------------------------
  316. /** PopupHostGameUpdate callback */
  317. //-------------------------------------------------------------------------------------------------
  318. void PopupHostGameUpdate( WindowLayout * layout, void *userData)
  319. {
  320. if (GadgetCheckBoxIsChecked( checkBoxUseStats ))
  321. {
  322. checkBoxLimitArmies->winEnable( FALSE );
  323. GadgetCheckBoxSetChecked( checkBoxLimitArmies, FALSE );
  324. }
  325. else
  326. {
  327. checkBoxLimitArmies->winEnable( TRUE );
  328. }
  329. }
  330. //-------------------------------------------------------------------------------------------------
  331. /** PopupHostGameInput callback */
  332. //-------------------------------------------------------------------------------------------------
  333. WindowMsgHandledType PopupHostGameInput( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  334. {
  335. switch( msg )
  336. {
  337. // --------------------------------------------------------------------------------------------
  338. case GWM_CHAR:
  339. {
  340. UnsignedByte key = mData1;
  341. UnsignedByte state = mData2;
  342. // if (buttonPushed)
  343. // break;
  344. switch( key )
  345. {
  346. // ----------------------------------------------------------------------------------------
  347. case KEY_ESC:
  348. {
  349. //
  350. // send a simulated selected event to the parent window of the
  351. // back/exit button
  352. //
  353. if( BitTest( state, KEY_STATE_UP ) )
  354. {
  355. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  356. (WindowMsgData)buttonCancel, buttonCancelID );
  357. } // end if
  358. // don't let key fall through anywhere else
  359. return MSG_HANDLED;
  360. } // end escape
  361. } // end switch( key )
  362. } // end char
  363. } // end switch( msg )
  364. return MSG_IGNORED;
  365. }
  366. //-------------------------------------------------------------------------------------------------
  367. /** PopupHostGameSystem callback */
  368. //-------------------------------------------------------------------------------------------------
  369. WindowMsgHandledType PopupHostGameSystem( GameWindow *window, UnsignedInt msg, WindowMsgData mData1, WindowMsgData mData2 )
  370. {
  371. switch( msg )
  372. {
  373. // --------------------------------------------------------------------------------------------
  374. case GWM_CREATE:
  375. {
  376. break;
  377. } // end create
  378. //---------------------------------------------------------------------------------------------
  379. case GWM_DESTROY:
  380. {
  381. parentPopup = NULL;
  382. break;
  383. } // end case
  384. //----------------------------------------------------------------------------------------------
  385. case GWM_INPUT_FOCUS:
  386. {
  387. // if we're givin the opportunity to take the keyboard focus we must say we want it
  388. if( mData1 == TRUE )
  389. *(Bool *)mData2 = TRUE;
  390. break;
  391. } // end input
  392. //----------------------------------------------------------------------------------------------
  393. case GEM_UPDATE_TEXT:
  394. {
  395. GameWindow *control = (GameWindow *)mData1;
  396. Int controlID = control->winGetWindowId();
  397. if ( controlID == textEntryGameNameID )
  398. {
  399. UnicodeString txtInput;
  400. // grab the game's name
  401. txtInput.set(GadgetTextEntryGetText( textEntryGameName ));
  402. // Clean up the text (remove leading/trailing chars, etc)
  403. const WideChar *c = txtInput.str();
  404. while (c && (iswspace(*c)))
  405. c++;
  406. if (c)
  407. txtInput = UnicodeString(c);
  408. else
  409. txtInput = UnicodeString::TheEmptyString;
  410. // Put the whitespace-free version in the box
  411. GadgetTextEntrySetText( textEntryGameName, txtInput );
  412. }// if ( controlID == textEntryPlayerNameID )
  413. break;
  414. }//case GEM_UPDATE_TEXT:
  415. //---------------------------------------------------------------------------------------------
  416. case GCM_SELECTED:
  417. {
  418. GameWindow *control = (GameWindow *)mData1;
  419. Int controlID = control->winGetWindowId();
  420. Int pos = -1;
  421. GadgetComboBoxGetSelectedPos(control, &pos);
  422. if (controlID == comboBoxLadderNameID && !isPopulatingLadderBox)
  423. {
  424. if (pos >= 0)
  425. {
  426. Int ladderID = (Int)GadgetComboBoxGetItemData(control, pos);
  427. if (ladderID < 0)
  428. {
  429. // "Choose a ladder" selected - open overlay
  430. PopulateCustomLadderComboBox(); // this restores the non-"Choose a ladder" selection
  431. GameSpyOpenOverlay( GSOVERLAY_LADDERSELECT );
  432. }
  433. }
  434. }
  435. break;
  436. } // case GCM_SELECTED
  437. //---------------------------------------------------------------------------------------------
  438. case GBM_SELECTED:
  439. {
  440. GameWindow *control = (GameWindow *)mData1;
  441. Int controlID = control->winGetWindowId();
  442. if( controlID == buttonCancelID )
  443. {
  444. parentPopup = NULL;
  445. GameSpyCloseOverlay(GSOVERLAY_GAMEOPTIONS);
  446. SetLobbyAttemptHostJoin( FALSE );
  447. }
  448. else if( controlID == buttonCreateGameID)
  449. {
  450. UnicodeString name;
  451. name = GadgetTextEntryGetText(textEntryGameName);
  452. name.trim();
  453. if(name.getLength() <= 0)
  454. {
  455. name.translate(TheGameSpyInfo->getLocalName());
  456. GadgetTextEntrySetText(textEntryGameName, name);
  457. }
  458. createGame();
  459. parentPopup = NULL;
  460. GameSpyCloseOverlay(GSOVERLAY_GAMEOPTIONS);
  461. }
  462. break;
  463. }
  464. default:
  465. return MSG_IGNORED;
  466. } // end switch
  467. return MSG_HANDLED;
  468. }
  469. //-----------------------------------------------------------------------------
  470. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
  471. //-----------------------------------------------------------------------------
  472. void createGame( void )
  473. {
  474. TheGameSpyInfo->setCurrentGroupRoom(0);
  475. PeerRequest req;
  476. UnicodeString gameName = GadgetTextEntryGetText(textEntryGameName);
  477. req.peerRequestType = PeerRequest::PEERREQUEST_CREATESTAGINGROOM;
  478. req.text = gameName.str();
  479. TheGameSpyGame->setGameName(gameName);
  480. AsciiString passwd;
  481. passwd.translate(GadgetTextEntryGetText(textEntryGamePassword));
  482. req.password = passwd.str();
  483. CustomMatchPreferences customPref;
  484. Bool aO = GadgetCheckBoxIsChecked(checkBoxAllowObservers);
  485. Bool limitArmies = GadgetCheckBoxIsChecked( checkBoxLimitArmies );
  486. Bool useStats = GadgetCheckBoxIsChecked( checkBoxUseStats );
  487. customPref.setAllowsObserver(aO);
  488. customPref.setFactionsLimited( limitArmies );
  489. customPref.setUseStats( useStats );
  490. customPref.write();
  491. req.stagingRoomCreation.allowObservers = aO;
  492. req.stagingRoomCreation.useStats = useStats;
  493. TheGameSpyGame->setAllowObservers(aO);
  494. TheGameSpyGame->setOldFactionsOnly( limitArmies );
  495. TheGameSpyGame->setUseStats( useStats );
  496. req.stagingRoomCreation.exeCRC = TheGlobalData->m_exeCRC;
  497. req.stagingRoomCreation.iniCRC = TheGlobalData->m_iniCRC;
  498. req.stagingRoomCreation.gameVersion = TheGameSpyInfo->getInternalIP();
  499. req.stagingRoomCreation.restrictGameList = TheGameSpyConfig->restrictGamesToLobby();
  500. Int ladderSelectPos = -1, ladderID = -1;
  501. GadgetComboBoxGetSelectedPos(comboBoxLadderName, &ladderSelectPos);
  502. req.ladderIP = "localhost";
  503. req.stagingRoomCreation.ladPort = 0;
  504. if (ladderSelectPos >= 0)
  505. {
  506. ladderID = (Int)GadgetComboBoxGetItemData(comboBoxLadderName, ladderSelectPos);
  507. if (ladderID != 0)
  508. {
  509. // actual ladder
  510. const LadderInfo *info = TheLadderList->findLadderByIndex(ladderID);
  511. if (info)
  512. {
  513. req.ladderIP = info->address.str();
  514. req.stagingRoomCreation.ladPort = info->port;
  515. }
  516. }
  517. }
  518. TheGameSpyGame->setLadderIP(req.ladderIP.c_str());
  519. TheGameSpyGame->setLadderPort(req.stagingRoomCreation.ladPort);
  520. req.hostPingStr = TheGameSpyInfo->getPingString().str();
  521. TheGameSpyPeerMessageQueue->addRequest(req);
  522. }