WOLLobbyMenu.cpp 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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. ///////////////////////////////////////////////////////////////////////////////////////
  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 = 1 };
  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, COLUMN_PLAYERNAME);
  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: //USA
  361. case 5: //Super Weapon
  362. case 6: //Laser
  363. case 7: //Air Force
  364. sideStr = "USA";
  365. break;
  366. case 3: //China
  367. case 8: //Tank
  368. case 9: //Infantry
  369. case 10: //Nuke
  370. sideStr = "CHA";
  371. break;
  372. case 4: //GLA
  373. case 11: //Toxin
  374. case 12: //Demolition
  375. case 13: //Stealth
  376. sideStr = "GLA";
  377. break;
  378. }
  379. AsciiString fullImageName;
  380. fullImageName.format("%s-%s", rankNames[rank], sideStr.str());
  381. const Image *img = TheMappedImageCollection->findImageByName(fullImageName);
  382. DEBUG_ASSERTLOG(img, ("*** Could not load small rank image '%s' from TheMappedImageCollection!\n", fullImageName.str()));
  383. return img;
  384. }
  385. static Int insertPlayerInListbox(const PlayerInfo& info, Color color)
  386. {
  387. UnicodeString uStr;
  388. uStr.translate(info.m_name);
  389. Int currentRank = info.m_rankPoints;
  390. Int currentSide = info.m_side;
  391. /* since PersistentStorage updates now update PlayerInfo, we don't need this.
  392. if (info.m_profileID)
  393. {
  394. PSPlayerStats psStats = TheGameSpyPSMessageQueue->findPlayerStatsByID(info.m_profileID);
  395. if (psStats.id)
  396. {
  397. currentRank = CalculateRank(psStats);
  398. PerGeneralMap::iterator it;
  399. Int numGames = 0;
  400. for(it = psStats.games.begin(); it != psStats.games.end(); ++it)
  401. {
  402. if(it->second >= numGames)
  403. {
  404. numGames = it->second;
  405. currentSide = it->first;
  406. }
  407. }
  408. if(numGames == 0 || psStats.gamesAsRandom >= numGames )
  409. {
  410. currentSide = 0;
  411. }
  412. }
  413. }
  414. */
  415. Bool isPreorder = TheGameSpyInfo->didPlayerPreorder(info.m_profileID);
  416. const Image *preorderImg = TheMappedImageCollection->findImageByName("OfficersClubsmall");
  417. Int w = (preorderImg)?preorderImg->getImageWidth():10;
  418. //Int h = (preorderImg)?preorderImg->getImageHeight():10;
  419. w = min(GadgetListBoxGetColumnWidth(listboxLobbyPlayers, 0), w);
  420. Int h = w;
  421. if (!isPreorder)
  422. preorderImg = NULL;
  423. const Image *rankImg = LookupSmallRankImage(currentSide, currentRank);
  424. #if 0 //Officer's Club (preorder image) no longer used in Zero Hour
  425. Int index = GadgetListBoxAddEntryImage(listboxLobbyPlayers, preorderImg, -1, 0, w, h);
  426. GadgetListBoxAddEntryImage(listboxLobbyPlayers, rankImg, index, 1, w, h);
  427. GadgetListBoxAddEntryText(listboxLobbyPlayers, uStr, color, index, 2);
  428. #else
  429. Int index = GadgetListBoxAddEntryImage(listboxLobbyPlayers, rankImg, -1, 0, w, h);
  430. GadgetListBoxAddEntryText(listboxLobbyPlayers, uStr, color, index, 1);
  431. #endif
  432. return index;
  433. }
  434. void PopulateLobbyPlayerListbox(void)
  435. {
  436. if (!listboxLobbyPlayers)
  437. return;
  438. // Display players
  439. PlayerInfoMap *players = TheGameSpyInfo->getPlayerInfoMap();
  440. PlayerInfoMap::iterator it;
  441. BuddyInfoMap *buddies = TheGameSpyInfo->getBuddyMap();
  442. BuddyInfoMap::iterator bIt;
  443. if (listboxLobbyPlayers)
  444. {
  445. // save off old selection
  446. Int maxSelectedItems = GadgetListBoxGetNumEntries(listboxLobbyPlayers);
  447. Int *selectedIndices;
  448. GadgetListBoxGetSelected(listboxLobbyPlayers, (Int *)(&selectedIndices));
  449. std::set<AsciiString> selectedNames;
  450. std::set<AsciiString>::const_iterator selIt;
  451. std::set<Int> indicesToSelect;
  452. UnicodeString uStr;
  453. Int numSelected = 0;
  454. for (Int i=0; i<maxSelectedItems; ++i)
  455. {
  456. if (selectedIndices[i] < 0)
  457. {
  458. break;
  459. }
  460. ++numSelected;
  461. AsciiString selectedName;
  462. uStr = GadgetListBoxGetText(listboxLobbyPlayers, selectedIndices[i], COLUMN_PLAYERNAME);
  463. selectedName.translate(uStr);
  464. selectedNames.insert(selectedName);
  465. DEBUG_LOG(("Saving off old selection %d (%s)\n", selectedIndices[i], selectedName.str()));
  466. }
  467. // save off old top entry
  468. Int previousTopIndex = GadgetListBoxGetTopVisibleEntry(listboxLobbyPlayers);
  469. GadgetListBoxReset(listboxLobbyPlayers);
  470. // Ops
  471. for (it = players->begin(); it != players->end(); ++it)
  472. {
  473. PlayerInfo info = it->second;
  474. if (info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID))
  475. {
  476. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_OWNER]);
  477. selIt = selectedNames.find(info.m_name);
  478. if (selIt != selectedNames.end())
  479. {
  480. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  481. indicesToSelect.insert(index);
  482. }
  483. }
  484. }
  485. // Buddies
  486. for (it = players->begin(); it != players->end(); ++it)
  487. {
  488. PlayerInfo info = it->second;
  489. bIt = buddies->find(info.m_profileID);
  490. if ( !(info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID)) && bIt != buddies->end() )
  491. {
  492. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_BUDDY]);
  493. selIt = selectedNames.find(info.m_name);
  494. if (selIt != selectedNames.end())
  495. {
  496. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  497. indicesToSelect.insert(index);
  498. }
  499. }
  500. }
  501. // Everyone else
  502. for (it = players->begin(); it != players->end(); ++it)
  503. {
  504. PlayerInfo info = it->second;
  505. bIt = buddies->find(info.m_profileID);
  506. if ( !(info.m_flags & PEER_FLAG_OP || TheGameSpyConfig->isPlayerVIP(info.m_profileID)) && bIt == buddies->end() )
  507. {
  508. Int index = insertPlayerInListbox(info, info.isIgnored()?GameSpyColor[GSCOLOR_PLAYER_IGNORED]:GameSpyColor[GSCOLOR_PLAYER_NORMAL]);
  509. selIt = selectedNames.find(info.m_name);
  510. if (selIt != selectedNames.end())
  511. {
  512. DEBUG_LOG(("Marking index %d (%s) to re-select\n", index, info.m_name.str()));
  513. indicesToSelect.insert(index);
  514. }
  515. }
  516. }
  517. // restore selection
  518. if (indicesToSelect.size())
  519. {
  520. std::set<Int>::const_iterator indexIt;
  521. Int *newIndices = NEW Int[indicesToSelect.size()];
  522. for (i=0, indexIt = indicesToSelect.begin(); indexIt != indicesToSelect.end(); ++i, ++indexIt)
  523. {
  524. newIndices[i] = *indexIt;
  525. DEBUG_LOG(("Queueing up index %d to re-select\n", *indexIt));
  526. }
  527. GadgetListBoxSetSelected(listboxLobbyPlayers, newIndices, indicesToSelect.size());
  528. delete[] newIndices;
  529. }
  530. if (indicesToSelect.size() != numSelected)
  531. {
  532. TheWindowManager->winSetLoneWindow(NULL);
  533. }
  534. // restore top visible entry
  535. GadgetListBoxSetTopVisibleEntry(listboxLobbyPlayers, previousTopIndex);
  536. }
  537. }
  538. //-------------------------------------------------------------------------------------------------
  539. /** Initialize the WOL Lobby Menu */
  540. //-------------------------------------------------------------------------------------------------
  541. void WOLLobbyMenuInit( WindowLayout *layout, void *userData )
  542. {
  543. nextScreen = NULL;
  544. buttonPushed = false;
  545. isShuttingDown = false;
  546. SetLobbyAttemptHostJoin(FALSE); // not trying to host or join
  547. gameListRefreshTime = 0;
  548. playerListRefreshTime = 0;
  549. parentWOLLobbyID = TheNameKeyGenerator->nameToKey( AsciiString( "WOLCustomLobby.wnd:WOLLobbyMenuParent" ) );
  550. parent = TheWindowManager->winGetWindowFromId(NULL, parentWOLLobbyID);
  551. buttonBackID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonBack"));
  552. buttonBack = TheWindowManager->winGetWindowFromId(parent, buttonBackID);
  553. buttonHostID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonHost"));
  554. buttonHost = TheWindowManager->winGetWindowFromId(parent, buttonHostID);
  555. buttonRefreshID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonRefresh"));
  556. buttonRefresh = TheWindowManager->winGetWindowFromId(parent, buttonRefreshID);
  557. buttonJoinID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonJoin"));
  558. buttonJoin = TheWindowManager->winGetWindowFromId(parent, buttonJoinID);
  559. buttonJoin->winEnable(FALSE);
  560. buttonBuddyID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonBuddy"));
  561. buttonBuddy = TheWindowManager->winGetWindowFromId(parent, buttonBuddyID);
  562. buttonEmoteID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ButtonEmote"));
  563. buttonEmote = TheWindowManager->winGetWindowFromId(parent, buttonEmoteID);
  564. textEntryChatID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:TextEntryChat"));
  565. textEntryChat = TheWindowManager->winGetWindowFromId(parent, textEntryChatID);
  566. listboxLobbyPlayersID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ListboxPlayers"));
  567. listboxLobbyPlayers = TheWindowManager->winGetWindowFromId(parent, listboxLobbyPlayersID);
  568. listboxLobbyPlayers->winSetTooltipFunc(playerTooltip);
  569. listboxLobbyChatID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ListboxChat"));
  570. listboxLobbyChat = TheWindowManager->winGetWindowFromId(parent, listboxLobbyChatID);
  571. TheGameSpyInfo->registerTextWindow(listboxLobbyChat);
  572. comboLobbyGroupRoomsID = TheNameKeyGenerator->nameToKey(AsciiString("WOLCustomLobby.wnd:ComboBoxGroupRooms"));
  573. comboLobbyGroupRooms = TheWindowManager->winGetWindowFromId(parent, comboLobbyGroupRoomsID);
  574. GadgetTextEntrySetText(textEntryChat, UnicodeString.TheEmptyString);
  575. populateGroupRoomListbox(comboLobbyGroupRooms);
  576. // Show Menu
  577. layout->hide( FALSE );
  578. // if we're not in a room, this will join the best available one
  579. if (!TheGameSpyInfo->getCurrentGroupRoom())
  580. {
  581. if (groupRoomToJoin)
  582. {
  583. DEBUG_LOG(("WOLLobbyMenuInit() - rejoining group room %d\n", groupRoomToJoin));
  584. TheGameSpyInfo->joinGroupRoom(groupRoomToJoin);
  585. groupRoomToJoin = 0;
  586. }
  587. else
  588. {
  589. DEBUG_LOG(("WOLLobbyMenuInit() - joining best group room\n"));
  590. TheGameSpyInfo->joinBestGroupRoom();
  591. }
  592. }
  593. else
  594. {
  595. DEBUG_LOG(("WOLLobbyMenuInit() - not joining group room because we're already in one\n"));
  596. }
  597. GrabWindowInfo();
  598. TheGameSpyInfo->clearStagingRoomList();
  599. PeerRequest req;
  600. req.peerRequestType = PeerRequest::PEERREQUEST_STARTGAMELIST;
  601. req.gameList.restrictGameList = TheGameSpyConfig->restrictGamesToLobby();
  602. TheGameSpyPeerMessageQueue->addRequest(req);
  603. // animate controls
  604. // TheShell->registerWithAnimateManager(parent, WIN_ANIMATION_SLIDE_TOP, TRUE);
  605. TheShell->showShellMap(TRUE);
  606. TheGameSpyGame->reset();
  607. CustomMatchPreferences pref;
  608. // GameWindow *slider = TheWindowManager->winGetWindowFromId(parent, sliderChatAdjustID);
  609. // if (slider)
  610. // {
  611. // GadgetSliderSetPosition(slider, pref.getChatSizeSlider());
  612. // doSliderTrack(slider, pref.getChatSizeSlider());
  613. // }
  614. //
  615. if (pref.usesLongGameList())
  616. {
  617. ToggleGameListType();
  618. }
  619. // Set Keyboard to chat window
  620. TheWindowManager->winSetFocus( textEntryChat );
  621. raiseMessageBoxes = true;
  622. TheLobbyQueuedUTMs.clear();
  623. justEntered = TRUE;
  624. initialGadgetDelay = 2;
  625. GameWindow *win = TheWindowManager->winGetWindowFromId(NULL, TheNameKeyGenerator->nameToKey("WOLCustomLobby.wnd:GadgetParent"));
  626. if(win)
  627. win->winHide(TRUE);
  628. DontShowMainMenu = TRUE;
  629. } // WOLLobbyMenuInit
  630. //-------------------------------------------------------------------------------------------------
  631. /** This is called when a shutdown is complete for this menu */
  632. //-------------------------------------------------------------------------------------------------
  633. static void shutdownComplete( WindowLayout *layout )
  634. {
  635. isShuttingDown = false;
  636. // hide the layout
  637. layout->hide( TRUE );
  638. // our shutdown is complete
  639. TheShell->shutdownComplete( layout, (nextScreen != NULL) );
  640. if (nextScreen != NULL)
  641. {
  642. TheShell->push(nextScreen);
  643. }
  644. nextScreen = NULL;
  645. } // end if
  646. //-------------------------------------------------------------------------------------------------
  647. /** WOL Lobby Menu shutdown method */
  648. //-------------------------------------------------------------------------------------------------
  649. void WOLLobbyMenuShutdown( WindowLayout *layout, void *userData )
  650. {
  651. CustomMatchPreferences pref;
  652. // GameWindow *slider = TheWindowManager->winGetWindowFromId(parent, sliderChatAdjustID);
  653. // if (slider)
  654. // {
  655. // pref.setChatSizeSlider(GadgetSliderGetPosition(slider));
  656. // }
  657. if (GetGameInfoListBox())
  658. {
  659. pref.setUsesLongGameList(FALSE);
  660. }
  661. else
  662. {
  663. pref.setUsesLongGameList(TRUE);
  664. }
  665. pref.write();
  666. ReleaseWindowInfo();
  667. TheGameSpyInfo->unregisterTextWindow(listboxLobbyChat);
  668. //TheGameSpyChat->stopListingGames();
  669. PeerRequest req;
  670. req.peerRequestType = PeerRequest::PEERREQUEST_STOPGAMELIST;
  671. TheGameSpyPeerMessageQueue->addRequest(req);
  672. listboxLobbyChat = NULL;
  673. listboxLobbyPlayers = NULL;
  674. isShuttingDown = true;
  675. // if we are shutting down for an immediate pop, skip the animations
  676. Bool popImmediate = *(Bool *)userData;
  677. if( popImmediate )
  678. {
  679. shutdownComplete( layout );
  680. return;
  681. } //end if
  682. TheShell->reverseAnimatewindow();
  683. DontShowMainMenu = FALSE;
  684. RaiseGSMessageBox();
  685. TheTransitionHandler->reverse("WOLCustomLobbyFade");
  686. } // WOLLobbyMenuShutdown
  687. static void fillPlayerInfo(const PeerResponse *resp, PlayerInfo *info)
  688. {
  689. info->m_name = resp->nick.c_str();
  690. info->m_profileID = resp->player.profileID;
  691. info->m_flags = resp->player.flags;
  692. info->m_wins = resp->player.wins;
  693. info->m_losses = resp->player.losses;
  694. info->m_locale = resp->locale.c_str();
  695. info->m_rankPoints= resp->player.rankPoints;
  696. info->m_side = resp->player.side;
  697. info->m_preorder = resp->player.preorder;
  698. }
  699. #ifdef PERF_TEST
  700. static const char* getMessageString(Int t)
  701. {
  702. switch(t)
  703. {
  704. case PeerResponse::PEERRESPONSE_LOGIN:
  705. return "login";
  706. case PeerResponse::PEERRESPONSE_DISCONNECT:
  707. return "disconnect";
  708. case PeerResponse::PEERRESPONSE_MESSAGE:
  709. return "message";
  710. case PeerResponse::PEERRESPONSE_GROUPROOM:
  711. return "group room";
  712. case PeerResponse::PEERRESPONSE_STAGINGROOM:
  713. return "staging room";
  714. case PeerResponse::PEERRESPONSE_STAGINGROOMPLAYERINFO:
  715. return "staging room player info";
  716. case PeerResponse::PEERRESPONSE_JOINGROUPROOM:
  717. return "group room join";
  718. case PeerResponse::PEERRESPONSE_CREATESTAGINGROOM:
  719. return "staging room create";
  720. case PeerResponse::PEERRESPONSE_JOINSTAGINGROOM:
  721. return "staging room join";
  722. case PeerResponse::PEERRESPONSE_PLAYERJOIN:
  723. return "player join";
  724. case PeerResponse::PEERRESPONSE_PLAYERLEFT:
  725. return "player part";
  726. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDNICK:
  727. return "player nick";
  728. case PeerResponse::PEERRESPONSE_PLAYERINFO:
  729. return "player info";
  730. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDFLAGS:
  731. return "player flags";
  732. case PeerResponse::PEERRESPONSE_ROOMUTM:
  733. return "room UTM";
  734. case PeerResponse::PEERRESPONSE_PLAYERUTM:
  735. return "player UTM";
  736. case PeerResponse::PEERRESPONSE_QUICKMATCHSTATUS:
  737. return "QM status";
  738. case PeerResponse::PEERRESPONSE_GAMESTART:
  739. return "game start";
  740. case PeerResponse::PEERRESPONSE_FAILEDTOHOST:
  741. return "host failure";
  742. }
  743. return "unknown";
  744. }
  745. #endif // PERF_TEST
  746. //-------------------------------------------------------------------------------------------------
  747. /** refreshGameList
  748. The Bool is used to force refresh if the refresh button was hit.*/
  749. //-------------------------------------------------------------------------------------------------
  750. static void refreshGameList( Bool forceRefresh )
  751. {
  752. Int refreshInterval = gameListRefreshInterval;
  753. if (forceRefresh || ((gameListRefreshTime == 0) || ((gameListRefreshTime + refreshInterval) <= timeGetTime())))
  754. {
  755. if (TheGameSpyInfo->hasStagingRoomListChanged())
  756. {
  757. //DEBUG_LOG(("################### refreshing game list\n"));
  758. //DEBUG_LOG(("gameRefreshTime=%d, refreshInterval=%d, now=%d\n", gameListRefreshTime, refreshInterval, timeGetTime()));
  759. RefreshGameListBoxes();
  760. gameListRefreshTime = timeGetTime();
  761. } else {
  762. //DEBUG_LOG(("-"));
  763. }
  764. } else {
  765. //DEBUG_LOG(("gameListRefreshTime: %d refreshInterval: %d\n"));
  766. }
  767. }
  768. //-------------------------------------------------------------------------------------------------
  769. /** refreshPlayerList
  770. The Bool is used to force refresh if the refresh button was hit.*/
  771. //-------------------------------------------------------------------------------------------------
  772. static void refreshPlayerList( Bool forceRefresh )
  773. {
  774. Int refreshInterval = playerListRefreshInterval;
  775. if (forceRefresh ||((playerListRefreshTime == 0) || ((playerListRefreshTime + refreshInterval) <= timeGetTime())))
  776. {
  777. PopulateLobbyPlayerListbox();
  778. playerListRefreshTime = timeGetTime();
  779. }
  780. }
  781. //-------------------------------------------------------------------------------------------------
  782. /** WOL Lobby Menu update method */
  783. //-------------------------------------------------------------------------------------------------
  784. void WOLLobbyMenuUpdate( WindowLayout * layout, void *userData)
  785. {
  786. if(justEntered)
  787. {
  788. if(initialGadgetDelay == 1)
  789. {
  790. TheTransitionHandler->remove("MainMenuDefaultMenuLogoFade");
  791. TheTransitionHandler->setGroup("WOLCustomLobbyFade");
  792. initialGadgetDelay = 2;
  793. justEntered = FALSE;
  794. }
  795. else
  796. initialGadgetDelay--;
  797. }
  798. if (TheGameLogic->isInShellGame() && TheGameLogic->getFrame() == 1)
  799. {
  800. SignalUIInteraction(SHELL_SCRIPT_HOOK_GENERALS_ONLINE_ENTERED_FROM_GAME);
  801. }
  802. // We'll only be successful if we've requested to
  803. if(isShuttingDown && TheShell->isAnimFinished() && TheTransitionHandler->isFinished())
  804. shutdownComplete(layout);
  805. if (raiseMessageBoxes)
  806. {
  807. RaiseGSMessageBox();
  808. raiseMessageBoxes = false;
  809. }
  810. if (TheShell->isAnimFinished() && TheTransitionHandler->isFinished() && !buttonPushed && TheGameSpyPeerMessageQueue)
  811. {
  812. HandleBuddyResponses();
  813. HandlePersistentStorageResponses();
  814. #ifdef PERF_TEST
  815. UnsignedInt start = timeGetTime();
  816. UnsignedInt end = timeGetTime();
  817. std::list<Int> responses;
  818. Int numMessages = 0;
  819. #endif // PERF_TEST
  820. Int allowedMessages = TheGameSpyInfo->getMaxMessagesPerUpdate();
  821. Bool sawImportantMessage = FALSE;
  822. Bool shouldRepopulatePlayers = FALSE;
  823. PeerResponse resp;
  824. while (allowedMessages-- && !sawImportantMessage && TheGameSpyPeerMessageQueue->getResponse( resp ))
  825. {
  826. #ifdef PERF_TEST
  827. ++numMessages;
  828. responses.push_back(resp.peerResponseType);
  829. #endif // PERF_TEST
  830. switch (resp.peerResponseType)
  831. {
  832. case PeerResponse::PEERRESPONSE_JOINGROUPROOM:
  833. sawImportantMessage = TRUE;
  834. if (resp.joinGroupRoom.ok)
  835. {
  836. //buttonPushed = true;
  837. TheGameSpyInfo->setCurrentGroupRoom(resp.joinGroupRoom.id);
  838. TheGameSpyInfo->getPlayerInfoMap()->clear();
  839. GroupRoomMap::iterator iter = TheGameSpyInfo->getGroupRoomList()->find(resp.joinGroupRoom.id);
  840. if (iter != TheGameSpyInfo->getGroupRoomList()->end())
  841. {
  842. GameSpyGroupRoom room = iter->second;
  843. UnicodeString msg;
  844. msg.format(TheGameText->fetch("GUI:LobbyJoined"), room.m_translatedName.str());
  845. TheGameSpyInfo->addText(msg, GameSpyColor[GSCOLOR_DEFAULT], NULL);
  846. }
  847. }
  848. else
  849. {
  850. DEBUG_LOG(("WOLLobbyMenuUpdate() - joining best group room\n"));
  851. TheGameSpyInfo->joinBestGroupRoom();
  852. }
  853. populateGroupRoomListbox(comboLobbyGroupRooms);
  854. shouldRepopulatePlayers = TRUE;
  855. break;
  856. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDFLAGS:
  857. {
  858. PlayerInfo p;
  859. fillPlayerInfo(&resp, &p);
  860. TheGameSpyInfo->updatePlayerInfo(p);
  861. shouldRepopulatePlayers = TRUE;
  862. }
  863. break;
  864. case PeerResponse::PEERRESPONSE_PLAYERCHANGEDNICK:
  865. {
  866. PlayerInfo p;
  867. fillPlayerInfo(&resp, &p);
  868. TheGameSpyInfo->updatePlayerInfo(p);
  869. shouldRepopulatePlayers = TRUE;
  870. }
  871. break;
  872. case PeerResponse::PEERRESPONSE_PLAYERINFO:
  873. {
  874. PlayerInfo p;
  875. fillPlayerInfo(&resp, &p);
  876. TheGameSpyInfo->updatePlayerInfo(p);
  877. shouldRepopulatePlayers = TRUE;
  878. }
  879. break;
  880. case PeerResponse::PEERRESPONSE_PLAYERJOIN:
  881. {
  882. if (resp.player.roomType == GroupRoom)
  883. {
  884. PlayerInfo p;
  885. fillPlayerInfo(&resp, &p);
  886. TheGameSpyInfo->updatePlayerInfo(p);
  887. shouldRepopulatePlayers = TRUE;
  888. }
  889. }
  890. break;
  891. case PeerResponse::PEERRESPONSE_PLAYERUTM:
  892. case PeerResponse::PEERRESPONSE_ROOMUTM:
  893. {
  894. DEBUG_LOG(("Putting off a UTM in the lobby\n"));
  895. TheLobbyQueuedUTMs.push_back(resp);
  896. }
  897. break;
  898. case PeerResponse::PEERRESPONSE_PLAYERLEFT:
  899. {
  900. PlayerInfo p;
  901. fillPlayerInfo(&resp, &p);
  902. TheGameSpyInfo->playerLeftGroupRoom(resp.nick.c_str());
  903. shouldRepopulatePlayers = TRUE;
  904. }
  905. break;
  906. case PeerResponse::PEERRESPONSE_MESSAGE:
  907. {
  908. TheGameSpyInfo->addChat(resp.nick.c_str(), resp.message.profileID,
  909. UnicodeString(resp.text.c_str()), !resp.message.isPrivate, resp.message.isAction, listboxLobbyChat);
  910. }
  911. break;
  912. case PeerResponse::PEERRESPONSE_DISCONNECT:
  913. {
  914. sawImportantMessage = TRUE;
  915. UnicodeString title, body;
  916. AsciiString disconMunkee;
  917. disconMunkee.format("GUI:GSDisconReason%d", resp.discon.reason);
  918. title = TheGameText->fetch( "GUI:GSErrorTitle" );
  919. body = TheGameText->fetch( disconMunkee );
  920. GameSpyCloseAllOverlays();
  921. GSMessageBoxOk( title, body );
  922. TheGameSpyInfo->reset();
  923. TheShell->pop();
  924. }
  925. case PeerResponse::PEERRESPONSE_CREATESTAGINGROOM:
  926. {
  927. sawImportantMessage = TRUE;
  928. SetLobbyAttemptHostJoin(FALSE);
  929. if (resp.createStagingRoom.result == PEERJoinSuccess)
  930. {
  931. // Woohoo! On to our next screen!
  932. buttonPushed = true;
  933. nextScreen = "Menus/GameSpyGameOptionsMenu.wnd";
  934. TheShell->pop();
  935. TheGameSpyInfo->markAsStagingRoomHost();
  936. TheGameSpyInfo->setGameOptions();
  937. }
  938. }
  939. break;
  940. case PeerResponse::PEERRESPONSE_JOINSTAGINGROOM:
  941. {
  942. sawImportantMessage = TRUE;
  943. SetLobbyAttemptHostJoin(FALSE);
  944. Bool isHostPresent = TRUE;
  945. if (resp.joinStagingRoom.ok == PEERTrue)
  946. {
  947. GameSpyStagingRoom *room = TheGameSpyInfo->getCurrentStagingRoom();
  948. if (!room)
  949. {
  950. isHostPresent = FALSE;
  951. }
  952. else
  953. {
  954. isHostPresent = FALSE;
  955. for (Int i=0; i<MAX_SLOTS; ++i)
  956. {
  957. AsciiString hostName;
  958. hostName.translate(room->getConstSlot(0)->getName());
  959. const char *firstPlayer = resp.stagingRoomPlayerNames[i].c_str();
  960. if (!strcmp(hostName.str(), firstPlayer))
  961. {
  962. DEBUG_LOG(("Saw host %s == %s in slot %d\n", hostName.str(), firstPlayer, i));
  963. isHostPresent = TRUE;
  964. }
  965. }
  966. }
  967. }
  968. if (resp.joinStagingRoom.ok == PEERTrue && isHostPresent)
  969. {
  970. // Woohoo! On to our next screen!
  971. buttonPushed = true;
  972. nextScreen = "Menus/GameSpyGameOptionsMenu.wnd";
  973. TheShell->pop();
  974. }
  975. else
  976. {
  977. UnicodeString s;
  978. switch(resp.joinStagingRoom.result)
  979. {
  980. case PEERFullRoom: // The room is full.
  981. s = TheGameText->fetch("GUI:JoinFailedRoomFull");
  982. break;
  983. case PEERInviteOnlyRoom: // The room is invite only.
  984. s = TheGameText->fetch("GUI:JoinFailedInviteOnly");
  985. break;
  986. case PEERBannedFromRoom: // The local user is banned from the room.
  987. s = TheGameText->fetch("GUI:JoinFailedBannedFromRoom");
  988. break;
  989. case PEERBadPassword: // An incorrect password (or none) was given for a passworded room.
  990. s = TheGameText->fetch("GUI:JoinFailedBadPassword");
  991. break;
  992. case PEERAlreadyInRoom: // The local user is already in or entering a room of the same type.
  993. s = TheGameText->fetch("GUI:JoinFailedAlreadyInRoom");
  994. break;
  995. case PEERNoConnection: // Can't join a room if there's no chat connection.
  996. s = TheGameText->fetch("GUI:JoinFailedNoConnection");
  997. break;
  998. default:
  999. s = TheGameText->fetch("GUI:JoinFailedDefault");
  1000. break;
  1001. }
  1002. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), s);
  1003. if (groupRoomToJoin)
  1004. {
  1005. DEBUG_LOG(("WOLLobbyMenuUpdate() - rejoining group room %d\n", groupRoomToJoin));
  1006. TheGameSpyInfo->joinGroupRoom(groupRoomToJoin);
  1007. groupRoomToJoin = 0;
  1008. }
  1009. else
  1010. {
  1011. DEBUG_LOG(("WOLLobbyMenuUpdate() - joining best group room\n"));
  1012. TheGameSpyInfo->joinBestGroupRoom();
  1013. }
  1014. }
  1015. }
  1016. break;
  1017. case PeerResponse::PEERRESPONSE_STAGINGROOMLISTCOMPLETE:
  1018. TheGameSpyInfo->sawFullGameList();
  1019. break;
  1020. case PeerResponse::PEERRESPONSE_STAGINGROOM:
  1021. {
  1022. GameSpyStagingRoom room;
  1023. switch(resp.stagingRoom.action)
  1024. {
  1025. case PEER_CLEAR:
  1026. TheGameSpyInfo->clearStagingRoomList();
  1027. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_CLEAR"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1028. break;
  1029. case PEER_ADD:
  1030. case PEER_UPDATE:
  1031. {
  1032. if (resp.stagingRoom.percentComplete == 100)
  1033. {
  1034. TheGameSpyInfo->sawFullGameList();
  1035. }
  1036. //if (ParseAsciiStringToGameInfo(&room, resp.stagingRoomMapName.c_str()))
  1037. //if (ParseAsciiStringToGameInfo(&room, resp.stagingServerGameOptions.c_str()))
  1038. Bool serverOk = TRUE;
  1039. if (!resp.stagingRoomMapName.length())
  1040. {
  1041. serverOk = FALSE;
  1042. }
  1043. // fix for ghost game problem - need to iterate over all resp.stagingRoomPlayerNames[i]
  1044. Bool sawSelf = FALSE;
  1045. //for (Int i=0; i<MAX_SLOTS; ++i)
  1046. //{
  1047. if (TheGameSpyInfo->getLocalName() == resp.stagingRoomPlayerNames[0].c_str())
  1048. {
  1049. sawSelf = TRUE; // don't show ghost games for myself
  1050. }
  1051. //}
  1052. if (sawSelf)
  1053. serverOk = FALSE;
  1054. if (serverOk)
  1055. {
  1056. room.setGameName(UnicodeString(resp.stagingServerName.c_str()));
  1057. room.setID(resp.stagingRoom.id);
  1058. room.setHasPassword(resp.stagingRoom.requiresPassword);
  1059. room.setVersion(resp.stagingRoom.version);
  1060. room.setExeCRC(resp.stagingRoom.exeCRC);
  1061. room.setIniCRC(resp.stagingRoom.iniCRC);
  1062. room.setAllowObservers(resp.stagingRoom.allowObservers);
  1063. room.setUseStats(resp.stagingRoom.useStats);
  1064. room.setPingString(resp.stagingServerPingString.c_str());
  1065. room.setLadderIP(resp.stagingServerLadderIP.c_str());
  1066. room.setLadderPort(resp.stagingRoom.ladderPort);
  1067. room.setReportedNumPlayers(resp.stagingRoom.numPlayers);
  1068. room.setReportedMaxPlayers(resp.stagingRoom.maxPlayers);
  1069. room.setReportedNumObservers(resp.stagingRoom.numObservers);
  1070. Int i;
  1071. AsciiString gsMapName = resp.stagingRoomMapName.c_str();
  1072. AsciiString mapName = "";
  1073. for (i=0; i<gsMapName.getLength(); ++i)
  1074. {
  1075. char c = gsMapName.getCharAt(i);
  1076. if (c != '/')
  1077. mapName.concat(c);
  1078. else
  1079. mapName.concat('\\');
  1080. }
  1081. room.setMap(TheGameState->portableMapPathToRealMapPath(mapName));
  1082. Int numPlayers = 0;
  1083. for (i=0; i<MAX_SLOTS; ++i)
  1084. {
  1085. GameSpyGameSlot *slot = room.getGameSpySlot(i);
  1086. if (slot)
  1087. {
  1088. slot->setWins( resp.stagingRoom.wins[i] );
  1089. slot->setLosses( resp.stagingRoom.losses[i] );
  1090. slot->setProfileID( resp.stagingRoom.profileID[i] );
  1091. slot->setPlayerTemplate( resp.stagingRoom.faction[i] );
  1092. slot->setColor( resp.stagingRoom.color[i] );
  1093. if (resp.stagingRoom.profileID[i] == SLOT_EASY_AI)
  1094. {
  1095. slot->setState(SLOT_EASY_AI);
  1096. ++numPlayers;
  1097. }
  1098. else if (resp.stagingRoom.profileID[i] == SLOT_MED_AI)
  1099. {
  1100. slot->setState(SLOT_MED_AI);
  1101. ++numPlayers;
  1102. }
  1103. else if (resp.stagingRoom.profileID[i] == SLOT_BRUTAL_AI)
  1104. {
  1105. slot->setState(SLOT_BRUTAL_AI);
  1106. ++numPlayers;
  1107. }
  1108. else if (resp.stagingRoomPlayerNames[i].length())
  1109. {
  1110. UnicodeString nameUStr;
  1111. nameUStr.translate(resp.stagingRoomPlayerNames[i].c_str());
  1112. slot->setState(SLOT_PLAYER, nameUStr);
  1113. ++numPlayers;
  1114. }
  1115. else
  1116. {
  1117. slot->setState(SLOT_OPEN);
  1118. }
  1119. }
  1120. }
  1121. DEBUG_ASSERTCRASH(numPlayers, ("Game had no players!\n"));
  1122. //DEBUG_LOG(("Saw room: hasPass=%d, allowsObservers=%d\n", room.getHasPassword(), room.getAllowObservers()));
  1123. if (resp.stagingRoom.action == PEER_ADD)
  1124. {
  1125. TheGameSpyInfo->addStagingRoom(room);
  1126. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_ADD"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1127. }
  1128. else
  1129. {
  1130. TheGameSpyInfo->updateStagingRoom(room);
  1131. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_UPDATE"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1132. }
  1133. }
  1134. else
  1135. {
  1136. room.setID(resp.stagingRoom.id);
  1137. TheGameSpyInfo->removeStagingRoom(room);
  1138. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_UPDATE FAILED"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1139. }
  1140. break;
  1141. }
  1142. case PEER_REMOVE:
  1143. room.setID(resp.stagingRoom.id);
  1144. TheGameSpyInfo->removeStagingRoom(room);
  1145. //TheGameSpyInfo->addText( UnicodeString(L"gameList: PEER_REMOVE"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1146. break;
  1147. default:
  1148. //TheGameSpyInfo->addText( UnicodeString(L"gameList: Unknown"), GameSpyColor[GSCOLOR_DEFAULT], listboxLobbyChat );
  1149. break;
  1150. }
  1151. }
  1152. break;
  1153. }
  1154. }
  1155. #if 0
  1156. if (shouldRepopulatePlayers)
  1157. {
  1158. PopulateLobbyPlayerListbox();
  1159. }
  1160. #else
  1161. refreshPlayerList();
  1162. #endif
  1163. #ifdef PERF_TEST
  1164. // check performance
  1165. end = timeGetTime();
  1166. PERF_LOG(("Frame time was %d ms\n", end-start));
  1167. std::list<Int>::const_iterator it;
  1168. for (it = responses.begin(); it != responses.end(); ++it)
  1169. {
  1170. PERF_LOG((" %s\n", getMessageString(*it)));
  1171. }
  1172. PERF_LOG(("\n"));
  1173. #endif // PERF_TEST
  1174. #if 0
  1175. // Removed 2-17-03 to pull out into a function so we can do the same checks
  1176. Int refreshInterval = gameListRefreshInterval;
  1177. if ((gameListRefreshTime == 0) || ((gameListRefreshTime + refreshInterval) <= timeGetTime()))
  1178. {
  1179. if (TheGameSpyInfo->hasStagingRoomListChanged())
  1180. {
  1181. //DEBUG_LOG(("################### refreshing game list\n"));
  1182. //DEBUG_LOG(("gameRefreshTime=%d, refreshInterval=%d, now=%d\n", gameListRefreshTime, refreshInterval, timeGetTime()));
  1183. RefreshGameListBoxes();
  1184. gameListRefreshTime = timeGetTime();
  1185. } else {
  1186. //DEBUG_LOG(("-"));
  1187. }
  1188. } else {
  1189. //DEBUG_LOG(("gameListRefreshTime: %d refreshInterval: %d\n"));
  1190. }
  1191. #else
  1192. refreshGameList();
  1193. #endif
  1194. }
  1195. }// WOLLobbyMenuUpdate
  1196. //-------------------------------------------------------------------------------------------------
  1197. /** WOL Lobby Menu input callback */
  1198. //-------------------------------------------------------------------------------------------------
  1199. WindowMsgHandledType WOLLobbyMenuInput( GameWindow *window, UnsignedInt msg,
  1200. WindowMsgData mData1, WindowMsgData mData2 )
  1201. {
  1202. switch( msg )
  1203. {
  1204. // --------------------------------------------------------------------------------------------
  1205. case GWM_CHAR:
  1206. {
  1207. UnsignedByte key = mData1;
  1208. UnsignedByte state = mData2;
  1209. if (buttonPushed)
  1210. break;
  1211. switch( key )
  1212. {
  1213. // ----------------------------------------------------------------------------------------
  1214. case KEY_ESC:
  1215. {
  1216. //
  1217. // send a simulated selected event to the parent window of the
  1218. // back/exit button
  1219. //
  1220. if( BitTest( state, KEY_STATE_UP ) )
  1221. {
  1222. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  1223. (WindowMsgData)buttonBack, buttonBackID );
  1224. } // end if
  1225. // don't let key fall through anywhere else
  1226. return MSG_HANDLED;
  1227. } // end escape
  1228. } // end switch( key )
  1229. } // end char
  1230. } // end switch( msg )
  1231. return MSG_IGNORED;
  1232. }// WOLLobbyMenuInput
  1233. //static void doSliderTrack(GameWindow *control, Int val)
  1234. //{
  1235. // Int sliderW, sliderH, sliderX, sliderY;
  1236. // control->winGetPosition(&sliderX, &sliderY);
  1237. // control->winGetSize(&sliderW, &sliderH);
  1238. // Real cursorY = sliderY + (100-val)*0.01f*sliderH;
  1239. //
  1240. // extern GameWindow *listboxLobbyGamesSmall;
  1241. // extern GameWindow *listboxLobbyGamesLarge;
  1242. // extern GameWindow *listboxLobbyGameInfo;
  1243. //
  1244. // static Int gwsX = 0, gwsY = 0, gwsW = 0, gwsH = 0;
  1245. // static Int gwlX = 0, gwlY = 0, gwlW = 0, gwlH = 0;
  1246. // static Int gwiX = 0, gwiY = 0, gwiW = 0, gwiH = 0;
  1247. // static Int pwX = 0, pwY = 0, pwW = 0, pwH = 0;
  1248. // static Int chatPosX = 0, chatPosY = 0, chatW = 0, chatH = 0;
  1249. // static Int spacing = 0;
  1250. // if (chatPosX == 0)
  1251. // {
  1252. // listboxLobbyChat->winGetPosition(&chatPosX, &chatPosY);
  1253. // listboxLobbyChat->winGetSize(&chatW, &chatH);
  1254. //
  1255. //// listboxLobbyGamesSmall->winGetPosition(&gwsX, &gwsY);
  1256. //// listboxLobbyGamesSmall->winGetSize(&gwsW, &gwsH);
  1257. //
  1258. // listboxLobbyGamesLarge->winGetPosition(&gwlX, &gwlY);
  1259. // listboxLobbyGamesLarge->winGetSize(&gwlW, &gwlH);
  1260. //
  1261. //// listboxLobbyGameInfo->winGetPosition(&gwiX, &gwiY);
  1262. //// listboxLobbyGameInfo->winGetSize(&gwiW, &gwiH);
  1263. ////
  1264. // listboxLobbyPlayers->winGetPosition(&pwX, &pwY);
  1265. // listboxLobbyPlayers->winGetSize(&pwW, &pwH);
  1266. //
  1267. // spacing = chatPosY - pwY - pwH;
  1268. // }
  1269. //
  1270. // Int newChatY = cursorY;
  1271. // Int newChatH = chatH + chatPosY - newChatY;
  1272. // listboxLobbyChat->winSetPosition(chatPosX, newChatY);
  1273. // listboxLobbyChat->winSetSize(chatW, newChatH);
  1274. //
  1275. // Int newH = cursorY - pwY - spacing;
  1276. // listboxLobbyPlayers->winSetSize(pwW, newH);
  1277. //// listboxLobbyGamesSmall->winSetSize(gwsW, newH);
  1278. // listboxLobbyGamesLarge->winSetSize(gwlW, newH);
  1279. //// listboxLobbyGameInfo->winSetSize(gwiW, newH);
  1280. //-------------------------------------------------------------------------------------------------
  1281. /** WOL Lobby Menu window system callback */
  1282. //-------------------------------------------------------------------------------------------------
  1283. WindowMsgHandledType WOLLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
  1284. WindowMsgData mData1, WindowMsgData mData2 )
  1285. {
  1286. UnicodeString txtInput;
  1287. static NameKeyType buttonGameListTypeToggleID = NAMEKEY_INVALID;
  1288. switch( msg )
  1289. {
  1290. //---------------------------------------------------------------------------------------------
  1291. case GWM_CREATE:
  1292. {
  1293. buttonGameListTypeToggleID = NAMEKEY("WOLCustomLobby.wnd:ButtonGameListToggle");
  1294. // sliderChatAdjustID = NAMEKEY("WOLCustomLobby.wnd:SliderChatAdjust");
  1295. break;
  1296. } // case GWM_DESTROY:
  1297. //---------------------------------------------------------------------------------------------
  1298. case GWM_DESTROY:
  1299. {
  1300. break;
  1301. } // case GWM_DESTROY:
  1302. //---------------------------------------------------------------------------------------------
  1303. case GWM_INPUT_FOCUS:
  1304. {
  1305. // if we're givin the opportunity to take the keyboard focus we must say we want it
  1306. if( mData1 == TRUE )
  1307. *(Bool *)mData2 = TRUE;
  1308. return MSG_HANDLED;
  1309. }//case GWM_INPUT_FOCUS:
  1310. //---------------------------------------------------------------------------------------------
  1311. case GLM_SELECTED:
  1312. {
  1313. GameWindow *control = (GameWindow *)mData1;
  1314. Int controlID = control->winGetWindowId();
  1315. if ( controlID == GetGameListBoxID() )
  1316. {
  1317. int rowSelected = mData2;
  1318. if( rowSelected >= 0 )
  1319. {
  1320. buttonJoin->winEnable(TRUE);
  1321. static UnsignedInt lastFrame = 0;
  1322. static Int lastID = -1;
  1323. UnsignedInt now = TheGameClient->getFrame();
  1324. PeerRequest req;
  1325. req.peerRequestType = PeerRequest::PEERREQUEST_GETEXTENDEDSTAGINGROOMINFO;
  1326. req.stagingRoom.id = (Int)GadgetListBoxGetItemData(control, rowSelected, 0);
  1327. if (lastID != req.stagingRoom.id || now > lastFrame + 60)
  1328. {
  1329. TheGameSpyPeerMessageQueue->addRequest(req);
  1330. }
  1331. lastID = req.stagingRoom.id;
  1332. lastFrame = now;
  1333. }
  1334. else
  1335. {
  1336. buttonJoin->winEnable(FALSE);
  1337. }
  1338. if (GetGameInfoListBox())
  1339. {
  1340. RefreshGameInfoListBox(GetGameListBox(), GetGameInfoListBox());
  1341. }
  1342. } //if ( controlID == GetGameListBoxID() )
  1343. break;
  1344. }
  1345. //---------------------------------------------------------------------------------------------
  1346. case GBM_SELECTED:
  1347. {
  1348. if (buttonPushed)
  1349. break;
  1350. GameWindow *control = (GameWindow *)mData1;
  1351. Int controlID = control->winGetWindowId();
  1352. if (HandleSortButton((NameKeyType)controlID))
  1353. break;
  1354. // If we back out, just bail - we haven't gotten far enough to need to log out
  1355. if ( controlID == buttonBackID )
  1356. {
  1357. if (s_tryingToHostOrJoin)
  1358. break;
  1359. // Leave any group room, then pop off the screen
  1360. TheGameSpyInfo->leaveGroupRoom();
  1361. SetLobbyAttemptHostJoin( TRUE ); // pretend, since we don't want to queue up another action
  1362. buttonPushed = true;
  1363. nextScreen = "Menus/WOLWelcomeMenu.wnd";
  1364. TheShell->pop();
  1365. } //if ( controlID == buttonBack )
  1366. else if ( controlID == buttonRefreshID )
  1367. {
  1368. // Added 2/17/03 added the game refresh button
  1369. refreshGameList(TRUE);
  1370. refreshPlayerList(TRUE);
  1371. }
  1372. else if ( controlID == buttonHostID )
  1373. {
  1374. if (s_tryingToHostOrJoin)
  1375. break;
  1376. SetLobbyAttemptHostJoin( TRUE );
  1377. TheLobbyQueuedUTMs.clear();
  1378. groupRoomToJoin = TheGameSpyInfo->getCurrentGroupRoom();
  1379. GameSpyOpenOverlay(GSOVERLAY_GAMEOPTIONS);
  1380. }
  1381. else if ( controlID == buttonJoinID )
  1382. {
  1383. if (s_tryingToHostOrJoin)
  1384. break;
  1385. TheLobbyQueuedUTMs.clear();
  1386. // Look for a game to join
  1387. groupRoomToJoin = TheGameSpyInfo->getCurrentGroupRoom();
  1388. Int selected;
  1389. GadgetListBoxGetSelected(GetGameListBox(), &selected);
  1390. if (selected >= 0)
  1391. {
  1392. Int selectedID = (Int)GadgetListBoxGetItemData(GetGameListBox(), selected);
  1393. if (selectedID > 0)
  1394. {
  1395. StagingRoomMap *srm = TheGameSpyInfo->getStagingRoomList();
  1396. StagingRoomMap::iterator srmIt = srm->find(selectedID);
  1397. if (srmIt != srm->end())
  1398. {
  1399. GameSpyStagingRoom *roomToJoin = srmIt->second;
  1400. if (!roomToJoin || roomToJoin->getExeCRC() != TheGlobalData->m_exeCRC || roomToJoin->getIniCRC() != TheGlobalData->m_iniCRC)
  1401. {
  1402. // bad crc. don't go.
  1403. 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()));
  1404. #if defined(_DEBUG) || defined(_INTERNAL)
  1405. if (TheGlobalData->m_netMinPlayers)
  1406. {
  1407. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedCRCMismatch"));
  1408. break;
  1409. }
  1410. else if (g_fakeCRC)
  1411. {
  1412. TheWritableGlobalData->m_exeCRC = roomToJoin->getExeCRC();
  1413. TheWritableGlobalData->m_iniCRC = roomToJoin->getIniCRC();
  1414. }
  1415. #else
  1416. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedCRCMismatch"));
  1417. break;
  1418. #endif
  1419. }
  1420. Bool unknownLadder = (roomToJoin->getLadderPort() && TheLadderList->findLadder(roomToJoin->getLadderIP(), roomToJoin->getLadderPort()) == NULL);
  1421. if (unknownLadder)
  1422. {
  1423. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedUnknownLadder"));
  1424. break;
  1425. }
  1426. if (roomToJoin->getNumPlayers() == MAX_SLOTS)
  1427. {
  1428. GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), TheGameText->fetch("GUI:JoinFailedRoomFull"));
  1429. break;
  1430. }
  1431. TheGameSpyInfo->markAsStagingRoomJoiner(selectedID);
  1432. TheGameSpyGame->setGameName(roomToJoin->getGameName());
  1433. TheGameSpyGame->setLadderIP(roomToJoin->getLadderIP());
  1434. TheGameSpyGame->setLadderPort(roomToJoin->getLadderPort());
  1435. SetLobbyAttemptHostJoin( TRUE );
  1436. if (roomToJoin->getHasPassword())
  1437. {
  1438. GameSpyOpenOverlay(GSOVERLAY_GAMEPASSWORD);
  1439. }
  1440. else
  1441. {
  1442. // no password - just join it
  1443. PeerRequest req;
  1444. req.peerRequestType = PeerRequest::PEERREQUEST_JOINSTAGINGROOM;
  1445. req.text = srmIt->second->getGameName().str();
  1446. req.stagingRoom.id = selectedID;
  1447. req.password = "";
  1448. TheGameSpyPeerMessageQueue->addRequest(req);
  1449. }
  1450. }
  1451. }
  1452. else
  1453. {
  1454. GSMessageBoxOk(TheGameText->fetch("GUI:Error"), TheGameText->fetch("GUI:NoGameInfo"), NULL);
  1455. }
  1456. }
  1457. else
  1458. {
  1459. GSMessageBoxOk(TheGameText->fetch("GUI:Error"), TheGameText->fetch("GUI:NoGameSelected"), NULL);
  1460. }
  1461. }
  1462. else if ( controlID == buttonBuddyID )
  1463. {
  1464. GameSpyToggleOverlay( GSOVERLAY_BUDDY );
  1465. }
  1466. else if ( controlID == buttonGameListTypeToggleID )
  1467. {
  1468. ToggleGameListType();
  1469. }
  1470. else if ( controlID == buttonEmoteID )
  1471. {
  1472. // read the user's input and clear the entry box
  1473. UnicodeString txtInput;
  1474. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1475. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1476. txtInput.trim();
  1477. if (!txtInput.isEmpty())
  1478. {
  1479. // Send the message
  1480. TheGameSpyInfo->sendChat( txtInput, FALSE, listboxLobbyPlayers ); // 'emote' button now just sends text
  1481. }
  1482. }
  1483. break;
  1484. }// case GBM_SELECTED:
  1485. //---------------------------------------------------------------------------------------------
  1486. case GCM_SELECTED:
  1487. {
  1488. if (s_tryingToHostOrJoin)
  1489. break;
  1490. GameWindow *control = (GameWindow *)mData1;
  1491. Int controlID = control->winGetWindowId();
  1492. if( controlID == comboLobbyGroupRoomsID )
  1493. {
  1494. int rowSelected = -1;
  1495. GadgetComboBoxGetSelectedPos(control, &rowSelected);
  1496. DEBUG_LOG(("Row selected = %d\n", rowSelected));
  1497. if (rowSelected >= 0)
  1498. {
  1499. Int groupID;
  1500. groupID = (Int)GadgetComboBoxGetItemData(comboLobbyGroupRooms, rowSelected);
  1501. DEBUG_LOG(("ItemData was %d, current Group Room is %d\n", groupID, TheGameSpyInfo->getCurrentGroupRoom()));
  1502. if (groupID && groupID != TheGameSpyInfo->getCurrentGroupRoom())
  1503. {
  1504. TheGameSpyInfo->leaveGroupRoom();
  1505. TheGameSpyInfo->joinGroupRoom(groupID);
  1506. if (TheGameSpyConfig->restrictGamesToLobby())
  1507. {
  1508. TheGameSpyInfo->clearStagingRoomList();
  1509. RefreshGameListBoxes();
  1510. PeerRequest req;
  1511. req.peerRequestType = PeerRequest::PEERREQUEST_STARTGAMELIST;
  1512. req.gameList.restrictGameList = TRUE;
  1513. TheGameSpyPeerMessageQueue->addRequest(req);
  1514. }
  1515. }
  1516. }
  1517. }
  1518. } // case GCM_SELECTED
  1519. break;
  1520. //---------------------------------------------------------------------------------------------
  1521. case GLM_DOUBLE_CLICKED:
  1522. {
  1523. if (buttonPushed)
  1524. break;
  1525. GameWindow *control = (GameWindow *)mData1;
  1526. Int controlID = control->winGetWindowId();
  1527. if (controlID == GetGameListBoxID())
  1528. {
  1529. int rowSelected = mData2;
  1530. if (rowSelected >= 0)
  1531. {
  1532. GadgetListBoxSetSelected( control, rowSelected );
  1533. GameWindow *button = TheWindowManager->winGetWindowFromId( window, buttonJoinID );
  1534. TheWindowManager->winSendSystemMsg( window, GBM_SELECTED,
  1535. (WindowMsgData)button, buttonJoinID );
  1536. }
  1537. }
  1538. break;
  1539. }// case GLM_DOUBLE_CLICKED:
  1540. //---------------------------------------------------------------------------------------------
  1541. case GLM_RIGHT_CLICKED:
  1542. {
  1543. GameWindow *control = (GameWindow *)mData1;
  1544. Int controlID = control->winGetWindowId();
  1545. if( controlID == listboxLobbyPlayersID )
  1546. {
  1547. RightClickStruct *rc = (RightClickStruct *)mData2;
  1548. WindowLayout *rcLayout = NULL;
  1549. GameWindow *rcMenu;
  1550. if(rc->pos < 0)
  1551. {
  1552. GadgetListBoxSetSelected(control, -1);
  1553. break;
  1554. }
  1555. GPProfile profileID = 0;
  1556. AsciiString aName;
  1557. aName.translate(GadgetListBoxGetText(control, rc->pos, COLUMN_PLAYERNAME));
  1558. PlayerInfoMap::iterator it = TheGameSpyInfo->getPlayerInfoMap()->find(aName);
  1559. if (it != TheGameSpyInfo->getPlayerInfoMap()->end())
  1560. profileID = it->second.m_profileID;
  1561. Bool isBuddy = FALSE;
  1562. if (profileID <= 0)
  1563. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCNoProfileMenu.wnd"));
  1564. else
  1565. {
  1566. if (profileID == TheGameSpyInfo->getLocalProfileID())
  1567. {
  1568. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCLocalPlayerMenu.wnd"));
  1569. }
  1570. else if(TheGameSpyInfo->isBuddy(profileID))
  1571. {
  1572. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCBuddiesMenu.wnd"));
  1573. isBuddy = TRUE;
  1574. }
  1575. else
  1576. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCNonBuddiesMenu.wnd"));
  1577. }
  1578. if(!rcLayout)
  1579. break;
  1580. GadgetListBoxSetSelected(control, rc->pos);
  1581. rcMenu = rcLayout->getFirstWindow();
  1582. rcMenu->winGetLayout()->runInit();
  1583. rcMenu->winBringToTop();
  1584. rcMenu->winHide(FALSE);
  1585. setUnignoreText( rcLayout, aName, profileID);
  1586. ICoord2D rcSize, rcPos;
  1587. rcMenu->winGetSize(&rcSize.x, &rcSize.y);
  1588. rcPos.x = rc->mouseX;
  1589. rcPos.y = rc->mouseY;
  1590. if(rc->mouseX + rcSize.x > TheDisplay->getWidth())
  1591. rcPos.x = TheDisplay->getWidth() - rcSize.x;
  1592. if(rc->mouseY + rcSize.y > TheDisplay->getHeight())
  1593. rcPos.y = TheDisplay->getHeight() - rcSize.y;
  1594. rcMenu->winSetPosition(rcPos.x, rcPos.y);
  1595. GameSpyRCMenuData *rcData = NEW GameSpyRCMenuData;
  1596. rcData->m_id = profileID;
  1597. rcData->m_nick = aName;
  1598. rcData->m_itemType = (isBuddy)?ITEM_BUDDY:ITEM_NONBUDDY;
  1599. rcMenu->winSetUserData((void *)rcData);
  1600. TheWindowManager->winSetLoneWindow(rcMenu);
  1601. }
  1602. else if( controlID == GetGameListBoxID() )
  1603. {
  1604. RightClickStruct *rc = (RightClickStruct *)mData2;
  1605. WindowLayout *rcLayout = NULL;
  1606. GameWindow *rcMenu;
  1607. if(rc->pos < 0)
  1608. {
  1609. GadgetListBoxSetSelected(control, -1);
  1610. break;
  1611. }
  1612. Int selectedID = (Int)GadgetListBoxGetItemData(control, rc->pos);
  1613. if (selectedID > 0)
  1614. {
  1615. StagingRoomMap *srm = TheGameSpyInfo->getStagingRoomList();
  1616. StagingRoomMap::iterator srmIt = srm->find(selectedID);
  1617. if (srmIt != srm->end())
  1618. {
  1619. GameSpyStagingRoom *theRoom = srmIt->second;
  1620. if (!theRoom)
  1621. break;
  1622. const LadderInfo *linfo = TheLadderList->findLadder(theRoom->getLadderIP(), theRoom->getLadderPort());
  1623. if (linfo)
  1624. {
  1625. rcLayout = TheWindowManager->winCreateLayout(AsciiString("Menus/RCGameDetailsMenu.wnd"));
  1626. if (!rcLayout)
  1627. break;
  1628. GadgetListBoxSetSelected(control, rc->pos);
  1629. rcMenu = rcLayout->getFirstWindow();
  1630. rcMenu->winGetLayout()->runInit();
  1631. rcMenu->winBringToTop();
  1632. rcMenu->winHide(FALSE);
  1633. rcMenu->winSetPosition(rc->mouseX, rc->mouseY);
  1634. rcMenu->winSetUserData((void *)selectedID);
  1635. TheWindowManager->winSetLoneWindow(rcMenu);
  1636. }
  1637. }
  1638. }
  1639. }
  1640. break;
  1641. }
  1642. // //---------------------------------------------------------------------------------------------
  1643. // case GSM_SLIDER_TRACK:
  1644. // {
  1645. // if (buttonPushed)
  1646. // break;
  1647. //
  1648. // GameWindow *control = (GameWindow *)mData1;
  1649. // Int val = (Int)mData2;
  1650. // Int controlID = control->winGetWindowId();
  1651. // if (controlID == sliderChatAdjustID)
  1652. // {
  1653. // doSliderTrack(control, val);
  1654. // }
  1655. // break;
  1656. // }
  1657. //---------------------------------------------------------------------------------------------
  1658. case GEM_EDIT_DONE:
  1659. {
  1660. if (buttonPushed)
  1661. break;
  1662. // read the user's input and clear the entry box
  1663. UnicodeString txtInput;
  1664. txtInput.set(GadgetTextEntryGetText( textEntryChat ));
  1665. GadgetTextEntrySetText(textEntryChat, UnicodeString::TheEmptyString);
  1666. txtInput.trim();
  1667. if (!txtInput.isEmpty())
  1668. {
  1669. // Send the message
  1670. if (!handleLobbySlashCommands(txtInput))
  1671. {
  1672. TheGameSpyInfo->sendChat( txtInput, false, listboxLobbyPlayers );
  1673. }
  1674. }
  1675. break;
  1676. }
  1677. //---------------------------------------------------------------------------------------------
  1678. default:
  1679. return MSG_IGNORED;
  1680. }//Switch
  1681. return MSG_HANDLED;
  1682. }// WOLLobbyMenuSystem