forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathLobbyUtils.cpp
More file actions
1526 lines (1368 loc) · 43.3 KB
/
LobbyUtils.cpp
File metadata and controls
1526 lines (1368 loc) · 43.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
// FILE: LobbyUtils.cpp
// Author: Matthew D. Campbell, Sept 2002
// Description: GameSpy lobby utils
///////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/GameEngine.h"
#include "Common/MultiplayerSettings.h"
#include "Common/PlayerTemplate.h"
#include "Common/Version.h"
#include "GameClient/AnimateWindowManager.h"
#include "GameClient/WindowLayout.h"
#include "GameClient/Gadget.h"
#include "GameClient/Image.h"
#include "GameClient/Shell.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GadgetComboBox.h"
#include "GameClient/GadgetListBox.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/GameText.h"
#include "GameClient/MapUtil.h"
#include "GameClient/MessageBox.h"
#include "GameClient/Mouse.h"
#include "GameNetwork/GameSpyOverlay.h"
#include "GameClient/LanguageFilter.h"
#include "GameNetwork/GameSpy/BuddyDefs.h"
#include "GameNetwork/GameSpy/LadderDefs.h"
#include "GameNetwork/GameSpy/LobbyUtils.h"
#include "GameNetwork/GameSpy/PeerDefs.h"
#include "GameNetwork/GameSpy/PeerThread.h"
#include "GameNetwork/GameSpy/PersistentStorageDefs.h"
#include "GameNetwork/GameSpy/GSConfig.h"
#include "Common/STLTypedefs.h"
#include "GameNetwork/GeneralsOnline/NGMP_interfaces.h"
#include "GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h"
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
// Note: if you add more columns, you must modify the .wnd files and change the listbox properties (yuck!)
// TODO_NGMP: We probably need to modify this in the WND... they set the width for observer to 0, for now we dont show ping, but we should show box
#if defined(GENERALS_ONLINE)
enum {
COLUMN_NAME = 0,
COLUMN_MAP,
COLUMN_LADDER,
COLUMN_NUMPLAYERS,
COLUMN_PASSWORD,
COLUMN_OBSERVER,
COLUMN_USE_STATS,
COLUMN_PING
};
#else
enum {
COLUMN_NAME = 0,
COLUMN_MAP,
COLUMN_LADDER,
COLUMN_NUMPLAYERS,
COLUMN_PASSWORD,
COLUMN_OBSERVER,
#if !RTS_GENERALS
COLUMN_USE_STATS,
#endif
COLUMN_PING,
};
#endif
// ---------------------------------------------------------------------------
// row entry animation
// ---------------------------------------------------------------------------
static std::map<int, GameRowAnim> g_gameListAnim;
// initialize the smoothed index for this lobbyID
static float UpdateAndGetGameRowIndex(int lobbyID, float logicalIndex)
{
GameRowAnim& anim = g_gameListAnim[lobbyID];
if (!anim.alive)
{
// start slightly below, then glide into place
anim.currentIndex = logicalIndex + 2.f;
anim.targetIndex = logicalIndex;
anim.alive = true;
}
else
{
anim.targetIndex = logicalIndex;
}
// how fast to snap into place
const float t = 0.2f;
float delta = anim.targetIndex - anim.currentIndex;
anim.currentIndex += delta * t;
return anim.currentIndex;
}
static NameKeyType buttonSortAlphaID = NAMEKEY_INVALID;
static NameKeyType buttonSortPingID = NAMEKEY_INVALID;
static NameKeyType buttonSortBuddiesID = NAMEKEY_INVALID;
static NameKeyType windowSortAlphaID = NAMEKEY_INVALID;
static NameKeyType windowSortPingID = NAMEKEY_INVALID;
static NameKeyType windowSortBuddiesID = NAMEKEY_INVALID;
static GameWindow *buttonSortAlpha = nullptr;
static GameWindow *buttonSortPing = nullptr;
static GameWindow *buttonSortBuddies = nullptr;
static GameWindow *windowSortAlpha = nullptr;
static GameWindow *windowSortPing = nullptr;
static GameWindow *windowSortBuddies = nullptr;
static GameSortType theGameSortType = GAMESORT_MAP_ASCENDING; // was ping
static Bool sortBuddies = TRUE;
static void showSortIcons()
{
if (windowSortAlpha && windowSortPing)
{
switch (theGameSortType)
{
case GAMESORT_AGE_ASCENDING: // was alpha
windowSortAlpha->winHide(FALSE);
windowSortAlpha->winEnable(TRUE);
windowSortPing->winHide(TRUE);
break;
case GAMESORT_AGE_DESCENDING: // was alpha
windowSortAlpha->winHide(FALSE);
windowSortAlpha->winEnable(FALSE);
windowSortPing->winHide(TRUE);
break;
case GAMESORT_MAP_ASCENDING: // was ping
windowSortPing->winHide(FALSE);
windowSortPing->winEnable(TRUE);
windowSortAlpha->winHide(TRUE);
break;
case GAMESORT_MAP_DESCENDING: // was ping
windowSortPing->winHide(FALSE);
windowSortPing->winEnable(FALSE);
windowSortAlpha->winHide(TRUE);
break;
}
}
if (sortBuddies)
{
if (windowSortBuddies)
{
windowSortBuddies->winHide(FALSE);
}
}
else
{
if (windowSortBuddies)
{
windowSortBuddies->winHide(TRUE);
}
}
}
LobbyGameModeFilter theLobbyFilter = LOBBY_FILTER_ALL;
static LobbyGameModeFilter detectGameMode(const std::string& name)
{
std::string modeName = name;
std::transform(modeName.begin(), modeName.end(), modeName.begin(), tolower);
// remove spaces
modeName.erase(std::remove(modeName.begin(), modeName.end(), ' '), modeName.end());
// handle common variations
for (size_t i = 0; i < modeName.size(); ++i)
{
if (modeName.compare(i, 2, "vs") == 0)
{
modeName.erase(i + 1, 1);
continue;
}
if (modeName[i] == 'x')
modeName[i] = 'v';
}
if (modeName.find("aod") != -1)
return LOBBY_FILTER_AOD;
if (modeName.find("ffa") != -1 || modeName.find("1v1v1") != -1)
return LOBBY_FILTER_FFA;
if (modeName.find("1v1") != -1)
return LOBBY_FILTER_1V1;
if (modeName.find("2v2") != -1 || modeName.find("3v3") != -1 || modeName.find("4v4") != -1)
return LOBBY_FILTER_TEAM;
return LOBBY_FILTER_ALL;
}
void setSortMode(GameSortType sortType) { theGameSortType = sortType; showSortIcons(); RefreshGameListBoxes(); }
void sortByBuddies(Bool doSort) { sortBuddies = doSort; showSortIcons(); RefreshGameListBoxes(); }
Bool HandleSortButton(NameKeyType sortButton)
{
if (sortButton == buttonSortBuddiesID)
{
sortByBuddies(!sortBuddies);
return TRUE;
}
else if (sortButton == buttonSortAlphaID)
{
if (theGameSortType == GAMESORT_AGE_ASCENDING) // was alpha
{
setSortMode(GAMESORT_AGE_DESCENDING); // was alpha
}
else
{
setSortMode(GAMESORT_AGE_ASCENDING); // was alpha
}
return TRUE;
}
else if (sortButton == buttonSortPingID)
{
if (theGameSortType == GAMESORT_MAP_ASCENDING) // was ping
{
setSortMode(GAMESORT_MAP_DESCENDING); // was ping
}
else
{
setSortMode(GAMESORT_MAP_ASCENDING); // was ping
}
return TRUE;
}
return FALSE;
}
// window ids ------------------------------------------------------------------------------
static NameKeyType parentID = NAMEKEY_INVALID;
//static NameKeyType parentGameListSmallID = NAMEKEY_INVALID;
static NameKeyType parentGameListLargeID = NAMEKEY_INVALID;
static NameKeyType listboxLobbyGamesSmallID = NAMEKEY_INVALID;
static NameKeyType listboxLobbyGamesLargeID = NAMEKEY_INVALID;
//static NameKeyType listboxLobbyGameInfoID = NAMEKEY_INVALID;
// Window Pointers ------------------------------------------------------------------------
static GameWindow *parent = nullptr;
//static GameWindow *parentGameListSmall = nullptr;
static GameWindow *parentGameListLarge = nullptr;
//GameWindow *listboxLobbyGamesSmall = nullptr;
GameWindow *listboxLobbyGamesLarge = nullptr;
//GameWindow *listboxLobbyGameInfo = nullptr;
static const Image *pingImages[3] = { nullptr, nullptr, nullptr };
static void gameTooltip(GameWindow* window,
WinInstanceData* instData,
UnsignedInt mouse)
{
Int x, y, row, col;
x = LOLONGTOSHORT(mouse);
y = HILONGTOSHORT(mouse);
GadgetListBoxGetEntryBasedOnXY(window, x, y, row, col);
if (row == -1 || col == -1)
{
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString);//TheGameText->fetch("TOOLTIP:GamesBeingFormed") );
return;
}
Int gameID = (Int)GadgetListBoxGetItemData(window, row, 0);
#if defined(GENERALS_ONLINE)
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
if (pLobbyInterface == nullptr)
{
return;
}
LobbyEntry lobbyEntry = pLobbyInterface->GetLobbyFromID(gameID);
if (lobbyEntry.lobbyID == -1)
{
return;
}
#else
GameSpyStagingRoom *room = TheGameSpyInfo->findStagingRoomByID(gameID);
if (!room)
{
TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:UnknownGame") );
return;
}
#endif
if (col == COLUMN_PING)
{
#if 0 //def DEBUG_LOGGING
UnicodeString s;
s.format(L"Ping is %d ms (cutoffs are %d ms and %d ms\n%hs local pings\n%hs remote pings",
room->getPingAsInt(), TheGameSpyConfig->getPingCutoffGood(), TheGameSpyConfig->getPingCutoffBad(),
TheGameSpyInfo->getPingString().str(), room->getPingString().str()
);
TheMouse->setCursorTooltip( s, 10, nullptr, 2.0f ); // the text and width are the only params used. the others are the default values.
#else
TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:PingInfo"), 10, nullptr, 2.0f ); // the text and width are the only params used. the others are the default values.
#endif
return;
}
if (col == COLUMN_NUMPLAYERS)
{
TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:NumberOfPlayers"), 10, nullptr, 2.0f ); // the text and width are the only params used. the others are the default values.
return;
}
if (col == COLUMN_PASSWORD)
{
#if defined(GENERALS_ONLINE)
if (lobbyEntry.passworded)
#else
if (room->getHasPassword())
#endif
{
UnicodeString checkTooltip =TheGameText->fetch("TOOTIP:Password");
if(!checkTooltip.compare(L"Password required to joing game"))
checkTooltip.set(L"Password required to join game");
TheMouse->setCursorTooltip( checkTooltip, 10, nullptr, 2.0f ); // the text and width are the only params used. the others are the default values.
}
else
TheMouse->setCursorTooltip( UnicodeString::TheEmptyString );
return;
}
#if !RTS_GENERALS
if (col == COLUMN_USE_STATS)
{
#if defined(GENERALS_ONLINE)
if (lobbyEntry.track_stats)
#else
if (room->getUseStats())
#endif
{
TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:UseStatsOn") );
}
else
{
TheMouse->setCursorTooltip( TheGameText->fetch("TOOLTIP:UseStatsOff") );
}
return;
}
#endif
UnicodeString tooltip;
UnicodeString mapName;
#if defined(GENERALS_ONLINE)
// GO already has the full map info, don't need the cache
mapName.translate(lobbyEntry.map_name.c_str());
#else
const MapMetaData *md = TheMapCache->findMap(room->getMap());
if (md)
{
mapName = md->m_displayName;
}
else
{
const char *start = room->getMap().reverseFind('\\');
if (start)
{
++start;
}
else
{
start = room->getMap().str();
}
mapName.translate( start );
}
#endif
UnicodeString tmp;
#if defined(GENERALS_ONLINE)
UnicodeString gameName;
gameName.format(L"%s", from_utf8(lobbyEntry.name).c_str());
tooltip.format(TheGameText->fetch("TOOLTIP:GameInfoGameName"), gameName.str());
UnicodeString region;
region.format(L"\n\nRegion: %s", from_utf8(lobbyEntry.region).c_str());
tooltip.concat(region);
UnicodeString latency;
latency.format(L"\nLatency: %d (%d frames)\n", lobbyEntry.latency, ConvertMSLatencyToGenToolFrames(lobbyEntry.latency));
tooltip.concat(latency);
#else
tooltip.format(TheGameText->fetch("TOOLTIP:GameInfoGameName"), room->getGameName().str());
#endif
#if defined(GENERALS_ONLINE)
// TODO_QUICKMATCH
if (false)
#else
if (room->getLadderPort() != 0)
{
const LadderInfo *linfo = TheLadderList->findLadder(room->getLadderIP(), room->getLadderPort());
if (linfo)
{
tmp.format(TheGameText->fetch("TOOLTIP:GameInfoLadderName"), linfo->name.str());
tooltip.concat(tmp);
}
}
#endif
#if defined(GENERALS_ONLINE)
if (lobbyEntry.exe_crc != TheGlobalData->m_exeCRC || lobbyEntry.ini_crc != TheGlobalData->m_iniCRC)
#else
if (room->getExeCRC() != TheGlobalData->m_exeCRC || room->getIniCRC() != TheGlobalData->m_iniCRC)
#endif
{
tmp.format(TheGameText->fetch("TOOLTIP:InvalidGameVersion"), mapName.str());
tooltip.concat(tmp);
}
tmp.format(TheGameText->fetch("TOOLTIP:GameInfoMap"), mapName.str());
tooltip.concat(tmp);
tooltip.concat(L"\n");
#if defined(GENERALS_ONLINE)
for (LobbyMemberEntry& member : lobbyEntry.members)
{
if (member.IsHuman())
{
UnicodeString plrName;
plrName.format(L"%s [%hs, %dms latency]", from_utf8(member.display_name).c_str(), member.region.c_str(), member.latency);
// TODO_NGMP: We don't have stats info
//tmp.format(TheGameText->fetch("TOOLTIP:GameInfoPlayer"), plrName.str(), slot->getWins(), slot->getLosses());
tooltip.concat(L'\n');
tooltip.concat(plrName);
}
else
{
switch (member.m_SlotState)
{
case SLOT_EASY_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:EasyAI"));
break;
case SLOT_MED_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:MediumAI"));
break;
case SLOT_BRUTAL_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:HardAI"));
break;
}
}
}
#else
AsciiString aPlayer;
UnicodeString player;
Int numPlayers = 0;
for (Int i=0; i<MAX_SLOTS; ++i)
{
GameSpyGameSlot *slot = room->getGameSpySlot(i);
if (i == 0 && (!slot || !slot->isHuman()))
{
DEBUG_CRASH(("About to tooltip a non-hosted game!"));
}
if (slot && slot->isHuman())
{
tmp.format(TheGameText->fetch("TOOLTIP:GameInfoPlayer"), slot->getName().str(), slot->getWins(), slot->getLosses());
tooltip.concat(tmp);
++numPlayers;
}
else if (slot && slot->isAI())
{
++numPlayers;
switch(slot->getState())
{
case SLOT_EASY_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:EasyAI"));
break;
case SLOT_MED_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:MediumAI"));
break;
case SLOT_BRUTAL_AI:
tooltip.concat(L'\n');
tooltip.concat(TheGameText->fetch("GUI:HardAI"));
break;
}
}
}
DEBUG_ASSERTCRASH(numPlayers, ("Tooltipping a 0-player game!"));
#endif
TheMouse->setCursorTooltip( tooltip, 10, nullptr, 2.0f ); // the text and width are the only params used. the others are the default values.
}
static Bool isSmall = TRUE;
GameWindow *GetGameListBox()
{
return listboxLobbyGamesLarge;
}
GameWindow *GetGameInfoListBox()
{
return nullptr;
}
NameKeyType GetGameListBoxID()
{
return listboxLobbyGamesLargeID;
}
NameKeyType GetGameInfoListBoxID()
{
return NAMEKEY_INVALID;
}
void GrabWindowInfo()
{
isSmall = TRUE;
parentID = NAMEKEY( "WOLCustomLobby.wnd:WOLLobbyMenuParent" );
parent = TheWindowManager->winGetWindowFromId(nullptr, parentID);
pingImages[0] = TheMappedImageCollection->findImageByName("Ping03");
pingImages[1] = TheMappedImageCollection->findImageByName("Ping02");
pingImages[2] = TheMappedImageCollection->findImageByName("Ping01");
DEBUG_ASSERTCRASH(pingImages[0], ("Can't find ping image!"));
DEBUG_ASSERTCRASH(pingImages[1], ("Can't find ping image!"));
DEBUG_ASSERTCRASH(pingImages[2], ("Can't find ping image!"));
// parentGameListSmallID = NAMEKEY( "WOLCustomLobby.wnd:ParentGameListSmall" );
// parentGameListSmall = TheWindowManager->winGetWindowFromId(nullptr, parentGameListSmallID);
parentGameListLargeID = NAMEKEY( "WOLCustomLobby.wnd:ParentGameListLarge" );
parentGameListLarge = TheWindowManager->winGetWindowFromId(nullptr, parentGameListLargeID);
listboxLobbyGamesSmallID = NAMEKEY( "WOLCustomLobby.wnd:ListboxGames" );
// listboxLobbyGamesSmall = TheWindowManager->winGetWindowFromId(nullptr, listboxLobbyGamesSmallID);
// listboxLobbyGamesSmall->winSetTooltipFunc(gameTooltip);
listboxLobbyGamesLargeID = NAMEKEY( "WOLCustomLobby.wnd:ListboxGamesLarge" );
listboxLobbyGamesLarge = TheWindowManager->winGetWindowFromId(nullptr, listboxLobbyGamesLargeID);
listboxLobbyGamesLarge->winSetTooltipFunc(gameTooltip);
//
// listboxLobbyGameInfoID = NAMEKEY( "WOLCustomLobby.wnd:ListboxGameInfo" );
// listboxLobbyGameInfo = TheWindowManager->winGetWindowFromId(nullptr, listboxLobbyGameInfoID);
buttonSortAlphaID = NAMEKEY("WOLCustomLobby.wnd:ButtonSortAlpha");
buttonSortPingID = NAMEKEY("WOLCustomLobby.wnd:ButtonSortPing");
buttonSortBuddiesID = NAMEKEY("WOLCustomLobby.wnd:ButtonSortBuddies");
windowSortAlphaID = NAMEKEY("WOLCustomLobby.wnd:WindowSortAlpha");
windowSortPingID = NAMEKEY("WOLCustomLobby.wnd:WindowSortPing");
windowSortBuddiesID = NAMEKEY("WOLCustomLobby.wnd:WindowSortBuddies");
buttonSortAlpha = TheWindowManager->winGetWindowFromId(parent, buttonSortAlphaID);
if (buttonSortAlpha)
{
buttonSortAlpha->winSetText(UnicodeString(L"Sort by Newest"));
buttonSortAlpha->winSetTooltip(UnicodeString::TheEmptyString);
}
buttonSortPing = TheWindowManager->winGetWindowFromId(parent, buttonSortPingID);
if (buttonSortPing)
{
buttonSortPing->winSetText(UnicodeString(L"Sort by Map"));
buttonSortPing->winSetTooltip(UnicodeString::TheEmptyString);
}
buttonSortBuddies = TheWindowManager->winGetWindowFromId(parent, buttonSortBuddiesID);
if (buttonSortBuddies)
{
buttonSortBuddies->winSetText(UnicodeString(L"Sort by Buddies"));
buttonSortBuddies->winSetTooltip(UnicodeString::TheEmptyString);
}
windowSortAlpha = TheWindowManager->winGetWindowFromId(parent, windowSortAlphaID);
windowSortPing = TheWindowManager->winGetWindowFromId(parent, windowSortPingID);
windowSortBuddies = TheWindowManager->winGetWindowFromId(parent, windowSortBuddiesID);
showSortIcons();
}
void ReleaseWindowInfo()
{
isSmall = TRUE;
parent = nullptr;
// parentGameListSmall = nullptr;
parentGameListLarge = nullptr;
// listboxLobbyGamesSmall = nullptr;
listboxLobbyGamesLarge = nullptr;
// listboxLobbyGameInfo = nullptr;
buttonSortAlpha = nullptr;
buttonSortPing = nullptr;
buttonSortBuddies = nullptr;
windowSortAlpha = nullptr;
windowSortPing = nullptr;
windowSortBuddies = nullptr;
}
#if defined(GENERALS_ONLINE)
typedef std::set<int64_t> BuddyGameSet;
#else
typedef std::set<GameSpyStagingRoom*> BuddyGameSet;
#endif
static BuddyGameSet *theBuddyGames = nullptr;
#if defined(GENERALS_ONLINE)
static void populateBuddyGames(std::vector<LobbyEntry>& vecLobbies)
#else
static void populateBuddyGames(void)
#endif
{
#if defined(GENERALS_ONLINE)
theBuddyGames = NEW BuddyGameSet;
NGMP_OnlineServices_SocialInterface* pSocialInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_SocialInterface>();
if (pSocialInterface == nullptr)
{
return;
}
for (LobbyEntry& lobby : vecLobbies)
{
// is host our friend?
if (pSocialInterface->IsUserFriend(lobby.owner))
{
theBuddyGames->insert(lobby.lobbyID);
}
else // does the lobby contain any of our friends
{
for (auto member : lobby.members)
{
if (pSocialInterface->IsUserFriend(member.user_id))
{
theBuddyGames->insert(lobby.lobbyID);
break; // its binary, we don't care how many friends
}
}
}
}
#else
BuddyInfoMap *m = TheGameSpyInfo->getBuddyMap();
theBuddyGames = NEW BuddyGameSet;
if (!m)
{
return;
}
for (BuddyInfoMap::const_iterator bit = m->begin(); bit != m->end(); ++bit)
{
BuddyInfo info = bit->second;
if (info.m_status == GP_STAGING)
{
StagingRoomMap *srm = TheGameSpyInfo->getStagingRoomList();
for (StagingRoomMap::iterator srmIt = srm->begin(); srmIt != srm->end(); ++srmIt)
{
GameSpyStagingRoom *game = srmIt->second;
game->cleanUpSlotPointers();
const GameSpyGameSlot *slot = game->getGameSpySlot(0);
if (slot && slot->getName() == info.m_locationString)
{
theBuddyGames->insert(game);
break;
}
}
}
}
#endif
}
static void clearBuddyGames()
{
delete theBuddyGames;
theBuddyGames = nullptr;
}
#if defined(GENERALS_ONLINE)
struct GameSortStruct
{
bool operator()(const LobbyEntry& g1, const LobbyEntry& g2) const
{
const bool g1Join = !(g1.exe_crc != TheGlobalData->m_exeCRC || g1.ini_crc != TheGlobalData->m_iniCRC);
const bool g2Join = !(g2.exe_crc != TheGlobalData->m_exeCRC || g2.ini_crc != TheGlobalData->m_iniCRC);
if (g1Join != g2Join)
return g1Join && !g2Join;
if (sortBuddies)
{
const bool g1Buddy = (theBuddyGames && theBuddyGames->count(g1.lobbyID));
const bool g2Buddy = (theBuddyGames && theBuddyGames->count(g2.lobbyID));
if (g1Buddy != g2Buddy)
return g1Buddy && !g2Buddy;
}
// Push passworded lobbies below open ones
if (g1.passworded != g2.passworded)
return !g1.passworded && g2.passworded;
// NOTE: GO currently does not have private ladders, so this check is moot
/*
// sort games with private ladders to the bottom
Bool g1UnknownLadder = (g1->getLadderPort() && TheLadderList->findLadder(g1->getLadderIP(), g1->getLadderPort()) == NULL);
Bool g2UnknownLadder = (g2->getLadderPort() && TheLadderList->findLadder(g2->getLadderIP(), g2->getLadderPort()) == NULL);
if (g1UnknownLadder ^ g2UnknownLadder)
{
return g2UnknownLadder;
}
*/
switch (theGameSortType)
{
case GAMESORT_MAP_ASCENDING: // was ping
if (g1.map_name != g2.map_name)
return g1.map_name < g2.map_name;
break;
case GAMESORT_MAP_DESCENDING: // was ping
if (g1.map_name != g2.map_name)
return g1.map_name > g2.map_name;
break;
case GAMESORT_AGE_ASCENDING: // was alpha
return g1.lobbyID > g2.lobbyID;
case GAMESORT_AGE_DESCENDING: // was alpha
return g1.lobbyID < g2.lobbyID;
}
return g1.lobbyID > g2.lobbyID;
}
};
#else
struct GameSortStruct
{
bool operator()(GameSpyStagingRoom *g1, GameSpyStagingRoom *g2) const
{
// sort CRC mismatches to the bottom
Bool g1Good = (g1->getExeCRC() == TheGlobalData->m_exeCRC && g1->getIniCRC() == TheGlobalData->m_iniCRC);
Bool g2Good = (g2->getExeCRC() == TheGlobalData->m_exeCRC && g2->getIniCRC() == TheGlobalData->m_iniCRC);
if ( g1Good ^ g2Good )
{
return g1Good;
}
// sort games with private ladders to the bottom
Bool g1UnknownLadder = (g1->getLadderPort() && TheLadderList->findLadder(g1->getLadderIP(), g1->getLadderPort()) == nullptr);
Bool g2UnknownLadder = (g2->getLadderPort() && TheLadderList->findLadder(g2->getLadderIP(), g2->getLadderPort()) == nullptr);
if ( g1UnknownLadder ^ g2UnknownLadder )
{
return g2UnknownLadder;
}
// sort full games to the bottom
Bool g1Full = (g1->getNumNonObserverPlayers() == g1->getMaxPlayers() || g1->getNumPlayers() == MAX_SLOTS);
Bool g2Full = (g2->getNumNonObserverPlayers() == g2->getMaxPlayers() || g2->getNumPlayers() == MAX_SLOTS);
if ( g1Full ^ g2Full )
{
return g2Full;
}
if (sortBuddies)
{
Bool g1HasBuddies = (theBuddyGames->find(g1) != theBuddyGames->end());
Bool g2HasBuddies = (theBuddyGames->find(g2) != theBuddyGames->end());
if ( g1HasBuddies ^ g2HasBuddies )
{
return g1HasBuddies;
}
}
switch(theGameSortType)
{
case GAMESORT_ALPHA_ASCENDING:
return wcsicmp(g1->getGameName().str(), g2->getGameName().str()) < 0;
break;
case GAMESORT_ALPHA_DESCENDING:
return wcsicmp(g1->getGameName().str(),g2->getGameName().str()) > 0;
break;
case GAMESORT_PING_ASCENDING:
return g1->getPingAsInt() < g2->getPingAsInt();
break;
case GAMESORT_PING_DESCENDING:
return g1->getPingAsInt() > g2->getPingAsInt();
break;
}
return false;
}
};
#endif
static Int insertGame(GameWindow* win, LobbyEntry& lobbyInfo, Bool showMap)
{
Color gameColor = GameSpyColor[GSCOLOR_GAME];
if (lobbyInfo.exe_crc != TheGlobalData->m_exeCRC || lobbyInfo.ini_crc != TheGlobalData->m_iniCRC)
{
gameColor = GameSpyColor[GSCOLOR_GAME_CRCMISMATCH];
}
#if defined(GENERALS_ONLINE)
// Buddy lobby highlight:
if (theBuddyGames && theBuddyGames->count(lobbyInfo.lobbyID))
{
const bool nonJoinable =
(gameColor == GameSpyColor[GSCOLOR_GAME_CRCMISMATCH]);
gameColor = nonJoinable
? GameMakeColor(0, 98, 130, 255) // darker cyan
: GameMakeColor(20, 177, 255, 255); // lighter cyan
}
#endif
std::wstring strOwnerName = L"";
for (LobbyMemberEntry& member : lobbyInfo.members)
{
if (member.user_id == lobbyInfo.owner)
{
strOwnerName = from_utf8(member.display_name);
}
}
UnicodeString gameName;
gameName.format(L"%s (%s)", from_utf8(lobbyInfo.name).c_str(), strOwnerName.c_str());
int numPlayers = lobbyInfo.current_players;
int maxPlayers = lobbyInfo.max_players;
AsciiString lobbyMapName = AsciiString(lobbyInfo.map_name.c_str());
AsciiString ladder = AsciiString("TODO_NGMP");
USHORT ladderPort = 1;
int gameID = lobbyInfo.lobbyID; // TODO_NGMP: Downcast. We should use int64 everywhere, although its unlikely we actually need int64 for lobby since its reset regularly.
bool bHasPassword = lobbyInfo.passworded;
bool bAllowSpectators = lobbyInfo.allow_observers;
bool bTrackStats = lobbyInfo.track_stats;
int latency = lobbyInfo.latency;
// TODO_NGMP: Asian text
/*
if (TheGameSpyInfo->getDisallowAsianText())
{
const WideChar* buff = gameName.str();
Int length = gameName.getLength();
for (Int i = 0; i < length; ++i)
{
if (buff[i] >= 256)
return -1;
}
}
else if (TheGameSpyInfo->getDisallowNonAsianText())
{
const WideChar* buff = gameName.str();
Int length = gameName.getLength();
Bool hasUnicode = FALSE;
for (Int i = 0; i < length; ++i)
{
if (buff[i] >= 256)
{
hasUnicode = TRUE;
break;
}
}
if (!hasUnicode)
return -1;
}
*/
Int rowCount = GadgetListBoxGetNumEntries(win);
bool bAlternate = (rowCount % 2 == 0);
if (bAlternate && gameColor == GameSpyColor[GSCOLOR_GAME])
{
if (NGMP_OnlineServicesManager::Settings.LobbyList_AlternateColors())
{
gameColor = GameMakeColor(191, 198, 201, 255);
}
}
Int index = GadgetListBoxAddEntryText(win, gameName, gameColor, -1, COLUMN_NAME);
GadgetListBoxSetItemData(win, (void*)gameID, index);
UnicodeString s;
if (showMap)
{
UnicodeString mapName;
const MapMetaData* md = TheMapCache->findMap(lobbyMapName);
if (md)
{
mapName = md->m_displayName;
}
else
{
const char* start = lobbyInfo.map_name.c_str();
const char* slashPos = strrchr(start, '\\');
if (slashPos)
start = slashPos + 1;
mapName.format(L"%s", from_utf8(start).c_str());
}
GadgetListBoxAddEntryText(win, mapName, gameColor, index, COLUMN_MAP);
// TODO_NGMP: Support ladder again
if (TheLadderList != nullptr)
{
const LadderInfo* li = TheLadderList->findLadder(ladder, ladderPort);
if (li)
{
GadgetListBoxAddEntryText(win, li->name, gameColor, index, COLUMN_LADDER);
}
else if (ladderPort)
{
GadgetListBoxAddEntryText(win, TheGameText->fetch("GUI:UnknownLadder"), gameColor, index, COLUMN_LADDER);
}
else
{
GadgetListBoxAddEntryText(win, TheGameText->fetch("GUI:NoLadder"), gameColor, index, COLUMN_LADDER);
}
}
else
{
GadgetListBoxAddEntryText(win, TheGameText->fetch("GUI:NoLadder"), gameColor, index, COLUMN_LADDER);
}
}
else
{
GadgetListBoxAddEntryText(win, UnicodeString(L" "), gameColor, index, COLUMN_MAP);
GadgetListBoxAddEntryText(win, UnicodeString(L" "), gameColor, index, COLUMN_LADDER);
}
s.format(L"%d/%d", numPlayers, maxPlayers);
const bool bIsFull = (lobbyInfo.current_players == lobbyInfo.max_players || lobbyInfo.current_players == MAX_SLOTS);
const bool bIsAlmostFull = !bIsFull && (maxPlayers > 0) && ((float)numPlayers / (float)maxPlayers >= 0.6f);
Color numPlayersColor = bIsFull ? GameMakeColor(255, 80, 80, 255)
: bIsAlmostFull ? GameMakeColor(16, 173, 144, 255)
: gameColor;
GadgetListBoxAddEntryText(win, s, numPlayersColor, index, COLUMN_NUMPLAYERS);
if (bHasPassword)
{
const Image* img = TheMappedImageCollection->findImageByName("Password");
Int width = 10, height = 10;
if (img)
{
width = img->getImageWidth();
height = img->getImageHeight();
}
GadgetListBoxAddEntryImage(win, img, index, COLUMN_PASSWORD, width, height);
}
else
{
GadgetListBoxAddEntryText(win, UnicodeString(L" "), gameColor, index, COLUMN_PASSWORD);
}
if (bAllowSpectators)
{
const Image* img = TheMappedImageCollection->findImageByName("Observer");
GadgetListBoxAddEntryImage(win, img, index, COLUMN_OBSERVER, img->getImageHeight()/2, img->getImageWidth()/2);
}
else
{
GadgetListBoxAddEntryText(win, UnicodeString(L" "), gameColor, index, COLUMN_OBSERVER);
}
if (bTrackStats)
{
const Image* img = TheMappedImageCollection->findImageByName("GoodStatsIcon");
GadgetListBoxAddEntryImage(win, img, index, COLUMN_USE_STATS, img->getImageHeight(), img->getImageWidth());
}
s.format(L"%d", latency);
GadgetListBoxAddEntryText(win, s, gameColor, index, COLUMN_PING);
Int ping = latency;
Int width = 10, height = 10;
if (pingImages[0])
{
width = pingImages[0]->getImageWidth();
height = pingImages[0]->getImageHeight();
}