WOLLobbyMenu.cpp 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857
  1. /*
  2. ** Command & Conquer Generals(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. ///////////////////////////////////////////////////////////////////////////////////////
  24. // FILE: WOLLobbyMenu.cpp
  25. // Author: Chris Huybregts, November 2001
  26. // Description: WOL Lobby Menu
  27. ///////////////////////////////////////////////////////////////////////////////////////
  28. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  29. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  30. #include "Common/GameEngine.h"
  31. #include "Common/GameState.h"
  32. #include "Common/MiniLog.h"
  33. #include "Common/MultiplayerSettings.h"
  34. #include "Common/PlayerTemplate.h"
  35. #include "Common/CustomMatchPreferences.h"
  36. #include "Common/Version.h"
  37. #include "GameClient/AnimateWindowManager.h"
  38. #include "GameClient/WindowLayout.h"
  39. #include "GameClient/Gadget.h"
  40. #include "GameClient/GameClient.h"
  41. #include "GameClient/Shell.h"
  42. #include "GameClient/ShellHooks.h"
  43. #include "GameClient/KeyDefs.h"
  44. #include "GameClient/GameWindowManager.h"
  45. #include "GameClient/GadgetComboBox.h"
  46. #include "GameClient/GadgetListBox.h"
  47. #include "GameClient/GadgetSlider.h"
  48. #include "GameClient/GadgetTextEntry.h"
  49. #include "GameClient/GameText.h"
  50. #include "GameClient/MessageBox.h"
  51. #include "GameClient/Mouse.h"
  52. #include "GameClient/Display.h"
  53. #include "GameNetwork/GameSpyOverlay.h"
  54. #include "GameClient/GameWindowTransitions.h"
  55. #include "GameLogic/GameLogic.h"
  56. #include "GameClient/LanguageFilter.h"
  57. #include "GameNetwork/GameSpy/BuddyDefs.h"
  58. #include "GameNetwork/GameSpy/GSConfig.h"
  59. #include "GameNetwork/GameSpy/LadderDefs.h"
  60. #include "GameNetwork/GameSpy/PeerDefs.h"
  61. #include "GameNetwork/GameSpy/PeerThread.h"
  62. #include "GameNetwork/GameSpy/PersistentStorageDefs.h"
  63. #include "GameNetwork/GameSpy/PersistentStorageThread.h"
  64. #include "GameNetwork/GameSpy/LobbyUtils.h"
  65. #include "GameNetwork/RankPointValue.h"
  66. #ifdef _INTERNAL
  67. // for occasional debugging...
  68. //#pragma optimize("", off)
  69. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  70. #endif
  71. void refreshGameList( Bool forceRefresh = FALSE );
  72. void refreshPlayerList( Bool forceRefresh = FALSE );
  73. #ifdef DEBUG_LOGGING
  74. #define PERF_TEST
  75. static LogClass s_perfLog("Perf.txt");
  76. #define PERF_LOG(x) s_perfLog.log x
  77. #else // DEBUG_LOGGING
  78. #define PERF_LOG(x) {}
  79. #endif // DEBUG_LOGGING
  80. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  81. static Bool isShuttingDown = false;
  82. static Bool buttonPushed = false;
  83. static char *nextScreen = NULL;
  84. static Bool raiseMessageBoxes = false;
  85. static time_t gameListRefreshTime = 0;
  86. static const time_t gameListRefreshInterval = 10000;
  87. static time_t playerListRefreshTime = 0;
  88. static const time_t playerListRefreshInterval = 5000;
  89. void setUnignoreText( WindowLayout *layout, AsciiString nick, GPProfile id);
  90. static void doSliderTrack(GameWindow *control, Int val);
  91. Bool DontShowMainMenu = FALSE;
  92. enum { COLUMN_PLAYERNAME = 2 };
  93. // window ids ------------------------------------------------------------------------------
  94. static NameKeyType parentWOLLobbyID = NAMEKEY_INVALID;
  95. static NameKeyType buttonBackID = NAMEKEY_INVALID;
  96. static NameKeyType buttonHostID = NAMEKEY_INVALID;
  97. static NameKeyType buttonRefreshID = NAMEKEY_INVALID;
  98. static NameKeyType buttonJoinID = NAMEKEY_INVALID;
  99. static NameKeyType buttonBuddyID = NAMEKEY_INVALID;
  100. static NameKeyType buttonEmoteID = NAMEKEY_INVALID;
  101. static NameKeyType textEntryChatID = NAMEKEY_INVALID;
  102. static NameKeyType listboxLobbyPlayersID = NAMEKEY_INVALID;
  103. static NameKeyType listboxLobbyChatID = NAMEKEY_INVALID;
  104. static NameKeyType comboLobbyGroupRoomsID = NAMEKEY_INVALID;
  105. //static NameKeyType // sliderChatAdjustID = NAMEKEY_INVALID;
  106. // Window Pointers ------------------------------------------------------------------------
  107. static GameWindow *parentWOLLobby = NULL;
  108. static GameWindow *buttonBack = NULL;
  109. static GameWindow *buttonHost = NULL;
  110. static GameWindow *buttonRefresh = NULL;
  111. static GameWindow *buttonJoin = NULL;
  112. static GameWindow *buttonBuddy = NULL;
  113. static GameWindow *buttonEmote = NULL;
  114. static GameWindow *textEntryChat = NULL;
  115. static GameWindow *listboxLobbyPlayers = NULL;
  116. static GameWindow *listboxLobbyChat = NULL;
  117. static GameWindow *comboLobbyGroupRooms = NULL;
  118. static GameWindow *parent = NULL;
  119. static Int groupRoomToJoin = 0;
  120. static Int initialGadgetDelay = 2;
  121. static Bool justEntered = FALSE;
  122. #if defined(_INTERNAL) || defined(_DEBUG)
  123. Bool g_fakeCRC = FALSE;
  124. Bool g_debugSlots = FALSE;
  125. #endif
  126. std::list<PeerResponse> TheLobbyQueuedUTMs;
  127. // Slash commands -------------------------------------------------------------------------
  128. extern "C" {
  129. int getQR2HostingStatus(void);
  130. }
  131. extern int isThreadHosting;
  132. Bool handleLobbySlashCommands(UnicodeString uText)
  133. {
  134. AsciiString message;
  135. message.translate(uText);
  136. if (message.getCharAt(0) != '/')
  137. {
  138. return FALSE; // not a slash command
  139. }
  140. AsciiString remainder = message.str() + 1;
  141. AsciiString token;
  142. remainder.nextToken(&token);
  143. token.toLower();
  144. if (token == "host")
  145. {
  146. UnicodeString s;
  147. s.format(L"Hosting qr2:%d thread:%d", getQR2HostingStatus(), isThreadHosting);
  148. TheGameSpyInfo->addText(s, GameSpyColor[GSCOLOR_DEFAULT], NULL);
  149. return TRUE; // was a slash command
  150. }
  151. else if (token == "me" && uText.getLength()>4)
  152. {
  153. TheGameSpyInfo->sendChat(UnicodeString(uText.str()+4), TRUE, listboxLobbyPlayers);
  154. return TRUE; // was a slash command
  155. }
  156. else if (token == "refresh")
  157. {
  158. // Added 2/19/03 added the game refresh
  159. refreshGameList(TRUE);
  160. refreshPlayerList(TRUE);
  161. return TRUE; // was a slash command
  162. }
  163. /*
  164. if (token == "togglegamelist")
  165. {
  166. NameKeyType buttonID = NAMEKEY("WOLCustomLobby.wnd:ButtonGameListToggle");
  167. GameWindow *button = TheWindowManager->winGetWindowFromId(parent, buttonID);
  168. if (button)
  169. {
  170. button->winHide(!button->winIsHidden());
  171. }
  172. return TRUE; // was a slash command
  173. }
  174. else if (token == "adjustchat")
  175. {
  176. NameKeyType sliderID = NAMEKEY("WOLCustomLobby.wnd:SliderChatAdjust");
  177. GameWindow *slider = TheWindowManager->winGetWindowFromId(parent, sliderID);
  178. if (slider)
  179. {
  180. slider->winHide(!slider->winIsHidden());
  181. }
  182. return TRUE; // was a slash command
  183. }
  184. */
  185. #if defined(_INTERNAL) || defined(_DEBUG)
  186. else if (token == "fakecrc")
  187. {
  188. g_fakeCRC = !g_fakeCRC;
  189. TheGameSpyInfo->addText(UnicodeString(L"Toggled CRC fakery"), GameSpyColor[GSCOLOR_DEFAULT], NULL);
  190. return TRUE; // was a slash command
  191. }
  192. else if (token == "slots")
  193. {
  194. g_debugSlots = !g_debugSlots;
  195. TheGameSpyInfo->addText(UnicodeString(L"Toggled SlotList debug"), GameSpyColor[GSCOLOR_DEFAULT], NULL);
  196. return TRUE; // was a slash command
  197. }
  198. #endif
  199. return FALSE; // not a slash command
  200. }
  201. static Bool s_tryingToHostOrJoin = FALSE;
  202. void SetLobbyAttemptHostJoin(Bool start)
  203. {
  204. s_tryingToHostOrJoin = start;
  205. }
  206. // Tooltips -------------------------------------------------------------------------------
  207. static void playerTooltip(GameWindow *window,
  208. WinInstanceData *instData,
  209. UnsignedInt mouse)
  210. {
  211. Int x, y, row, col;
  212. x = LOLONGTOSHORT(mouse);
  213. y = HILONGTOSHORT(mouse);
  214. GadgetListBoxGetEntryBasedOnXY(window, x, y, row, col);
  215. if (row == -1 || col == -1)
  216. {
  217. TheMouse->setCursorTooltip( UnicodeString::TheEmptyString);//TheGameText->fetch("TOOLTIP:PlayersInLobby") );
  218. return;
  219. }
  220. UnicodeString uName = GadgetListBoxGetText(window, row, 2);
  221. AsciiString aName;
  222. aName.translate(uName);
  223. PlayerInfoMap::iterator it = TheGameSpyInfo->getPlayerInfoMap()->find(aName);
  224. PlayerInfo *info = &(it->second);
  225. Bool isLocalPlayer = (TheGameSpyInfo->getLocalName().compareNoCase(info->m_name) == 0);
  226. if (col == 0)
  227. {
  228. if (info->m_preorder)
  229. {
  230. TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:LobbyOfficersClub") );
  231. }
  232. else
  233. {
  234. TheMouse->setCursorTooltip( UnicodeString::TheEmptyString);
  235. }
  236. return;
  237. }
  238. AsciiString playerLocale = info->m_locale;
  239. AsciiString localeIdentifier;
  240. localeIdentifier.format("WOL:Locale%2.2d", atoi(playerLocale.str()));
  241. Int playerWins = info->m_wins;
  242. Int playerLosses = info->m_losses;
  243. UnicodeString playerInfo;
  244. playerInfo.format(TheGameText->fetch("TOOLTIP:PlayerInfo"), TheGameText->fetch(localeIdentifier).str(), playerWins, playerLosses);
  245. UnicodeString tooltip = UnicodeString::TheEmptyString;//TheGameText->fetch("TOOLTIP:PlayersInLobby");
  246. if (isLocalPlayer)
  247. {
  248. tooltip.format(TheGameText->fetch("TOOLTIP:LocalPlayer"), uName.str());
  249. }
  250. else
  251. {
  252. // not us
  253. if (TheGameSpyInfo->getBuddyMap()->find(info->m_profileID) != TheGameSpyInfo->getBuddyMap()->end())
  254. {
  255. // buddy
  256. tooltip.format(TheGameText->fetch("TOOLTIP:BuddyPlayer"), uName.str());
  257. }
  258. else
  259. {
  260. if (info->m_profileID)
  261. {
  262. // non-buddy profiled player
  263. tooltip.format(TheGameText->fetch("TOOLTIP:ProfiledPlayer"), uName.str());
  264. }
  265. else
  266. {
  267. // non-profiled player
  268. tooltip.format(TheGameText->fetch("TOOLTIP:GenericPlayer"), uName.str());
  269. }
  270. }
  271. }
  272. if (info->isIgnored())
  273. {
  274. tooltip.concat(TheGameText->fetch("TOOLTIP:IgnoredModifier"));
  275. }
  276. if (info->m_profileID)
  277. {
  278. tooltip.concat(playerInfo);
  279. }
  280. Int rank = 0;
  281. Int i = 0;
  282. while( info->m_rankPoints >= TheRankPointValues->m_ranks[i + 1])
  283. ++i;
  284. rank = i;
  285. AsciiString sideName = "GUI:RandomSide";
  286. if (info->m_side > 0)
  287. {
  288. const PlayerTemplate *fac = ThePlayerTemplateStore->getNthPlayerTemplate(info->m_side);
  289. if (fac)
  290. {
  291. sideName.format("SIDE:%s", fac->getSide().str());
  292. }
  293. }
  294. AsciiString rankName;
  295. rankName.format("GUI:GSRank%d", rank);
  296. UnicodeString tmp;
  297. tmp.format(L"\n%ls %ls", TheGameText->fetch(sideName).str(), TheGameText->fetch(rankName).str());
  298. tooltip.concat(tmp);
  299. TheMouse->setCursorTooltip( tooltip, -1, NULL, 1.5f ); // the text and width are the only params used. the others are the default values.
  300. }
  301. static void populateGroupRoomListbox(GameWindow *lb)
  302. {
  303. if (!lb)
  304. return;
  305. GadgetComboBoxReset(lb);
  306. Int indexToSelect = -1;
  307. GroupRoomMap::iterator iter;
  308. // now populate the combo box
  309. for (iter = TheGameSpyInfo->getGroupRoomList()->begin(); iter != TheGameSpyInfo->getGroupRoomList()->end(); ++iter)
  310. {
  311. GameSpyGroupRoom room = iter->second;
  312. if (room.m_groupID != TheGameSpyConfig->getQMChannel())
  313. {
  314. DEBUG_LOG(("populateGroupRoomListbox(): groupID %d\n", room.m_groupID));
  315. if (room.m_groupID == TheGameSpyInfo->getCurrentGroupRoom())
  316. {
  317. Int selected = GadgetComboBoxAddEntry(lb, room.m_translatedName, GameSpyColor[GSCOLOR_CURRENTROOM]);
  318. GadgetComboBoxSetItemData(lb, selected, (void *)(room.m_groupID));
  319. indexToSelect = selected;
  320. }
  321. else
  322. {
  323. Int selected = GadgetComboBoxAddEntry(lb, room.m_translatedName, GameSpyColor[GSCOLOR_ROOM]);
  324. GadgetComboBoxSetItemData(lb, selected, (void *)(room.m_groupID));
  325. }
  326. }
  327. else
  328. {
  329. DEBUG_LOG(("populateGroupRoomListbox(): skipping QM groupID %d\n", room.m_groupID));
  330. }
  331. }
  332. GadgetComboBoxSetSelectedPos(lb, indexToSelect);
  333. }
  334. static const char *rankNames[] = {
  335. "Private",
  336. "Corporal",
  337. "Sergeant",
  338. "Lieutenant",
  339. "Captain",
  340. "Major",
  341. "Colonel",
  342. "General",
  343. "Brigadier",
  344. "Commander",
  345. };
  346. const Image* LookupSmallRankImage(Int side, Int rankPoints)
  347. {
  348. if (rankPoints == 0)
  349. return NULL;
  350. Int rank = 0;
  351. Int i = 0;
  352. while( rankPoints >= TheRankPointValues->m_ranks[i + 1])
  353. ++i;
  354. rank = i;
  355. if (rank < 0 || rank >= 10)
  356. return NULL;
  357. AsciiString sideStr = "N";
  358. switch(side)
  359. {
  360. case 2:
  361. sideStr = "USA";
  362. break;
  363. case 3:
  364. sideStr = "CHA";
  365. break;
  366. case 4:
  367. sideStr = "GLA";
  368. break;
  369. }
  370. AsciiString fullImageName;
  371. fullImageName.format("%s-%s", rankNames[rank], sideStr.str());
  372. const Image *img = TheMappedImageCollection->findImageByName(fullImageName);
  373. DEBUG_ASSERTLOG(img, ("*** Could not load small rank image '%s' from TheMappedImageCollection!\n", fullImageName.str()));
  374. return img;
  375. }
  376. static Int insertPlayerInListbox(const PlayerInfo& info, Color color)
  377. {
  378. UnicodeString uStr;
  379. uStr.translate(info.m_name);
  380. Int currentRank = info.m_rankPoints;
  381. Int currentSide = info.m_side;
  382. /* since PersistentStorage updates now update PlayerInfo, we don't need this.
  383. if (info.m_profileID)
  384. {
  385. PSPlayerStats psStats = TheGameSpyPSMessageQueue->findPlayerStatsByID(info.m_profileID);
  386. if (psStats.id)
  387. {
  388. currentRank = CalculateRank(psStats);
  389. PerGeneralMap::iterator it;
  390. Int numGames = 0;
  391. for(it = psStats.games.begin(); it != psStats.games.end(); ++it)
  392. {
  393. if(it->second >= numGames)
  394. {
  395. numGames = it->second;
  396. currentSide = it->first;
  397. }
  398. }
  399. if(numGames == 0 || psStats.gamesAsRandom >= numGames )
  400. {
  401. currentSide = 0;
  402. }
  403. }
  404. }
  405. */
  406. Bool isPreorder = TheGameSpyInfo->didPlayerPreorder(info.m_profileID);
  407. const Image *preorderImg = TheMappedImageCollection->findImageByName("OfficersClubsmall");
  408. Int w = (preorderImg)?preorderImg->getImageWidth():10;
  409. //Int h = (preorderImg)?preorderImg->getImageHeight():10;
  410. w = min(GadgetListBoxGetColumnWidth(listboxLobbyPlayers, 0), w);
  411. Int h = w;
  412. if (!isPreorder)
  413. preorderImg = NULL;
  414. const Image *rankImg = LookupSmallRankImage(currentSide, currentRank);
  415. Int index = GadgetListBoxAddEntryImage(listboxLobbyPlayers, preorderImg, -1, 0, w, h);
  416. GadgetListBoxAddEntryImage(listboxLobbyPlayers, rankImg, index, 1, w, h);
  417. GadgetListBoxAddEntryText(listboxLobbyPlayers, uStr, color, index, 2);
  418. return index;
  419. }
  420. void PopulateLobbyPlayerListbox(void)
  421. {
  422. if (!listboxLobbyPlayers)
  423. return;
  424. // Display players
  425. PlayerInfoMap *players = TheGameSpyInfo->getPlayerInfoMap();
  426. PlayerInfoMap::iterator it;
  427. BuddyInfoMap *buddies = TheGameSpyInfo->getBuddyMap();
  428. BuddyInfoMap::iterator bIt;
  429. if (listboxLobbyPlayers)
  430. {
  431. // save off old selection
  432. Int maxSelectedItems = GadgetListBoxGetNumEntries(listboxLobbyPlayers);
  433. Int *selectedIndices;
  434. GadgetListBoxGetSelected(listboxLobbyPlayers, (Int *)(&selectedIndices));
  435. std::set<AsciiString> selectedNames;
  436. std::set<AsciiString>::const_iterator selIt;
  437. std::set<Int> indicesToSelect;
  438. UnicodeString uStr;
  439. Int numSelected = 0;
  440. for (Int i=0; i<maxSelectedItems; ++i)
  441. {
  442. if (selectedIndices[i] < 0)
  443. {
  444. break;
  445. }
  446. ++numSelected;
  447. AsciiString selectedName;
  448. uStr = GadgetListBoxGetText(listboxLobbyPlayers, selectedIndices[i], 2);
  449. selectedName.translate(uStr);
  450. selectedNames.insert(selectedName);
  451. DEBUG_LOG(("Saving off old selection %d (%s)\n", selectedIndices[i], selectedName.str()));
  452. }
  453. // save off old top entry
  454. Int previousTopIndex = GadgetListBoxGetTopVisibleEntry(listboxLobbyPlayers);
  455. GadgetListBoxReset(listboxLobbyPlayers);
  456. // Ops
  457. for (it = players->begin(); it != players->end(); ++it)
  458. {
  459. PlayerInfo info = it->second;
  460. if (info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID))
  461. {
  462. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_OWNER]);
  463. selIt = selectedNames.find(info.m_name);
  464. if (selIt != selectedNames.end())
  465. {
  466. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  467. indicesToSelect.insert(index);
  468. }
  469. }
  470. }
  471. // Buddies
  472. for (it = players->begin(); it != players->end(); ++it)
  473. {
  474. PlayerInfo info = it->second;
  475. bIt = buddies->find(info.m_profileID);
  476. if ( !(info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID)) && bIt != buddies->end() )
  477. {
  478. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_BUDDY]);
  479. selIt = selectedNames.find(info.m_name);
  480. if (selIt != selectedNames.end())
  481. {
  482. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  483. indicesToSelect.insert(index);
  484. }
  485. }
  486. }
  487. // Everyone else
  488. for (it = players->begin(); it != players->end(); ++it)
  489. {
  490. PlayerInfo info = it->second;
  491. bIt = buddies->find(info.m_profileID);
  492. if ( !(info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID)) && bIt == buddies->end() )
  493. {
  494. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
  495. selIt = selectedNames.find(info.m_name);
  496. if (selIt != selectedNames.end())
  497. {
  498. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  499. indicesToSelect.insert(index);
  500. }
  501. }
  502. }
  503. // restore selection
  504. if (indicesToSelect.size())
  505. {
  506. std::set<Int>::const_iterator indexIt;
  507. Int *newIndices = NEW Int[indicesToSelect.size()];
  508. for (i=0, indexIt = indicesToSelect.begin(); indexIt != indicesToSelect.end(); ++i, ++indexIt)
  509. {
  510. newIndices[i] = *indexIt;
  511. DEBUG_LOG(("Queueing up index %d to re-select\n", *indexIt));
  512. }
  513. GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, indicesToSelect.size());
  514. delete[] newIndices;
  515. }
  516. if (indicesToSelect.size() != numSelected)
  517. {
  518. TheWindowManager->winSetLoneWindow(NULL);
  519. }
  520. // restore top visible entry
  521. GadgetListBoxSetTopVisibleEntry(listboxLobbyPlayers, previousTopIndex);
  522. }
  523. }
  524. //-------------------------------------------------------------------------------------------------
  525. /** Initialize the WOL Lobby Menu */
  526. //-------------------------------------------------------------------------------------------------
  527. void WOLLobbyMenuInit( WindowLayout *layout, void *userData )
  528. {
  529. nextScreen = NULL;
  530. buttonPushed = false;
  531. isShuttingDown = false;
  532. SetLobbyAttemptHostJoin(FALSE); // not trying to host or join
  533. gameListRefreshTime = 0;
  534. playerListRefreshTime = 0;
  535. parentWOLLobbyID = TheNameKeyGenerator->nameToKey( AsciiString( "WOLCustomLobby.wnd:WOLLobbyMenuParent" ) );
  536. parent = TheWindowManager->winGetWindowFromId(NULL, parentWOLLobbyID);
  537. buttonBackID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonBack"));
  538. buttonBack = TheWindowManager->winGetWindowFromId(parent, buttonBackID);
  539. buttonHostID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonHost"));
  540. buttonHost = TheWindowManager->winGetWindowFromId(parent, buttonHostID);
  541. buttonRefreshID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonRefresh"));
  542. buttonRefresh = TheWindowManager->winGetWindowFromId(parent, buttonRefreshID);
  543. buttonJoinID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonJoin"));
  544. buttonJoin = TheWindowManager->winGetWindowFromId(parent, buttonJoinID);
  545. buttonJoin->winEnable(FALSE);
  546. buttonBuddyID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonBuddy"));
  547. buttonBuddy = TheWindowManager->winGetWindowFromId(parent, buttonBuddyID);
  548. buttonEmoteID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonEmote"));
  549. buttonEmote = TheWindowManager->winGetWindowFromId(parent, buttonEmoteID);
  550. textEntryChatID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:TextEntryChat"));
  551. textEntryChat = TheWindowManager->winGetWindowFromId(parent, textEntryChatID);
  552. listboxLobbyPlayersID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ListboxPlayers"));
  553. listboxLobbyPlayers = TheWindowManager->winGetWindowFromId(parent, listboxLobbyPlayersID);
  554. listboxLobbyPlayers->winSetTooltipFunc(playerTooltip);
  555. listboxLobbyChatID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ListboxChat"));
  556. listboxLobbyChat = TheWindowManager->winGetWindowFromId(parent, listboxLobbyChatID);
  557. TheGameSpyInfo->registerTextWindow(listboxLobbyChat);
  558. comboLobbyGroupRoomsID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ComboBoxGroupRooms"));
  559. comboLobbyGroupRooms = TheWindowManager->winGetWindowFromId(parent, comboLobbyGroupRoomsID);
  560. GadgetTextEntrySetText(textEntryChat, UnicodeString.TheEmptyString);
  561. populateGroupRoomListbox(comboLobbyGroupRooms);
  562. // Show Menu
  563. layout->hide( FALSE );
  564. // if we're not in a room, this will join the best available one
  565. if (!TheGameSpyInfo->getCurrentGroupRoom())
  566. {
  567. if (groupRoomToJoin)
  568. {
  569. DEBUG_LOG(("WOLLobbyMenuInit() - rejoining group room %d\n", groupRoomToJoin));
  570. TheGameSpyInfo->joinGroupRoom(groupRoomToJoin);
  571. groupRoomToJoin = 0;
  572. }
  573. else
  574. {
  575. DEBUG_LOG(("WOLLobbyMenuInit() - joining best group room\n"));
  576. TheGameSpyInfo->joinBestGroupRoom();
  577. }
  578. }
  579. else
  580. {
  581. DEBUG_LOG(("WOLLobbyMenuInit() - not joining group room because we're already in one\n"));
  582. }
  583. GrabWindowInfo();
  584. TheGameSpyInfo->clearStagingRoomList();
  585. PeerRequest req;
  586. req.peerRequestType = PeerRequest::PEERREQUEST_STARTGAMELIST;
  587. req.gameList.restrictGameList = TheGameSpyConfig->restrictGamesToLobby();
  588. TheGameSpyPeerMessageQueue->addRequest(req);
  589. // animate controls
  590. // TheShell->registerWithAnimateManager(parent, WIN_ANIMATION_SLIDE_TOP, TRUE);
  591. TheShell->showShellMap(TRUE);
  592. TheGameSpyGame->reset();
  593. CustomMatchPreferences pref;
  594. // GameWindow *slider = TheWindowManager->winGetWindowFromId(parent, sliderChatAdjustID);
  595. // if (slider)
  596. // {
  597. // GadgetSliderSetPosition(slider, pref.getChatSizeSlider());
  598. // doSliderTrack(slider, pref.getChatSizeSlider());
  599. // }
  600. //
  601. if (pref.usesLongGameList())
  602. {
  603. ToggleGameListType();
  604. }
  605. // Set Keyboard to chat window
  606. TheWindowManager->winSetFocus( textEntryChat );
  607. raiseMessageBoxes = true;
  608. TheLobbyQueuedUTMs.clear();
  609. justEntered = TRUE;
  610. initialGadgetDelay = 2;
  611. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("WOLCustomLobby.wnd:GadgetParent"));
  612. if(win)
  613. win->winHide(TRUE);
  614. DontShowMainMenu = TRUE;
  615. } // WOLLobbyMenuInit
  616. //-------------------------------------------------------------------------------------------------
  617. /** This is called when a shutdown is complete for this menu */
  618. //-------------------------------------------------------------------------------------------------
  619. static void shutdownComplete( WindowLayout *layout )
  620. {
  621. isShuttingDown = false;
  622. // hide the layout
  623. layout->hide( TRUE );
  624. // our shutdown is complete
  625. TheShell->shutdownComplete( layout, (nextScreen != NULL) );
  626. if (nextScreen != NULL)
  627. {
  628. TheShell->push(nextScreen);
  629. }
  630. nextScreen = NULL;
  631. } // end if
  632. //-------------------------------------------------------------------------------------------------
  633. /** WOL Lobby Menu shutdown method */
  634. //-------------------------------------------------------------------------------------------------
  635. void WOLLobbyMenuShutdown( WindowLayout *layout, void *userData )
  636. {
  637. CustomMatchPreferences pref;
  638. // GameWindow *slider = TheWindowManager->winGetWindowFromId(parent, sliderChatAdjustID);
  639. // if (slider)
  640. // {
  641. // pref.setChatSizeSlider(GadgetSliderGetPosition(slider));
  642. // }
  643. if (GetGameInfoListBox())
  644. {
  645. pref.setUsesLongGameList(FALSE);
  646. }
  647. else
  648. {
  649. pref.setUsesLongGameList(TRUE);
  650. }
  651. pref.write();
  652. ReleaseWindowInfo();
  653. TheGameSpyInfo->unregisterTextWindow(listboxLobbyChat);
  654. //TheGameSpyChat->stopListingGames();
  655. PeerRequest req;
  656. req.peerRequestType = PeerRequest::PEERREQUEST_STOPGAMELIST;
  657. TheGameSpyPeerMessageQueue->addRequest(req);
  658. listboxLobbyChat = NULL;
  659. listboxLobbyPlayers = NULL;
  660. isShuttingDown = true;
  661. // if we are shutting down for an immediate pop, skip the animations
  662. Bool popImmediate = *(Bool *)userData;
  663. if( popImmediate )
  664. {
  665. shutdownComplete( layout );
  666. return;
  667. } //end if
  668. TheShell->reverseAnimatewindow();
  669. DontShowMainMenu = FALSE;
  670. RaiseGSMessageBox();
  671. TheTransitionHandler->reverse("WOLCustomLobbyFade");
  672. } // WOLLobbyMenuShutdown
  673. static void fillPlayerInfo(const PeerResponse *resp, PlayerInfo *info)
  674. {
  675. info->m_name = resp->nick.c_str();
  676. info->m_profileID = resp->player.profileID;
  677. info->m_flags = resp->player.flags;
  678. info->m_wins = resp->player.wins;
  679. info->m_losses = resp->player.losses;
  680. info->m_locale = resp->locale.c_str();
  681. info->m_rankPoints= resp->player.rankPoints;
  682. info->m_side = resp->player.side;
  683. info->m_preorder = resp->player.preorder;
  684. }
  685. #ifdef PERF_TEST
  686. static const char* getMessageString(Int t)
  687. {
  688. switch(t)
  689. {
  690. case PeerResponse::PEERRESPONSE_LOGIN:
  691. return "login";
  692. case PeerResponse::PEERRESPONSE_DISCONNECT:
  693. return "disconnect";
  694. case PeerResponse::PEERRESPONSE_MESSAGE:
  695. return "message";
  696. case PeerResponse::PEERRESPONSE_GROUPROOM:
  697. return "group room";
  698. case PeerResponse::PEERRESPONSE_STAGINGROOM:
  699. return "staging room";
  700. case PeerResponse::PEERRESPONSE_STAGINGROOMPLAYERINFO:
  701. return "staging room player info";
  702. case PeerResponse::PEERRESPONSE_JOINGROUPROOM:
  703. return "group room join";
  704. case PeerResponse::PEERRESPONSE_CREATESTAGINGROOM:
  705. return "staging room create";
  706. case PeerResponse::PEERRESPONSE_JOINSTAGINGROOM:
  707. return "staging room join";
  708. case PeerResponse::PEERRESPONSE_PLAYERJOIN:
  709. return "player join";
  710. case PeerResponse::PEERRESPONSE_PLAYERLEFT:
  711. return "player part";
  712. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDNICK:
  713. return "player nick";
  714. case PeerResponse::PEERRESPONSE_PLAYERINFO:
  715. return "player info";
  716. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDFLAGS:
  717. return "player flags";
  718. case PeerResponse::PEERRESPONSE_ROOMUTM:
  719. return "room UTM";
  720. case PeerResponse::PEERRESPONSE_PLAYERUTM:
  721. return "player UTM";
  722. case PeerResponse::PEERRESPONSE_QUICKMATCHSTATUS:
  723. return "QM status";
  724. case PeerResponse::PEERRESPONSE_GAMESTART:
  725. return "game start";
  726. case PeerResponse::PEERRESPONSE_FAILEDTOHOST:
  727. return "host failure";
  728. }
  729. return "unknown";
  730. }
  731. #endif // PERF_TEST
  732. //-------------------------------------------------------------------------------------------------
  733. /** refreshGameList
  734. The Bool is used to force refresh if the refresh button was hit.*/
  735. //-------------------------------------------------------------------------------------------------
  736. static void refreshGameList( Bool forceRefresh )
  737. {
  738. Int refreshInterval = gameListRefreshInterval;
  739. if (forceRefresh || ((gameListRefreshTime == 0) || ((gameListRefreshTime + refreshInterval) <= timeGetTime())))
  740. {
  741. if (TheGameSpyInfo->hasStagingRoomListChanged())
  742. {
  743. //DEBUG_LOG(("################### refreshing game list\n"));
  744. //DEBUG_LOG(("gameRefreshTime=%d, refreshInterval=%d, now=%d\n", gameListRefreshTime, refreshInterval, timeGetTime()));
  745. RefreshGameListBoxes();
  746. gameListRefreshTime = timeGetTime();
  747. } else {
  748. //DEBUG_LOG(("-"));
  749. }
  750. } else {
  751. //DEBUG_LOG(("gameListRefreshTime: %d refreshInterval: %d\n"));
  752. }
  753. }
  754. //-------------------------------------------------------------------------------------------------
  755. /** refreshPlayerList
  756. The Bool is used to force refresh if the refresh button was hit.*/
  757. //-------------------------------------------------------------------------------------------------
  758. static void refreshPlayerList( Bool forceRefresh )
  759. {
  760. Int refreshInterval = playerListRefreshInterval;
  761. if (forceRefresh ||((playerListRefreshTime == 0) || ((playerListRefreshTime + refreshInterval) <= timeGetTime())))
  762. {
  763. PopulateLobbyPlayerListbox();
  764. playerListRefreshTime = timeGetTime();
  765. }
  766. }
  767. //-------------------------------------------------------------------------------------------------
  768. /** WOL Lobby Menu update method */
  769. //-------------------------------------------------------------------------------------------------
  770. void WOLLobbyMenuUpdate( WindowLayout * layout, void *userData)
  771. {
  772. if(justEntered)
  773. {
  774. if(initialGadgetDelay == 1)
  775. {
  776. TheTransitionHandler->remove("MainMenuDefaultMenuLogoFade");
  777. TheTransitionHandler->setGroup("WOLCustomLobbyFade");
  778. initialGadgetDelay = 2;
  779. justEntered = FALSE;
  780. }
  781. else
  782. initialGadgetDelay--;
  783. }
  784. if (TheGameLogic->isInShellGame() && TheGameLogic->getFrame() == 1)
  785. {
  786. SignalUIInteraction(SHELL_SCRIPT_HOOK_GENERALS_ONLINE_ENTERED_FROM_GAME);
  787. }
  788. // We'll only be successful if we've requested to
  789. if(isShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  790. shutdownComplete(layout);
  791. if (raiseMessageBoxes)
  792. {
  793. RaiseGSMessageBox();
  794. raiseMessageBoxes = false;
  795. }
  796. if (TheShell->isAnimFinished() && TheTransitionHandler->isFinished() && !buttonPushed && TheGameSpyPeerMessageQueue)
  797. {
  798. HandleBuddyResponses();
  799. HandlePersistentStorageResponses();
  800. #ifdef PERF_TEST
  801. UnsignedInt start = timeGetTime();
  802. UnsignedInt end = timeGetTime();
  803. std::list<Int> responses;
  804. Int numMessages = 0;
  805. #endif // PERF_TEST
  806. Int allowedMessages = TheGameSpyInfo->getMaxMessagesPerUpdate();
  807. Bool sawImportantMessage = FALSE;
  808. Bool shouldRepopulatePlayers = FALSE;
  809. PeerResponse resp;
  810. while (allowedMessages-- && !sawImportantMessage && TheGameSpyPeerMessageQueue->getResponse( resp ))
  811. {
  812. #ifdef PERF_TEST
  813. ++numMessages;
  814. responses.push_back(resp.peerResponseType);
  815. #endif // PERF_TEST
  816. switch (resp.peerResponseType)
  817. {
  818. case PeerResponse::PEERRESPONSE_JOINGROUPROOM:
  819. sawImportantMessage = TRUE;
  820. if (resp.joinGroupRoom.ok)
  821. {
  822. //buttonPushed = true;
  823. TheGameSpyInfo->setCurrentGroupRoom(resp.joinGroupRoom.id);
  824. TheGameSpyInfo->getPlayerInfoMap()->clear();
  825. GroupRoomMap::iterator iter = TheGameSpyInfo->getGroupRoomList()->find(resp.joinGroupRoom.id);
  826. if (iter != TheGameSpyInfo->getGroupRoomList()->end())
  827. {
  828. GameSpyGroupRoom room = iter->second;
  829. UnicodeString msg;
  830. msg.format(TheGameText->fetch("GUI:LobbyJoined"), room.m_translatedName.str());
  831. TheGameSpyInfo->addText(msg, GameSpyColor[GSCOLOR_DEFAULT], NULL);
  832. }
  833. }
  834. else
  835. {
  836. DEBUG_LOG(("WOLLobbyMenuUpdate() - joining best group room\n"));
  837. TheGameSpyInfo->joinBestGroupRoom();
  838. }
  839. populateGroupRoomListbox(comboLobbyGroupRooms);
  840. shouldRepopulatePlayers = TRUE;
  841. break;
  842. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDFLAGS:
  843. {
  844. PlayerInfo p;
  845. fillPlayerInfo(&resp, &p);
  846. TheGameSpyInfo->updatePlayerInfo(p);
  847. shouldRepopulatePlayers = TRUE;
  848. }
  849. break;
  850. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDNICK:
  851. {
  852. PlayerInfo p;
  853. fillPlayerInfo(&resp, &p);
  854. TheGameSpyInfo->updatePlayerInfo(p);
  855. shouldRepopulatePlayers = TRUE;
  856. }
  857. break;
  858. case PeerResponse::PEERRESPONSE_PLAYERINFO:
  859. {
  860. PlayerInfo p;
  861. fillPlayerInfo(&resp, &p);
  862. TheGameSpyInfo->updatePlayerInfo(p);
  863. shouldRepopulatePlayers = TRUE;
  864. }
  865. break;
  866. case PeerResponse::PEERRESPONSE_PLAYERJOIN:
  867. {
  868. if (resp.player.roomType == GroupRoom)
  869. {
  870. PlayerInfo p;
  871. fillPlayerInfo(&resp, &p);
  872. TheGameSpyInfo->updatePlayerInfo(p);
  873. shouldRepopulatePlayers = TRUE;
  874. }
  875. }
  876. break;
  877. case PeerResponse::PEERRESPONSE_PLAYERUTM:
  878. case PeerResponse::PEERRESPONSE_ROOMUTM:
  879. {
  880. DEBUG_LOG(("Putting off a UTM in the lobby\n"));
  881. TheLobbyQueuedUTMs.push_back(resp);
  882. }
  883. break;
  884. case PeerResponse::PEERRESPONSE_PLAYERLEFT:
  885. {
  886. PlayerInfo p;
  887. fillPlayerInfo(&resp, &p);
  888. TheGameSpyInfo->playerLeftGroupRoom(resp.nick.c_str());
  889. shouldRepopulatePlayers = TRUE;
  890. }
  891. break;
  892. case PeerResponse::PEERRESPONSE_MESSAGE:
  893. {
  894. TheGameSpyInfo->addChat(resp.nick.c_str(), resp.message.profileID,
  895. UnicodeString(resp.text.c_str()), !resp.message.isPrivate, resp.message.isAction, listboxLobbyChat);
  896. }
  897. break;
  898. case PeerResponse::PEERRESPONSE_DISCONNECT:
  899. {
  900. sawImportantMessage = TRUE;
  901. UnicodeString title, body;
  902. AsciiString disconMunkee;
  903. disconMunkee.format("GUI:GSDisconReason%d", resp.discon.reason);
  904. title = TheGameText->fetch( "GUI:GSErrorTitle" );
  905. body = TheGameText->fetch( disconMunkee );
  906. GameSpyCloseAllOverlays();
  907. GSMessageBoxOk( title, body );
  908. TheGameSpyInfo->reset();
  909. TheShell->pop();
  910. }
  911. case PeerResponse::PEERRESPONSE_CREATESTAGINGROOM:
  912. {
  913. sawImportantMessage = TRUE;
  914. SetLobbyAttemptHostJoin(FALSE);
  915. if (resp.createStagingRoom.result == PEERJoinSuccess)
  916. {
  917. // Woohoo! On to our next screen!
  918. buttonPushed = true;
  919. nextScreen = "Menus/GameSpyGameOptionsMenu.wnd";
  920. TheShell->pop();
  921. TheGameSpyInfo->markAsStagingRoomHost();
  922. TheGameSpyInfo->setGameOptions();
  923. }
  924. }
  925. break;
  926. case PeerResponse::PEERRESPONSE_JOINSTAGINGROOM:
  927. {
  928. sawImportantMessage = TRUE;
  929. SetLobbyAttemptHostJoin(FALSE);
  930. Bool isHostPresent = TRUE;
  931. if (resp.joinStagingRoom.ok == PEERTrue)
  932. {
  933. GameSpyStagingRoom *room = TheGameSpyInfo->getCurrentStagingRoom();
  934. if (!room)
  935. {
  936. isHostPresent = FALSE;
  937. }
  938. else
  939. {
  940. isHostPresent = FALSE;
  941. for (Int i=0; i<MAX_SLOTS; ++i)
  942. {
  943. AsciiString hostName;
  944. hostName.translate(room->getConstSlot(0)->getName());
  945. const char *firstPlayer = resp.stagingRoomPlayerNames[i].c_str();
  946. if (!strcmp(hostName.str(), firstPlayer))
  947. {
  948. DEBUG_LOG(("Saw host %s == %s in slot %d\n", hostName.str(), firstPlayer, i));
  949. isHostPresent = TRUE;
  950. }
  951. }
  952. }
  953. }
  954. if (resp.joinStagingRoom.ok == PEERTrue && isHostPresent)
  955. {
  956. // Woohoo! On to our next screen!
  957. buttonPushed = true;
  958. nextScreen = "Menus/GameSpyGameOptionsMenu.wnd";
  959. TheShell->pop();
  960. }
  961. else
  962. {
  963. UnicodeString s;
  964. switch(resp.joinStagingRoom.result)
  965. {
  966. case PEERFullRoom: // The room is full.
  967. s = TheGameText->fetch("GUI:JoinFailedRoomFull");
  968. break;
  969. case PEERInviteOnlyRoom: // The room is invite only.
  970. s = TheGameText->fetch("GUI:JoinFailedInviteOnly");
  971. break;
  972. case PEERBannedFromRoom: // The local user is banned from the room.
  973. s = TheGameText->fetch("GUI:JoinFailedBannedFromRoom");
  974. break;
  975. case PEERBadPassword: // An incorrect password (or none) was given for a passworded room.
  976. s = TheGameText->fetch("GUI:JoinFailedBadPassword");
  977. break;
  978. case PEERAlreadyInRoom: // The local user is already in or entering a room of the same type.
  979. s = TheGameText->fetch("GUI:JoinFailedAlreadyInRoom");
  980. break;
  981. case PEERNoConnection: // Can't join a room if there's no chat connection.
  982. s = TheGameText->fetch("GUI:JoinFailedNoConnection");
  983. break;
  984. default:
  985. s = TheGameText->fetch("GUI:JoinFailedDefault");
  986. break;
  987. }
  988. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), s);
  989. if (groupRoomToJoin)
  990. {
  991. DEBUG_LOG(("WOLLobbyMenuUpdate() - rejoining group room %d\n", groupRoomToJoin));
  992. TheGameSpyInfo->joinGroupRoom(groupRoomToJoin);
  993. groupRoomToJoin = 0;
  994. }
  995. else
  996. {
  997. DEBUG_LOG(("WOLLobbyMenuUpdate() - joining best group room\n"));
  998. TheGameSpyInfo->joinBestGroupRoom();
  999. }
  1000. }
  1001. }
  1002. break;
  1003. case PeerResponse::PEERRESPONSE_STAGINGROOMLISTCOMPLETE:
  1004. TheGameSpyInfo->sawFullGameList();
  1005. break;
  1006. case PeerResponse::PEERRESPONSE_STAGINGROOM:
  1007. {
  1008. GameSpyStagingRoom room;
  1009. switch(resp.stagingRoom.action)
  1010. {
  1011. case PEER_CLEAR:
  1012. TheGameSpyInfo->clearStagingRoomList();
  1013. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_CLEAR"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1014. break;
  1015. case PEER_ADD:
  1016. case PEER_UPDATE:
  1017. {
  1018. if (resp.stagingRoom.percentComplete == 100)
  1019. {
  1020. TheGameSpyInfo->sawFullGameList();
  1021. }
  1022. //if (ParseAsciiStringToGameInfo(&room, resp.stagingRoomMapName.c_str()))
  1023. //if (ParseAsciiStringToGameInfo(&room, resp.stagingServerGameOptions.c_str()))
  1024. Bool serverOk = TRUE;
  1025. if (!resp.stagingRoomMapName.length())
  1026. {
  1027. serverOk = FALSE;
  1028. }
  1029. // fix for ghost game problem - need to iterate over all resp.stagingRoomPlayerNames[i]
  1030. Bool sawSelf = FALSE;
  1031. //for (Int i=0; i<MAX_SLOTS; ++i)
  1032. //{
  1033. if (TheGameSpyInfo->getLocalName() == resp.stagingRoomPlayerNames[0].c_str())
  1034. {
  1035. sawSelf = TRUE; // don't show ghost games for myself
  1036. }
  1037. //}
  1038. if (sawSelf)
  1039. serverOk = FALSE;
  1040. if (serverOk)
  1041. {
  1042. room.setGameName(UnicodeString(resp.stagingServerName.c_str()));
  1043. room.setID(resp.stagingRoom.id);
  1044. room.setHasPassword(resp.stagingRoom.requiresPassword);
  1045. room.setVersion(resp.stagingRoom.version);
  1046. room.setExeCRC(resp.stagingRoom.exeCRC);
  1047. room.setIniCRC(resp.stagingRoom.iniCRC);
  1048. room.setAllowObservers(resp.stagingRoom.allowObservers);
  1049. room.setPingString(resp.stagingServerPingString.c_str());
  1050. room.setLadderIP(resp.stagingServerLadderIP.c_str());
  1051. room.setLadderPort(resp.stagingRoom.ladderPort);
  1052. room.setReportedNumPlayers(resp.stagingRoom.numPlayers);
  1053. room.setReportedMaxPlayers(resp.stagingRoom.maxPlayers);
  1054. room.setReportedNumObservers(resp.stagingRoom.numObservers);
  1055. Int i;
  1056. AsciiString gsMapName = resp.stagingRoomMapName.c_str();
  1057. AsciiString mapName = "";
  1058. for (i=0; i<gsMapName.getLength(); ++i)
  1059. {
  1060. char c = gsMapName.getCharAt(i);
  1061. if (c != '/')
  1062. mapName.concat(c);
  1063. else
  1064. mapName.concat('\\');
  1065. }
  1066. room.setMap(TheGameState->portableMapPathToRealMapPath(mapName));
  1067. Int numPlayers = 0;
  1068. for (i=0; i<MAX_SLOTS; ++i)
  1069. {
  1070. GameSpyGameSlot *slot = room.getGameSpySlot(i);
  1071. if (slot)
  1072. {
  1073. slot->setWins( resp.stagingRoom.wins[i] );
  1074. slot->setLosses( resp.stagingRoom.losses[i] );
  1075. slot->setProfileID( resp.stagingRoom.profileID[i] );
  1076. slot->setPlayerTemplate( resp.stagingRoom.faction[i] );
  1077. slot->setColor( resp.stagingRoom.color[i] );
  1078. if (resp.stagingRoom.profileID[i] == SLOT_EASY_AI)
  1079. {
  1080. slot->setState(SLOT_EASY_AI);
  1081. ++numPlayers;
  1082. }
  1083. else if (resp.stagingRoom.profileID[i] == SLOT_MED_AI)
  1084. {
  1085. slot->setState(SLOT_MED_AI);
  1086. ++numPlayers;
  1087. }
  1088. else if (resp.stagingRoom.profileID[i] == SLOT_BRUTAL_AI)
  1089. {
  1090. slot->setState(SLOT_BRUTAL_AI);
  1091. ++numPlayers;
  1092. }
  1093. else if (resp.stagingRoomPlayerNames[i].length())
  1094. {
  1095. UnicodeString nameUStr;
  1096. nameUStr.translate(resp.stagingRoomPlayerNames[i].c_str());
  1097. slot->setState(SLOT_PLAYER, nameUStr);
  1098. ++numPlayers;
  1099. }
  1100. else
  1101. {
  1102. slot->setState(SLOT_OPEN);
  1103. }
  1104. }
  1105. }
  1106. DEBUG_ASSERTCRASH(numPlayers, ("Game had no players!\n"));
  1107. //DEBUG_LOG(("Saw room: hasPass=%d, allowsObservers=%d\n", room.getHasPassword(), room.getAllowObservers()));
  1108. if (resp.stagingRoom.action == PEER_ADD)
  1109. {
  1110. TheGameSpyInfo->addStagingRoom(room);
  1111. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_ADD"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1112. }
  1113. else
  1114. {
  1115. TheGameSpyInfo->updateStagingRoom(room);
  1116. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_UPDATE"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1117. }
  1118. }
  1119. else
  1120. {
  1121. room.setID(resp.stagingRoom.id);
  1122. TheGameSpyInfo->removeStagingRoom(room);
  1123. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_UPDATE FAILED"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1124. }
  1125. break;
  1126. }
  1127. case PEER_REMOVE:
  1128. room.setID(resp.stagingRoom.id);
  1129. TheGameSpyInfo->removeStagingRoom(room);
  1130. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_REMOVE"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1131. break;
  1132. default:
  1133. //TheGameSpyInfo->addText( UnicodeString(L"gameList: Unknown"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1134. break;
  1135. }
  1136. }
  1137. break;
  1138. }
  1139. }
  1140. #if 0
  1141. if (shouldRepopulatePlayers)
  1142. {
  1143. PopulateLobbyPlayerListbox();
  1144. }
  1145. #else
  1146. refreshPlayerList();
  1147. #endif
  1148. #ifdef PERF_TEST
  1149. // check performance
  1150. end = timeGetTime();
  1151. PERF_LOG(("Frame time was %d ms\n", end-start));
  1152. std::list<Int>::const_iterator it;
  1153. for (it = responses.begin(); it != responses.end(); ++it)
  1154. {
  1155. PERF_LOG((" %s\n", getMessageString(*it)));
  1156. }
  1157. PERF_LOG(("\n"));
  1158. #endif // PERF_TEST
  1159. #if 0
  1160. // Removed 2-17-03 to pull out into a function so we can do the same checks
  1161. Int refreshInterval = gameListRefreshInterval;
  1162. if ((gameListRefreshTime == 0) || ((gameListRefreshTime + refreshInterval) <= timeGetTime()))
  1163. {
  1164. if (TheGameSpyInfo->hasStagingRoomListChanged())
  1165. {
  1166. //DEBUG_LOG(("################### refreshing game list\n"));
  1167. //DEBUG_LOG(("gameRefreshTime=%d, refreshInterval=%d, now=%d\n", gameListRefreshTime, refreshInterval, timeGetTime()));
  1168. RefreshGameListBoxes();
  1169. gameListRefreshTime = timeGetTime();
  1170. } else {
  1171. //DEBUG_LOG(("-"));
  1172. }
  1173. } else {
  1174. //DEBUG_LOG(("gameListRefreshTime: %d refreshInterval: %d\n"));
  1175. }
  1176. #else
  1177. refreshGameList();
  1178. #endif
  1179. }
  1180. }// WOLLobbyMenuUpdate
  1181. //-------------------------------------------------------------------------------------------------
  1182. /** WOL Lobby Menu input callback */
  1183. //-------------------------------------------------------------------------------------------------
  1184. WindowMsgHandledType WOLLobbyMenuInput( GameWindow *window, UnsignedInt msg,
  1185. WindowMsgData mData1, WindowMsgData mData2 )
  1186. {
  1187. switch( msg )
  1188. {
  1189. // --------------------------------------------------------------------------------------------
  1190. case GWM_CHAR:
  1191. {
  1192. UnsignedByte key = mData1;
  1193. UnsignedByte state = mData2;
  1194. if (buttonPushed)
  1195. break;
  1196. switch( key )
  1197. {
  1198. // ----------------------------------------------------------------------------------------
  1199. case KEY_ESC:
  1200. {
  1201. //
  1202. // send a simulated selected event to the parent window of the
  1203. // back/exit button
  1204. //
  1205. if( BitTest( state, KEY_STATE_UP ) )
  1206. {
  1207. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  1208. (WindowMsgData)buttonBack, buttonBackID );
  1209. } // end if
  1210. // don't let key fall through anywhere else
  1211. return MSG_HANDLED;
  1212. } // end escape
  1213. } // end switch( key )
  1214. } // end char
  1215. } // end switch( msg )
  1216. return MSG_IGNORED;
  1217. }// WOLLobbyMenuInput
  1218. //static void doSliderTrack(GameWindow *control, Int val)
  1219. //{
  1220. // Int sliderW, sliderH, sliderX, sliderY;
  1221. // control->winGetPosition(&sliderX, &sliderY);
  1222. // control->winGetSize(&sliderW, &sliderH);
  1223. // Real cursorY = sliderY + (100-val)*0.01f*sliderH;
  1224. //
  1225. // extern GameWindow *listboxLobbyGamesSmall;
  1226. // extern GameWindow *listboxLobbyGamesLarge;
  1227. // extern GameWindow *listboxLobbyGameInfo;
  1228. //
  1229. // static Int gwsX = 0, gwsY = 0, gwsW = 0, gwsH = 0;
  1230. // static Int gwlX = 0, gwlY = 0, gwlW = 0, gwlH = 0;
  1231. // static Int gwiX = 0, gwiY = 0, gwiW = 0, gwiH = 0;
  1232. // static Int pwX = 0, pwY = 0, pwW = 0, pwH = 0;
  1233. // static Int chatPosX = 0, chatPosY = 0, chatW = 0, chatH = 0;
  1234. // static Int spacing = 0;
  1235. // if (chatPosX == 0)
  1236. // {
  1237. // listboxLobbyChat->winGetPosition(&chatPosX, &chatPosY);
  1238. // listboxLobbyChat->winGetSize(&chatW, &chatH);
  1239. //
  1240. //// listboxLobbyGamesSmall->winGetPosition(&gwsX, &gwsY);
  1241. //// listboxLobbyGamesSmall->winGetSize(&gwsW, &gwsH);
  1242. //
  1243. // listboxLobbyGamesLarge->winGetPosition(&gwlX, &gwlY);
  1244. // listboxLobbyGamesLarge->winGetSize(&gwlW, &gwlH);
  1245. //
  1246. //// listboxLobbyGameInfo->winGetPosition(&gwiX, &gwiY);
  1247. //// listboxLobbyGameInfo->winGetSize(&gwiW, &gwiH);
  1248. ////
  1249. // listboxLobbyPlayers->winGetPosition(&pwX, &pwY);
  1250. // listboxLobbyPlayers->winGetSize(&pwW, &pwH);
  1251. //
  1252. // spacing = chatPosY - pwY - pwH;
  1253. // }
  1254. //
  1255. // Int newChatY = cursorY;
  1256. // Int newChatH = chatH + chatPosY - newChatY;
  1257. // listboxLobbyChat->winSetPosition(chatPosX, newChatY);
  1258. // listboxLobbyChat->winSetSize(chatW, newChatH);
  1259. //
  1260. // Int newH = cursorY - pwY - spacing;
  1261. // listboxLobbyPlayers->winSetSize(pwW, newH);
  1262. //// listboxLobbyGamesSmall->winSetSize(gwsW, newH);
  1263. // listboxLobbyGamesLarge->winSetSize(gwlW, newH);
  1264. //// listboxLobbyGameInfo->winSetSize(gwiW, newH);
  1265. //-------------------------------------------------------------------------------------------------
  1266. /** WOL Lobby Menu window system callback */
  1267. //-------------------------------------------------------------------------------------------------
  1268. WindowMsgHandledType WOLLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
  1269. WindowMsgData mData1, WindowMsgData mData2 )
  1270. {
  1271. UnicodeString txtInput;
  1272. static NameKeyType buttonGameListTypeToggleID = NAMEKEY_INVALID;
  1273. switch( msg )
  1274. {
  1275. //---------------------------------------------------------------------------------------------
  1276. case GWM_CREATE:
  1277. {
  1278. buttonGameListTypeToggleID = NAMEKEY("WOLCustomLobby.wnd:ButtonGameListToggle");
  1279. // sliderChatAdjustID = NAMEKEY("WOLCustomLobby.wnd:SliderChatAdjust");
  1280. break;
  1281. } // case GWM_DESTROY:
  1282. //---------------------------------------------------------------------------------------------
  1283. case GWM_DESTROY:
  1284. {
  1285. break;
  1286. } // case GWM_DESTROY:
  1287. //---------------------------------------------------------------------------------------------
  1288. case GWM_INPUT_FOCUS:
  1289. {
  1290. // if we're givin the opportunity to take the keyboard focus we must say we want it
  1291. if( mData1 == TRUE )
  1292. *(Bool *)mData2 = TRUE;
  1293. return MSG_HANDLED;
  1294. }//case GWM_INPUT_FOCUS:
  1295. //---------------------------------------------------------------------------------------------
  1296. case GLM_SELECTED:
  1297. {
  1298. GameWindow *control = (GameWindow *)mData1;
  1299. Int controlID = control->winGetWindowId();
  1300. if ( controlID == GetGameListBoxID() )
  1301. {
  1302. int rowSelected = mData2;
  1303. if( rowSelected >= 0 )
  1304. {
  1305. buttonJoin->winEnable(TRUE);
  1306. static UnsignedInt lastFrame = 0;
  1307. static Int lastID = -1;
  1308. UnsignedInt now = TheGameClient->getFrame();
  1309. PeerRequest req;
  1310. req.peerRequestType = PeerRequest::PEERREQUEST_GETEXTENDEDSTAGINGROOMINFO;
  1311. req.stagingRoom.id = (Int)GadgetListBoxGetItemData(control, rowSelected, 0);
  1312. if (lastID != req.stagingRoom.id || now > lastFrame + 60)
  1313. {
  1314. TheGameSpyPeerMessageQueue->addRequest(req);
  1315. }
  1316. lastID = req.stagingRoom.id;
  1317. lastFrame = now;
  1318. }
  1319. else
  1320. {
  1321. buttonJoin->winEnable(FALSE);
  1322. }
  1323. if (GetGameInfoListBox())
  1324. {
  1325. RefreshGameInfoListBox(GetGameListBox(), GetGameInfoListBox());
  1326. }
  1327. } //if ( controlID == GetGameListBoxID() )
  1328. break;
  1329. }
  1330. //---------------------------------------------------------------------------------------------
  1331. case GBM_SELECTED:
  1332. {
  1333. if (buttonPushed)
  1334. break;
  1335. GameWindow *control = (GameWindow *)mData1;
  1336. Int controlID = control->winGetWindowId();
  1337. if (HandleSortButton((NameKeyType)controlID))
  1338. break;
  1339. // If we back out, just bail - we haven't gotten far enough to need to log out
  1340. if ( controlID == buttonBackID )
  1341. {
  1342. if (s_tryingToHostOrJoin)
  1343. break;
  1344. // Leave any group room, then pop off the screen
  1345. TheGameSpyInfo->leaveGroupRoom();
  1346. SetLobbyAttemptHostJoin( TRUE ); // pretend, since we don't want to queue up another action
  1347. buttonPushed = true;
  1348. nextScreen = "Menus/WOLWelcomeMenu.wnd";
  1349. TheShell->pop();
  1350. } //if ( controlID == buttonBack )
  1351. else if ( controlID == buttonRefreshID )
  1352. {
  1353. // Added 2/17/03 added the game refresh button
  1354. refreshGameList(TRUE);
  1355. refreshPlayerList(TRUE);
  1356. }
  1357. else if ( controlID == buttonHostID )
  1358. {
  1359. if (s_tryingToHostOrJoin)
  1360. break;
  1361. SetLobbyAttemptHostJoin( TRUE );
  1362. TheLobbyQueuedUTMs.clear();
  1363. groupRoomToJoin = TheGameSpyInfo->getCurrentGroupRoom();
  1364. GameSpyOpenOverlay(GSOVERLAY_GAMEOPTIONS);
  1365. }
  1366. else if ( controlID == buttonJoinID )
  1367. {
  1368. if (s_tryingToHostOrJoin)
  1369. break;
  1370. TheLobbyQueuedUTMs.clear();
  1371. // Look for a game to join
  1372. groupRoomToJoin = TheGameSpyInfo->getCurrentGroupRoom();
  1373. Int selected;
  1374. GadgetListBoxGetSelected(GetGameListBox(), &selected);
  1375. if (selected >= 0)
  1376. {
  1377. Int selectedID = (Int)GadgetListBoxGetItemData(GetGameListBox(), selected);
  1378. if (selectedID > 0)
  1379. {
  1380. StagingRoomMap *srm = TheGameSpyInfo->getStagingRoomList();
  1381. StagingRoomMap::iterator srmIt = srm->find(selectedID);
  1382. if (srmIt != srm->end())
  1383. {
  1384. GameSpyStagingRoom *roomToJoin = srmIt->second;
  1385. if (!roomToJoin || roomToJoin->getExeCRC() != TheGlobalData->m_exeCRC || roomToJoin->getIniCRC() != TheGlobalData->m_iniCRC)
  1386. {
  1387. // bad crc. don't go.
  1388. DEBUG_LOG(("WOLLobbyMenuSystem - CRC mismatch with the game I'm trying to join. My CRC's - EXE:0x%08X INI:0x%08X Their CRC's - EXE:0x%08x INI:0x%08x\n", TheGlobalData->m_exeCRC, TheGlobalData->m_iniCRC, roomToJoin->getExeCRC(), roomToJoin->getIniCRC()));
  1389. #if defined(_DEBUG) || defined(_INTERNAL)
  1390. if (TheGlobalData->m_netMinPlayers)
  1391. {
  1392. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedCRCMismatch"));
  1393. break;
  1394. }
  1395. else if (g_fakeCRC)
  1396. {
  1397. TheWritableGlobalData->m_exeCRC = roomToJoin->getExeCRC();
  1398. TheWritableGlobalData->m_iniCRC = roomToJoin->getIniCRC();
  1399. }
  1400. #else
  1401. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedCRCMismatch"));
  1402. break;
  1403. #endif
  1404. }
  1405. Bool unknownLadder = (roomToJoin->getLadderPort() && TheLadderList->findLadder(roomToJoin->getLadderIP(), roomToJoin->getLadderPort()) == NULL);
  1406. if (unknownLadder)
  1407. {
  1408. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedUnknownLadder"));
  1409. break;
  1410. }
  1411. if (roomToJoin->getNumPlayers() == MAX_SLOTS)
  1412. {
  1413. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedRoomFull"));
  1414. break;
  1415. }
  1416. TheGameSpyInfo->markAsStagingRoomJoiner(selectedID);
  1417. TheGameSpyGame->setGameName(roomToJoin->getGameName());
  1418. TheGameSpyGame->setLadderIP(roomToJoin->getLadderIP());
  1419. TheGameSpyGame->setLadderPort(roomToJoin->getLadderPort());
  1420. SetLobbyAttemptHostJoin( TRUE );
  1421. if (roomToJoin->getHasPassword())
  1422. {
  1423. GameSpyOpenOverlay(GSOVERLAY_GAMEPASSWORD);
  1424. }
  1425. else
  1426. {
  1427. // no password - just join it
  1428. PeerRequest req;
  1429. req.peerRequestType = PeerRequest::PEERREQUEST_JOINSTAGINGROOM;
  1430. req.text = srmIt->second->getGameName().str();
  1431. req.stagingRoom.id = selectedID;
  1432. req.password = "";
  1433. TheGameSpyPeerMessageQueue->addRequest(req);
  1434. }
  1435. }
  1436. }
  1437. else
  1438. {
  1439. GSMessageBoxOk(TheGameText->fetch("GUI:Error"), TheGameText->fetch("GUI:NoGameInfo"), NULL);
  1440. }
  1441. }
  1442. else
  1443. {
  1444. GSMessageBoxOk(TheGameText->fetch("GUI:Error"), TheGameText->fetch("GUI:NoGameSelected"), NULL);
  1445. }
  1446. }
  1447. else if ( controlID == buttonBuddyID )
  1448. {
  1449. GameSpyToggleOverlay( GSOVERLAY_BUDDY );
  1450. }
  1451. else if ( controlID == buttonGameListTypeToggleID )
  1452. {
  1453. ToggleGameListType();
  1454. }
  1455. else if ( controlID == buttonEmoteID )
  1456. {
  1457. // read the user's input and clear the entry box
  1458. UnicodeString txtInput;
  1459. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1460. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1461. txtInput.trim();
  1462. if (!txtInput.isEmpty())
  1463. {
  1464. // Send the message
  1465. TheGameSpyInfo->sendChat( txtInput, FALSE, listboxLobbyPlayers ); // 'emote' button now just sends text
  1466. }
  1467. }
  1468. break;
  1469. }// case GBM_SELECTED:
  1470. //---------------------------------------------------------------------------------------------
  1471. case GCM_SELECTED:
  1472. {
  1473. if (s_tryingToHostOrJoin)
  1474. break;
  1475. GameWindow *control = (GameWindow *)mData1;
  1476. Int controlID = control->winGetWindowId();
  1477. if( controlID == comboLobbyGroupRoomsID )
  1478. {
  1479. int rowSelected = -1;
  1480. GadgetComboBoxGetSelectedPos(control, &rowSelected);
  1481. DEBUG_LOG(("Row selected = %d\n", rowSelected));
  1482. if (rowSelected >= 0)
  1483. {
  1484. Int groupID;
  1485. groupID = (Int)GadgetComboBoxGetItemData(comboLobbyGroupRooms, rowSelected);
  1486. DEBUG_LOG(("ItemData was %d, current Group Room is %d\n", groupID, TheGameSpyInfo->getCurrentGroupRoom()));
  1487. if (groupID && groupID != TheGameSpyInfo->getCurrentGroupRoom())
  1488. {
  1489. TheGameSpyInfo->leaveGroupRoom();
  1490. TheGameSpyInfo->joinGroupRoom(groupID);
  1491. if (TheGameSpyConfig->restrictGamesToLobby())
  1492. {
  1493. TheGameSpyInfo->clearStagingRoomList();
  1494. RefreshGameListBoxes();
  1495. PeerRequest req;
  1496. req.peerRequestType = PeerRequest::PEERREQUEST_STARTGAMELIST;
  1497. req.gameList.restrictGameList = TRUE;
  1498. TheGameSpyPeerMessageQueue->addRequest(req);
  1499. }
  1500. }
  1501. }
  1502. }
  1503. } // case GCM_SELECTED
  1504. break;
  1505. //---------------------------------------------------------------------------------------------
  1506. case GLM_DOUBLE_CLICKED:
  1507. {
  1508. if (buttonPushed)
  1509. break;
  1510. GameWindow *control = (GameWindow *)mData1;
  1511. Int controlID = control->winGetWindowId();
  1512. if (controlID == GetGameListBoxID())
  1513. {
  1514. int rowSelected = mData2;
  1515. if (rowSelected >= 0)
  1516. {
  1517. GadgetListBoxSetSelected( control, rowSelected );
  1518. GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonJoinID );
  1519. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  1520. (WindowMsgData)button, buttonJoinID );
  1521. }
  1522. }
  1523. break;
  1524. }// case GLM_DOUBLE_CLICKED:
  1525. //---------------------------------------------------------------------------------------------
  1526. case GLM_RIGHT_CLICKED:
  1527. {
  1528. GameWindow *control = (GameWindow *)mData1;
  1529. Int controlID = control->winGetWindowId();
  1530. if( controlID == listboxLobbyPlayersID )
  1531. {
  1532. RightClickStruct *rc = (RightClickStruct *)mData2;
  1533. WindowLayout *rcLayout = NULL;
  1534. GameWindow *rcMenu;
  1535. if(rc->pos < 0)
  1536. {
  1537. GadgetListBoxSetSelected(control, -1);
  1538. break;
  1539. }
  1540. GPProfile profileID = 0;
  1541. AsciiString aName;
  1542. aName.translate(GadgetListBoxGetText(control, rc->pos, COLUMN_PLAYERNAME));
  1543. PlayerInfoMap::iterator it = TheGameSpyInfo->getPlayerInfoMap()->find(aName);
  1544. if (it != TheGameSpyInfo->getPlayerInfoMap()->end())
  1545. profileID = it->second.m_profileID;
  1546. Bool isBuddy = FALSE;
  1547. if (profileID <= 0)
  1548. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCNoProfileMenu.wnd"));
  1549. else
  1550. {
  1551. if (profileID == TheGameSpyInfo->getLocalProfileID())
  1552. {
  1553. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCLocalPlayerMenu.wnd"));
  1554. }
  1555. else if(TheGameSpyInfo->isBuddy(profileID))
  1556. {
  1557. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCBuddiesMenu.wnd"));
  1558. isBuddy = TRUE;
  1559. }
  1560. else
  1561. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCNonBuddiesMenu.wnd"));
  1562. }
  1563. if(!rcLayout)
  1564. break;
  1565. GadgetListBoxSetSelected(control, rc->pos);
  1566. rcMenu = rcLayout->getFirstWindow();
  1567. rcMenu->winGetLayout()->runInit();
  1568. rcMenu->winBringToTop();
  1569. rcMenu->winHide(FALSE);
  1570. setUnignoreText( rcLayout, aName, profileID);
  1571. ICoord2D rcSize, rcPos;
  1572. rcMenu->winGetSize(&rcSize.x, &rcSize.y);
  1573. rcPos.x = rc->mouseX;
  1574. rcPos.y = rc->mouseY;
  1575. if(rc->mouseX + rcSize.x > TheDisplay->getWidth())
  1576. rcPos.x = TheDisplay->getWidth() - rcSize.x;
  1577. if(rc->mouseY + rcSize.y > TheDisplay->getHeight())
  1578. rcPos.y = TheDisplay->getHeight() - rcSize.y;
  1579. rcMenu->winSetPosition(rcPos.x, rcPos.y);
  1580. GameSpyRCMenuData *rcData = NEW GameSpyRCMenuData;
  1581. rcData->m_id = profileID;
  1582. rcData->m_nick = aName;
  1583. rcData->m_itemType = (isBuddy)?ITEM_BUDDY:ITEM_NONBUDDY;
  1584. rcMenu->winSetUserData((void *)rcData);
  1585. TheWindowManager->winSetLoneWindow(rcMenu);
  1586. }
  1587. else if( controlID == GetGameListBoxID() )
  1588. {
  1589. RightClickStruct *rc = (RightClickStruct *)mData2;
  1590. WindowLayout *rcLayout = NULL;
  1591. GameWindow *rcMenu;
  1592. if(rc->pos < 0)
  1593. {
  1594. GadgetListBoxSetSelected(control, -1);
  1595. break;
  1596. }
  1597. Int selectedID = (Int)GadgetListBoxGetItemData(control, rc->pos);
  1598. if (selectedID > 0)
  1599. {
  1600. StagingRoomMap *srm = TheGameSpyInfo->getStagingRoomList();
  1601. StagingRoomMap::iterator srmIt = srm->find(selectedID);
  1602. if (srmIt != srm->end())
  1603. {
  1604. GameSpyStagingRoom *theRoom = srmIt->second;
  1605. if (!theRoom)
  1606. break;
  1607. const LadderInfo *linfo = TheLadderList->findLadder(theRoom->getLadderIP(), theRoom->getLadderPort());
  1608. if (linfo)
  1609. {
  1610. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCGameDetailsMenu.wnd"));
  1611. if (!rcLayout)
  1612. break;
  1613. GadgetListBoxSetSelected(control, rc->pos);
  1614. rcMenu = rcLayout->getFirstWindow();
  1615. rcMenu->winGetLayout()->runInit();
  1616. rcMenu->winBringToTop();
  1617. rcMenu->winHide(FALSE);
  1618. rcMenu->winSetPosition(rc->mouseX, rc->mouseY);
  1619. rcMenu->winSetUserData((void *)selectedID);
  1620. TheWindowManager->winSetLoneWindow(rcMenu);
  1621. }
  1622. }
  1623. }
  1624. }
  1625. break;
  1626. }
  1627. // //---------------------------------------------------------------------------------------------
  1628. // case GSM_SLIDER_TRACK:
  1629. // {
  1630. // if (buttonPushed)
  1631. // break;
  1632. //
  1633. // GameWindow *control = (GameWindow *)mData1;
  1634. // Int val = (Int)mData2;
  1635. // Int controlID = control->winGetWindowId();
  1636. // if (controlID == sliderChatAdjustID)
  1637. // {
  1638. // doSliderTrack(control, val);
  1639. // }
  1640. // break;
  1641. // }
  1642. //---------------------------------------------------------------------------------------------
  1643. case GEM_EDIT_DONE:
  1644. {
  1645. if (buttonPushed)
  1646. break;
  1647. // read the user's input and clear the entry box
  1648. UnicodeString txtInput;
  1649. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1650. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1651. txtInput.trim();
  1652. if (!txtInput.isEmpty())
  1653. {
  1654. // Send the message
  1655. if (!handleLobbySlashCommands(txtInput))
  1656. {
  1657. TheGameSpyInfo->sendChat( txtInput, false, listboxLobbyPlayers );
  1658. }
  1659. }
  1660. break;
  1661. }
  1662. //---------------------------------------------------------------------------------------------
  1663. default:
  1664. return MSG_IGNORED;
  1665. }//Switch
  1666. return MSG_HANDLED;
  1667. }// WOLLobbyMenuSystem