Skip to content

Commit d7e85db

Browse files
committed
- support passworded lobbies
1 parent 29a4076 commit d7e85db

6 files changed

Lines changed: 122 additions & 35 deletions

File tree

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,22 @@ struct LobbyEntry
3535
bool limit_superweapons;
3636
bool track_stats;
3737

38+
bool passworded;
39+
std::string password;
40+
3841
std::vector<BYTE> EncKey;
3942
std::vector<BYTE> EncIV;
4043
std::vector<LobbyMemberEntry> members;
4144
};
4245

46+
enum class EJoinLobbyResult
47+
{
48+
JoinLobbyResult_Success, // The room was joined.
49+
JoinLobbyResult_FullRoom, // The room is full.
50+
JoinLobbyResult_BadPassword, // An incorrect password (or none) was given for a passworded room.
51+
JoinLobbyResult_JoinFailed // Generic failure.
52+
};
53+
4354
struct LobbyMemberEntry;
4455
struct LobbyEntry;
4556

@@ -103,7 +114,7 @@ class NGMP_OnlineServices_LobbyInterface
103114
UnicodeString m_PendingCreation_LobbyName;
104115
UnicodeString m_PendingCreation_InitialMapDisplayName;
105116
AsciiString m_PendingCreation_InitialMapPath;
106-
void CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash);
117+
void CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash, bool bPassworded, const char* szPassword);
107118

108119
void OnJoinedOrCreatedLobby(bool bAlreadyUpdatedDetails = false);
109120

@@ -241,7 +252,7 @@ class NGMP_OnlineServices_LobbyInterface
241252
m_OnChatCallback = cb;
242253
}
243254

244-
void RegisterForJoinLobbyCallback(std::function<void(bool)> cb)
255+
void RegisterForJoinLobbyCallback(std::function<void(EJoinLobbyResult)> cb)
245256
{
246257
m_callbackJoinedLobby = cb;
247258
}
@@ -283,7 +294,8 @@ class NGMP_OnlineServices_LobbyInterface
283294

284295
NetworkMesh* GetNetworkMesh() { return m_pLobbyMesh; }
285296

286-
void JoinLobby(int index);
297+
void JoinLobby(int index, const char* szPassword);
298+
void JoinLobby(LobbyEntry lobby, const char* szPassword);
287299

288300
void LeaveCurrentLobby();
289301

@@ -309,10 +321,25 @@ class NGMP_OnlineServices_LobbyInterface
309321
return m_timeStartAutoReadyCountdown != -1;
310322
}
311323

324+
void SetLobbyTryingToJoin(LobbyEntry lobby)
325+
{
326+
m_LobbyTryingToJoin = lobby;
327+
}
328+
329+
void ResetLobbyTryingToJoin()
330+
{
331+
m_LobbyTryingToJoin = LobbyEntry();
332+
}
333+
334+
LobbyEntry GetLobbyTryingToJoin()
335+
{
336+
return m_LobbyTryingToJoin;
337+
}
338+
312339
private:
313340
std::vector<std::function<void(bool)>> m_vecCreateLobby_PendingCallbacks = std::vector<std::function<void(bool)>>();
314341

315-
std::function<void(bool)> m_callbackJoinedLobby = nullptr;
342+
std::function<void(EJoinLobbyResult)> m_callbackJoinedLobby = nullptr;
316343

317344
LobbyEntry m_CurrentLobby;
318345

@@ -324,4 +351,6 @@ class NGMP_OnlineServices_LobbyInterface
324351
bool m_bLobbyListDirty = false;
325352

326353
int64_t m_timeStartAutoReadyCountdown = -1;
354+
355+
LobbyEntry m_LobbyTryingToJoin;
327356
};

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,11 @@ void createGame( void )
595595

596596
UnicodeString gameName = GadgetTextEntryGetText(textEntryGameName);
597597

598+
AsciiString passwd;
599+
passwd.translate(GadgetTextEntryGetText(textEntryGamePassword));
600+
598601
// 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
599-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->CreateLobby(gameName, md->m_displayName, md->m_fileName, md->m_numPlayers, limitArmies, useStats, TheGlobalData->m_defaultStartingCash.countMoney());
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());
600603

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

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
#include "GameNetwork/GameSpy/PeerDefs.h"
6363
#include "GameNetwork/GameSpy/PeerThread.h"
6464
#include "GameNetwork/GameSpyOverlay.h"
65+
#include "../ngmp_include.h"
66+
#include "../ngmp_interfaces.h"
6567

6668

6769
//-----------------------------------------------------------------------------
@@ -99,9 +101,10 @@ void PopupJoinGameInit( WindowLayout *layout, void *userData )
99101

100102
buttonCancelID = NAMEKEY("PopupJoinGame.wnd:ButtonCancel");
101103

102-
GameSpyStagingRoom *ourRoom = TheGameSpyInfo->findStagingRoomByID(TheGameSpyInfo->getCurrentStagingRoomID());
103-
if (ourRoom)
104-
GadgetStaticTextSetText(staticTextGameName, ourRoom->getGameName());
104+
LobbyEntry lobbyTryingToJoin = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetLobbyTryingToJoin();
105+
UnicodeString lobbyName;
106+
lobbyName.translate(lobbyTryingToJoin.name.c_str());
107+
GadgetStaticTextSetText(staticTextGameName, lobbyName);
105108

106109
TheWindowManager->winSetFocus( parentPopup );
107110
TheWindowManager->winSetModal( parentPopup );
@@ -243,21 +246,19 @@ WindowMsgHandledType PopupJoinGameSystem( GameWindow *window, UnsignedInt msg, W
243246

244247
static void joinGame( AsciiString password )
245248
{
246-
GameSpyStagingRoom *ourRoom = TheGameSpyInfo->findStagingRoomByID(TheGameSpyInfo->getCurrentStagingRoomID());
247-
if (!ourRoom)
249+
LobbyEntry lobbyTryingToJoin = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetLobbyTryingToJoin();
250+
251+
if (lobbyTryingToJoin.lobbyID == -1)
248252
{
249253
GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
250-
SetLobbyAttemptHostJoin( FALSE );
254+
SetLobbyAttemptHostJoin(FALSE);
251255
parentPopup = NULL;
252256
return;
253257
}
254-
PeerRequest req;
255-
req.peerRequestType = PeerRequest::PEERREQUEST_JOINSTAGINGROOM;
256-
req.text = ourRoom->getGameName().str();
257-
req.stagingRoom.id = ourRoom->getID();
258-
req.password = password.str();
259-
TheGameSpyPeerMessageQueue->addRequest(req);
260-
DEBUG_LOG(("Attempting to join game %d(%ls) with password [%s]\n", ourRoom->getID(), ourRoom->getGameName().str(), password.str()));
258+
259+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->JoinLobby(lobbyTryingToJoin, password.str());
260+
261+
DEBUG_LOG(("Attempting to join game %d(%s) with password [%s]\n", lobbyTryingToJoin.lobbyID, lobbyTryingToJoin.name.c_str(), password.str()));
261262
GameSpyCloseOverlay(GSOVERLAY_GAMEPASSWORD);
262263
parentPopup = NULL;
263264
}

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,12 @@ void NGMP_WOLLobbyMenu_CreateLobbyCallback(bool bSuccess)
704704
//TheGameSpyInfo->setGameOptions();
705705
}
706706

707-
void NGMP_WOLLobbyMenu_JoinLobbyCallback(bool bSuccess)
707+
void NGMP_WOLLobbyMenu_JoinLobbyCallback(EJoinLobbyResult result)
708708
{
709709
// TODO_NGMP: Show accurate errors again
710710

711711
SetLobbyAttemptHostJoin(FALSE);
712-
if (bSuccess)
712+
if (result == EJoinLobbyResult::JoinLobbyResult_Success)
713713
{
714714
// Woohoo! On to our next screen!
715715
buttonPushed = true;
@@ -718,35 +718,43 @@ void NGMP_WOLLobbyMenu_JoinLobbyCallback(bool bSuccess)
718718
}
719719
else
720720
{
721-
GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), UnicodeString(L"TODO_NGMP"));
722-
/*
723721
UnicodeString s;
724722

725-
switch (resp.joinStagingRoom.result)
723+
switch (result)
726724
{
727-
case PEERFullRoom: // The room is full.
725+
case EJoinLobbyResult::JoinLobbyResult_FullRoom: // The room is full.
728726
s = TheGameText->fetch("GUI:JoinFailedRoomFull");
729727
break;
728+
729+
// NOTE: Commented out ones are no longer supported. Seems like these we GS concepts but not part of the game
730+
/*
730731
case PEERInviteOnlyRoom: // The room is invite only.
731732
s = TheGameText->fetch("GUI:JoinFailedInviteOnly");
732733
break;
733734
case PEERBannedFromRoom: // The local user is banned from the room.
734735
s = TheGameText->fetch("GUI:JoinFailedBannedFromRoom");
735736
break;
736-
case PEERBadPassword: // An incorrect password (or none) was given for a passworded room.
737+
*/
738+
case EJoinLobbyResult::JoinLobbyResult_BadPassword: // An incorrect password (or none) was given for a passworded room.
737739
s = TheGameText->fetch("GUI:JoinFailedBadPassword");
738740
break;
741+
/*
739742
case PEERAlreadyInRoom: // The local user is already in or entering a room of the same type.
740743
s = TheGameText->fetch("GUI:JoinFailedAlreadyInRoom");
741744
break;
742745
case PEERNoConnection: // Can't join a room if there's no chat connection.
743746
s = TheGameText->fetch("GUI:JoinFailedNoConnection");
744747
break;
748+
*/
745749
default:
746750
s = TheGameText->fetch("GUI:JoinFailedDefault");
747751
break;
748752
}
753+
749754
GSMessageBoxOk(TheGameText->fetch("GUI:JoinFailedDefault"), s);
755+
756+
// NGMP: We don't need to do this anymore, the service does it for us
757+
/*
750758
if (groupRoomToJoin)
751759
{
752760
DEBUG_LOG(("WOLLobbyMenuUpdate() - rejoining group room %d\n", groupRoomToJoin));
@@ -1814,11 +1822,27 @@ WindowMsgHandledType WOLLobbyMenuSystem( GameWindow *window, UnsignedInt msg,
18141822
//Int selectedID = (Int)GadgetListBoxGetItemData(GetGameListBox(), selected);
18151823
//if (selectedID > 0)
18161824
{
1817-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->JoinLobby(selected);
1825+
// TODO_NGMP: Enforce this on the host too, vanilla game did not...
1826+
1827+
auto Lobby = NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->GetLobbyFromIndex(selected);
1828+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->SetLobbyTryingToJoin(Lobby);
1829+
1830+
if (Lobby.passworded)
1831+
{
1832+
GameSpyOpenOverlay(GSOVERLAY_GAMEPASSWORD);
1833+
}
1834+
else
1835+
{
1836+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->JoinLobby(selected, nullptr);
18181837

1819-
SetLobbyAttemptHostJoin(TRUE);
1838+
SetLobbyAttemptHostJoin(TRUE);
1839+
}
18201840
}
18211841
}
1842+
else
1843+
{
1844+
GSMessageBoxOk(TheGameText->fetch("GUI:Error"), TheGameText->fetch("GUI:NoGameSelected"), NULL);
1845+
}
18221846
// TODO_NGMP: Start using StagingRoomInfo again, it'll make this easier and cleaner
18231847
/*
18241848
if (s_tryingToHostOrJoin)

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/LobbyUtils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ static Int insertGame(GameWindow* win, LobbyEntry& lobbyInfo, Bool showMap)
573573
USHORT ladderPort = 1;
574574
int gameID = 0;
575575

576-
bool bHasPassword = false;
576+
bool bHasPassword = lobbyInfo.passworded;
577+
578+
// TODO_NGMP
577579
bool bAllowSpectators = true;
578580
int latency = 5;
579581

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,15 @@ void NGMP_OnlineServices_LobbyInterface::UpdateRoomDataCache(std::function<void(
665665
*/
666666
}
667667

668-
void NGMP_OnlineServices_LobbyInterface::JoinLobby(int index)
668+
void NGMP_OnlineServices_LobbyInterface::JoinLobby(int index, const char* szPassword)
669669
{
670-
m_CurrentLobby = LobbyEntry();
671670
LobbyEntry lobbyInfo = GetLobbyFromIndex(index);
671+
JoinLobby(lobbyInfo, szPassword);
672+
}
673+
674+
void NGMP_OnlineServices_LobbyInterface::JoinLobby(LobbyEntry lobbyInfo, const char* szPassword)
675+
{
676+
m_CurrentLobby = LobbyEntry();
672677

673678
std::string strURI = std::format("{}/{}", NGMP_OnlineServicesManager::GetAPIEndpoint("Lobby", true), lobbyInfo.lobbyID);
674679
std::map<std::string, std::string> mapHeaders;
@@ -677,16 +682,35 @@ void NGMP_OnlineServices_LobbyInterface::JoinLobby(int index)
677682

678683
nlohmann::json j;
679684
j["preferred_port"] = NGMP_OnlineServicesManager::GetInstance()->GetPortMapper().GetOpenPort();
685+
686+
if (szPassword != nullptr && strlen(szPassword) > 0)
687+
{
688+
j["password"] = szPassword;
689+
}
690+
680691
std::string strPostData = j.dump();
681692

682693
// convert
683694
NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPUTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody)
684695
{
696+
// reset trying to join
697+
ResetLobbyTryingToJoin();
698+
685699
// TODO_NGMP: Dont do extra get here, just return it in the put...
686-
bool bJoinSuccess = statusCode == 200;
700+
EJoinLobbyResult JoinResult = EJoinLobbyResult::JoinLobbyResult_JoinFailed;
687701

688-
// no response body from this, just http codes
689702
if (statusCode == 200)
703+
{
704+
JoinResult = EJoinLobbyResult::JoinLobbyResult_Success;
705+
}
706+
else if (statusCode == 401)
707+
{
708+
JoinResult = EJoinLobbyResult::JoinLobbyResult_BadPassword;
709+
}
710+
// TODO_NGMP: Handle room full error (JoinLobbyResult_FullRoom, can we even get that?
711+
712+
// no response body from this, just http codes
713+
if (JoinResult == EJoinLobbyResult::JoinLobbyResult_Success)
690714
{
691715
NetworkLog("[NGMP] Joined lobby");
692716

@@ -729,7 +753,7 @@ void NGMP_OnlineServices_LobbyInterface::JoinLobby(int index)
729753
}
730754
else if (statusCode == 401)
731755
{
732-
NetworkLog("[NGMP] Couldn't join lobby");
756+
NetworkLog("[NGMP] Couldn't join lobby, unauthorized, probably the wrong password");
733757
}
734758
else if (statusCode == 404)
735759
{
@@ -742,7 +766,7 @@ void NGMP_OnlineServices_LobbyInterface::JoinLobby(int index)
742766

743767
if (NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->m_callbackJoinedLobby != nullptr)
744768
{
745-
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->m_callbackJoinedLobby(bJoinSuccess);
769+
NGMP_OnlineServicesManager::GetInstance()->GetLobbyInterface()->m_callbackJoinedLobby(JoinResult);
746770
}
747771
});
748772

@@ -915,7 +939,7 @@ struct CreateLobbyResponse
915939
NLOHMANN_DEFINE_TYPE_INTRUSIVE(CreateLobbyResponse, result, lobby_id)
916940
};
917941

918-
void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash)
942+
void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName, UnicodeString strInitialMapName, AsciiString strInitialMapPath, int initialMaxSize, bool bVanillaTeamsOnly, bool bTrackStats, uint32_t startingCash, bool bPassworded, const char* szPassword)
919943
{
920944
m_CurrentLobby = LobbyEntry();
921945
std::string strURI = NGMP_OnlineServicesManager::GetAPIEndpoint("Lobbies", true);
@@ -937,6 +961,8 @@ void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName,
937961
j["vanilla_teams"] = bVanillaTeamsOnly;
938962
j["track_stats"] = bTrackStats;
939963
j["starting_cash"] = startingCash;
964+
j["passworded"] = bPassworded;
965+
j["password"] = szPassword;
940966
std::string strPostData = j.dump();
941967

942968
NGMP_OnlineServicesManager::GetInstance()->GetHTTPManager()->SendPUTRequest(strURI.c_str(), EIPProtocolVersion::DONT_CARE, mapHeaders, strPostData.c_str(), [=](bool bSuccess, int statusCode, std::string strBody)
@@ -962,6 +988,8 @@ void NGMP_OnlineServices_LobbyInterface::CreateLobby(UnicodeString strLobbyName,
962988
m_CurrentLobby.map_path = std::string(strInitialMapPath.str());
963989
m_CurrentLobby.current_players = 1;
964990
m_CurrentLobby.max_players = initialMaxSize;
991+
m_CurrentLobby.passworded = bPassworded;
992+
m_CurrentLobby.password = std::string(szPassword);
965993

966994
LobbyMemberEntry me;
967995

0 commit comments

Comments
 (0)