Skip to content

Commit 6926cee

Browse files
committed
- custom map support WIP
- fix for unpassworded lobbies
1 parent d7e85db commit 6926cee

10 files changed

Lines changed: 206 additions & 21 deletions

File tree

GeneralsMD/Code/GameEngine/Include/GameClient/MapUtil.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class MapCache : public std::map<AsciiString, MapMetaData>
9898
MapCache() {}
9999
void updateCache( void );
100100

101-
AsciiString getMapDir() const;
102-
AsciiString getUserMapDir() const;
101+
AsciiString getMapDir(bool bCustomMapDebug = false) const;
102+
AsciiString getUserMapDir(bool bCustomMapDebug = false) const;
103103
AsciiString getMapExtension() const;
104104

105105
const MapMetaData *findMap(AsciiString mapName);

GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/NextGenMP_defines.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@
3131
#define GENERALS_ONLINE_SERVICE_VERSION 1
3232

3333
// annoying game assertions, we'll catch real things in the debugger
34-
#define DISABLE_DEBUG_CRASHING 1
34+
#define DISABLE_DEBUG_CRASHING 1
35+
36+
#define GENERALS_ONLINE_TEST_MAP_TRANSFER 1

GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/OnlineServices_LobbyInterface.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct LobbyMemberEntry : public NetworkMemberBase
1616
int color = -1;
1717
int team = -1;
1818
int startpos = -1;
19+
bool has_map = false;
1920

2021
bool IsValid() const { return user_id != -1; }
2122
};
@@ -28,6 +29,7 @@ struct LobbyEntry
2829
std::string name;
2930
std::string map_name;
3031
std::string map_path;
32+
bool map_official;
3133
int current_players;
3234
int max_players;
3335
bool vanilla_teams;
@@ -78,10 +80,12 @@ class NGMP_OnlineServices_LobbyInterface
7880
}
7981

8082
// updates
81-
void UpdateCurrentLobby_Map(AsciiString strMap, AsciiString strMapPath, int newMaxPlayers);
83+
void UpdateCurrentLobby_Map(AsciiString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers);
8284
void UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons);
8385
void UpdateCurrentLobby_StartingCash(UnsignedInt startingCashValue);
8486

87+
void UpdateCurrentLobby_HasMap();
88+
8589
void UpdateCurrentLobby_MySide(int side, int updatedStartPos);
8690
void UpdateCurrentLobby_MyColor(int side);
8791
void UpdateCurrentLobby_MyStartPos(int side);
@@ -114,7 +118,7 @@ class NGMP_OnlineServices_LobbyInterface
114118
UnicodeString m_PendingCreation_LobbyName;
115119
UnicodeString m_PendingCreation_InitialMapDisplayName;
116120
AsciiString m_PendingCreation_InitialMapPath;
117-
void CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash, bool bPassworded, const char* szPassword);
121+
void CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, bool bIsOfficial, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash, bool bPassworded, const char* szPassword);
118122

119123
void OnJoinedOrCreatedLobby(bool bAlreadyUpdatedDetails = false);
120124

@@ -246,6 +250,12 @@ class NGMP_OnlineServices_LobbyInterface
246250

247251
void UpdateRoomDataCache(std::function<void(void)> fnCallback = nullptr);
248252

253+
std::function<void(LobbyMemberEntry)> m_cbPlayerDoesntHaveMap = nullptr;
254+
void RegisterForPlayerDoesntHaveMapCallback(std::function<void(LobbyMemberEntry)> cb)
255+
{
256+
m_cbPlayerDoesntHaveMap = cb;
257+
}
258+
249259
std::function<void(UnicodeString strMessage)> m_OnChatCallback = nullptr;
250260
void RegisterForChatCallback(std::function<void(UnicodeString strMessage)> cb)
251261
{

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupHostGame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,9 @@ void createGame( void )
598598
AsciiString passwd;
599599
passwd.translate(GadgetTextEntryGetText(textEntryGamePassword));
600600

601+
601602
// NGMP:NOTE: We count money here because mods etc sometimes change the starting money, so we dont want to hard code it, just create with whatever the client is telling us is a sensible amount
602-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->CreateLobby(gameName, md->m_displayName, md->m_fileName, md->m_numPlayers, limitArmies, useStats, TheGlobalData->m_defaultStartingCash.countMoney(), passwd.isNotEmpty(), passwd.str());
603+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->CreateLobby(gameName, md->m_displayName, md->m_fileName, md->m_isOfficial, md->m_numPlayers, limitArmies, useStats, TheGlobalData->m_defaultStartingCash.countMoney(), passwd.isNotEmpty(), passwd.str());
603604

604605
GSMessageBoxCancel(UnicodeString(L"Creating Lobby"), UnicodeString(L"Lobby Creation is in progress..."), nullptr);
605606

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,37 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
13981398
GadgetListBoxAddEntryText(listboxGameSetupChat, strMessage, GameMakeColor(255, 255, 255, 255), -1, -1);
13991399
});
14001400

1401+
// player doesnt have map events
1402+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->RegisterForPlayerDoesntHaveMapCallback([](LobbyMemberEntry lobbyMember)
1403+
{
1404+
// tell the host the user doesn't have the map
1405+
UnicodeString mapDisplayName;
1406+
const MapMetaData* mapData = TheMapCache->findMap(TheNGMPGame->getMap());
1407+
Bool willTransfer = TRUE;
1408+
if (mapData)
1409+
{
1410+
mapDisplayName.format(L"%ls", mapData->m_displayName.str());
1411+
willTransfer = !mapData->m_isOfficial;
1412+
}
1413+
else
1414+
{
1415+
mapDisplayName.format(L"%hs", TheNGMPGame->getMap().str());
1416+
willTransfer = WouldMapTransfer(TheNGMPGame->getMap());
1417+
}
1418+
1419+
UnicodeString strDisplayName;
1420+
strDisplayName.format(L"%hs", lobbyMember.display_name.c_str());
1421+
1422+
UnicodeString text;
1423+
if (willTransfer)
1424+
text.format(TheGameText->fetch("GUI:PlayerNoMapWillTransfer"), strDisplayName.str(), mapDisplayName.str());
1425+
else
1426+
text.format(TheGameText->fetch("GUI:PlayerNoMap"), strDisplayName.str(), mapDisplayName.str());
1427+
GadgetListBoxAddEntryText(listboxGameSetupChat, text, GameSpyColor[GSCOLOR_DEFAULT], -1, -1);
1428+
});
1429+
1430+
1431+
14011432
// register for roster events
14021433
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->RegisterForRosterNeedsRefreshCallback([]()
14031434
{
@@ -1550,7 +1581,7 @@ void WOLGameSetupMenuInit( WindowLayout *layout, void *userData )
15501581
}
15511582

15521583
// TODO_NGMP: preferred map support
1553-
AsciiString lowerMap = getDefaultMap(true);
1584+
AsciiString lowerMap = getDefaultOfficialMap();
15541585
//AsciiString lowerMap = customPref.getPreferredMap();
15551586
lowerMap.toLower();
15561587
std::map<AsciiString, MapMetaData>::iterator it = TheMapCache->find(lowerMap);

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLMapSelectMenu.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ void WOLMapSelectMenuInit( WindowLayout *layout, void *userData )
150150
usesSystemMapDir = mmd->m_isOfficial;
151151
}
152152

153+
// TODO_NGMP: Perhaps we should enforce this on the service too for extra security? base game didnt though.
153154
//if stats are enabled, only official maps can be used
154-
// TODO_NGMP: Reimpl this
155-
bool bUseStats = true;
156-
//if( TheGameSpyInfo->getCurrentStagingRoom()->getUseStats() )
157-
// usesSystemMapDir = true;
155+
bool bUseStats = TheNGMPGame->getUseStats();
156+
if(bUseStats)
157+
usesSystemMapDir = true;
158158

159159
buttonBack = TheNameKeyGenerator->nameToKey( AsciiString("WOLMapSelectMenu.wnd:ButtonBack") );
160160
buttonOK = TheNameKeyGenerator->nameToKey( AsciiString("WOLMapSelectMenu.wnd:ButtonOK") );
@@ -454,6 +454,7 @@ WindowMsgHandledType WOLMapSelectMenuSystem( GameWindow *window, UnsignedInt msg
454454

455455
int newMaxPlayers = -1;
456456
AsciiString strMapName;
457+
bool bOfficialMap = false;
457458

458459
TheNGMPGame->setMap(asciiMap);
459460
asciiMap.toLower();
@@ -466,6 +467,8 @@ WindowMsgHandledType WOLMapSelectMenuSystem( GameWindow *window, UnsignedInt msg
466467

467468
newMaxPlayers = it->second.m_numPlayers;
468469
strMapName.translate(it->second.m_displayName);
470+
471+
bOfficialMap = it->second.m_isOfficial;
469472
}
470473

471474
TheNGMPGame->adjustSlotsForMap(); // BGC- adjust the slots for the new map.
@@ -479,7 +482,7 @@ WindowMsgHandledType WOLMapSelectMenuSystem( GameWindow *window, UnsignedInt msg
479482
WOLDisplayGameOptions();
480483

481484
// NGMP: Update lobby
482-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_Map(strMapName, TheNGMPGame->getMap(), newMaxPlayers);
485+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->UpdateCurrentLobby_Map(strMapName, TheNGMPGame->getMap(), bOfficialMap, newMaxPlayers);
483486

484487
WOLMapSelectLayout->destroyWindows();
485488
WOLMapSelectLayout->deleteInstance();

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/LoadScreen.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,12 @@ void MapTransferLoadScreen::update( Int percent )
20642064
TheNetwork->liteupdate();
20652065
}
20662066

2067+
// GENERALS ONLINE: this is ticked in game engine, but game engine doesnt tick for MP loads and map transfers are while(true)... when the host is complete and remotes arent... do a liteupdate like TheNetwork does
2068+
if (NGMP_OnlineServicesManager::GetInstance() != nullptr)
2069+
{
2070+
NGMP_OnlineServicesManager::GetInstance()->Tick();
2071+
}
2072+
20672073
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
20682074

20692075
// Do this last!

GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
#include "GameNetwork/GameInfo.h"
6262
#include "GameNetwork/NetworkDefs.h"
6363

64+
#include "../NextGenMP_defines.h"
65+
#include "../NGMP_interfaces.h"
66+
6467
#ifdef _INTERNAL
6568
// for occasional debugging...
6669
//#pragma optimize("", off)
@@ -352,15 +355,34 @@ void WaypointMap::update( void )
352355

353356
const char * MapCache::m_mapCacheName = "MapCache.ini";
354357

355-
AsciiString MapCache::getMapDir() const
358+
AsciiString MapCache::getMapDir(bool bCustomMapDebug) const
356359
{
360+
#if defined(GENERALS_ONLINE_TEST_MAP_TRANSFER)
361+
362+
if (NGMP_OnlineServicesManager::GetInstance() != nullptr && NGMP_OnlineServicesManager::GetInstance()->GetAuthInterface()->GetUserID() == -2) // dev account 1 doesnt have custom maps, always transfer
363+
{
364+
if (bCustomMapDebug)
365+
{
366+
return AsciiString("MapsEmpty");
367+
}
368+
else
369+
{
370+
return AsciiString("Maps");
371+
}
372+
}
373+
else
374+
{
375+
return AsciiString("Maps");
376+
}
377+
#else
357378
return AsciiString("Maps");
379+
#endif
358380
}
359381

360-
AsciiString MapCache::getUserMapDir() const
382+
AsciiString MapCache::getUserMapDir(bool bCustomMapDebug) const
361383
{
362384
AsciiString tmp = TheGlobalData->getPath_UserData();
363-
tmp.concat(getMapDir());
385+
tmp.concat(getMapDir(bCustomMapDebug));
364386
return tmp;
365387
}
366388

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/NGMPGame.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ void NGMPGame::UpdateSlotsFromCurrentLobby()
129129
slot->unAccept();
130130
}
131131

132+
// has map?
133+
slot->setMapAvailability(pLobbyMember.has_map);
134+
132135
// store EOS ID
133136
slot->m_userID = pLobbyMember.user_id;
134137

0 commit comments

Comments
 (0)