Skip to content

Commit 70585f7

Browse files
committed
WIP MM
1 parent 42a5c40 commit 70585f7

5 files changed

Lines changed: 323 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ enum EWebSocketMessageID
4848
NETWORK_CONNECTION_START_SIGNALLING = 17,
4949
NETWORK_CONNECTION_DISCONNECT_PLAYER = 18,
5050
NETWORK_CONNECTION_CLIENT_REQUEST_SIGNALLING = 19,
51+
MATCHMAKING_ACTION_JOIN_PREARRANGED_LOBBY = 20,
52+
MATCHMAKING_ACTION_START_GAME = 21,
53+
MATCHMAKING_MESSAGE = 22
5154
};
5255

5356
enum class EQoSRegions

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,33 @@ class NGMP_OnlineServices_LobbyInterface
7979

8080
void SearchForLobbies(std::function<void()> onStartCallback, std::function<void(std::vector<LobbyEntry>)> onCompleteCallback);
8181

82+
std::function<void(std::string)> m_fnCallbackMatchmakingMessage = nullptr;
83+
void RegisterForMatchmakingMessageCallback(std::function<void(std::string)> cb)
84+
{
85+
m_fnCallbackMatchmakingMessage = cb;
86+
}
87+
void InvokeMatchmakingMessageCallback(std::string str)
88+
{
89+
if (m_fnCallbackMatchmakingMessage != nullptr)
90+
{
91+
m_fnCallbackMatchmakingMessage(str);
92+
}
93+
}
94+
95+
void InvokeMatchmakingStartGameCallback()
96+
{
97+
if (m_fnCallbackMatchmakingStartGame != nullptr)
98+
{
99+
m_fnCallbackMatchmakingStartGame();
100+
}
101+
}
102+
103+
std::function<void()> m_fnCallbackMatchmakingStartGame = nullptr;
104+
void RegisterForMatchmakingStartGameCallback(std::function<void()> cb)
105+
{
106+
m_fnCallbackMatchmakingStartGame = cb;
107+
}
108+
82109
// updates
83110
void UpdateCurrentLobby_Map(AsciiString strMap, AsciiString strMapPath, bool bIsOfficial, int newMaxPlayers);
84111
void UpdateCurrentLobby_LimitSuperweapons(bool bLimitSuperweapons);

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

Lines changed: 230 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static Bool s_inQM = FALSE;
8484
extern NGMPGame* TheNGMPGame;
8585
#endif
8686
#include "../OnlineServices_MatchmakingInterface.h"
87+
#include "../OnlineServices_LobbyInterface.h"
8788

8889
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
8990
// window ids ------------------------------------------------------------------------------
@@ -636,6 +637,11 @@ static void populateQuickMatchMapSelectListbox( QuickMatchPreferences& pref )
636637

637638
static void saveQuickMatchOptions( void )
638639
{
640+
// TODO_QUICKMATCH
641+
#if defined(GENERALS_ONLINE)
642+
return;
643+
#endif
644+
639645
if(isInInit)
640646
return;
641647
QuickMatchPreferences pref;
@@ -718,6 +724,224 @@ static void saveQuickMatchOptions( void )
718724
//-------------------------------------------------------------------------------------------------
719725
void WOLQuickMatchMenuInit( WindowLayout *layout, void *userData )
720726
{
727+
#if defined(GENERALS_ONLINE)
728+
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
729+
730+
// cannot connect to the lobby we joined
731+
pLobbyInterface->RegisterForCannotConnectToLobbyCallback([](void)
732+
{
733+
// TODO_QUICKMATCH: Show error message + stop matchmaking + enable buttons again
734+
});
735+
#endif
736+
737+
738+
if (pLobbyInterface != nullptr)
739+
{
740+
// TODO_QUICKMATCH: Deregister when leaving QM
741+
pLobbyInterface->RegisterForMatchmakingMessageCallback([](std::string strMsg)
742+
{
743+
UnicodeString uMsg;
744+
uMsg.format(L"%hs", strMsg.c_str());
745+
746+
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, uMsg, GameSpyColor[GSCOLOR_DEFAULT], -1, -1);
747+
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);
748+
});
749+
750+
pLobbyInterface->RegisterForMatchmakingStartGameCallback([]()
751+
{
752+
buttonWiden->winEnable(FALSE);
753+
754+
////TheNGMPGame->enterGame();
755+
//TheNGMPGame->setSeed(12356);
756+
757+
// TODO_QUICKMATCH
758+
//TheGameSpyGame->markGameAsQM();
759+
760+
// TODO_QUICKMATCH
761+
//const LadderInfo* info = getLadderInfo();
762+
763+
Int i;
764+
Int numPlayers = 0;
765+
for (i = 0; i < MAX_SLOTS; ++i)
766+
{
767+
//TheNGMPGame->getSlot(i);
768+
// TODO_QUICKMATCH
769+
//if (!resp.stagingRoomPlayerNames[i].empty())
770+
// ++numPlayers;
771+
}
772+
773+
// TODO_QUICKMATCH
774+
// TODO_QUICKMATCH
775+
//std::list<AsciiString> maps = TheGameSpyConfig->getQMMaps();
776+
std::list<AsciiString> maps;
777+
maps.push_back(AsciiString("Maps\\Homeland Alliance\\Homeland Alliance.map"));
778+
779+
for (std::list<AsciiString>::const_iterator it = maps.begin(); it != maps.end(); ++it)
780+
{
781+
AsciiString theMap = *it;
782+
theMap.toLower();
783+
const MapMetaData* md = TheMapCache->findMap(theMap);
784+
if (md && md->m_numPlayers >= numPlayers)
785+
{
786+
TheNGMPGame->setMap(*it);
787+
788+
// TODO_QUICKMATCH
789+
//if (resp.qmStatus.mapIdx-- == 0)
790+
// break;
791+
}
792+
}
793+
794+
// TODO_QUICKMATCH: Create and join a lobby instead
795+
// create our mesh
796+
//if (pLobbyInterface != nullptr)
797+
{
798+
//pLobbyInterface->CreateMesh();
799+
}
800+
801+
802+
Int numPlayersPerTeam = numPlayers / 2;
803+
DEBUG_ASSERTCRASH(numPlayersPerTeam, ("0 players per team???"));
804+
if (!numPlayersPerTeam)
805+
numPlayersPerTeam = 1;
806+
807+
for (i = 0; i < MAX_SLOTS; ++i)
808+
{
809+
NGMPGameSlot* slot = (NGMPGameSlot*)TheNGMPGame->getSlot(i);
810+
811+
////slot->setMapAvailability(TRUE);
812+
813+
// TODO_QUICKMATCH
814+
//if (resp.stagingRoomPlayerNames[i].empty())
815+
if (false)
816+
{
817+
//slot->setState(SLOT_CLOSED);
818+
}
819+
else if (slot->getState() == SLOT_PLAYER)
820+
{
821+
// TODO_QUICKMATCH
822+
//AsciiString aName = resp.stagingRoomPlayerNames[i].c_str();
823+
//AsciiString aName;
824+
//aName.format("QM User %d", i);
825+
//UnicodeString uName;
826+
//uName.translate(aName);
827+
//slot->setState(SLOT_PLAYER, uName, 0);
828+
829+
// TODO_QUICKMATCH
830+
slot->setColor(i);
831+
832+
// TODO_QUICKMATCH
833+
slot->setStartPos(i);
834+
slot->setPlayerTemplate(5+i);
835+
//slot->setProfileID(0);
836+
slot->setNATBehavior((FirewallHelperClass::FirewallBehaviorType)0);
837+
//slot->setLocale("");
838+
slot->setTeamNumber(i / numPlayersPerTeam);
839+
840+
slot->setMapAvailability(true);
841+
842+
// TODO_QUICKMATCH
843+
if (i == 0)
844+
TheNGMPGame->setGameName(UnicodeString(L"Quickmatch"));
845+
}
846+
}
847+
848+
//DEBUG_LOG(("Starting a QM game: options=[%s]", GameInfoToAsciiString(TheGameSpyGame).str()));
849+
//SendStatsToOtherPlayers(TheNGMPGame);
850+
TheNGMPGame->startGame(0);
851+
GameWindow* buttonBuddies = TheWindowManager->winGetWindowFromId(NULL, buttonBuddiesID);
852+
if (buttonBuddies)
853+
buttonBuddies->winEnable(FALSE);
854+
GameSpyCloseOverlay(GSOVERLAY_BUDDY);
855+
});
856+
857+
pLobbyInterface->RegisterForJoinLobbyCallback([](EJoinLobbyResult result)
858+
{
859+
NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
860+
861+
if (!pLobbyInterface->IsInLobby())
862+
{
863+
return;
864+
}
865+
866+
if (TheNGMPGame == nullptr)
867+
{
868+
TheNGMPGame = new NGMPGame();
869+
}
870+
pLobbyInterface->UpdateRoomDataCache([]()
871+
{
872+
873+
});
874+
875+
// connection events (for debug really)
876+
NetworkMesh* pMesh = NGMP_OnlineServicesManager::GetNetworkMesh();
877+
if (pMesh != nullptr)
878+
{
879+
pMesh->RegisterForConnectionEvents([](int64_t userID, std::wstring strDisplayName, PlayerConnection* connection)
880+
{
881+
std::string strState = "Unknown";
882+
883+
EConnectionState connState = connection->GetState();
884+
std::string strConnectionType = connection->GetConnectionType();
885+
886+
switch (connState)
887+
{
888+
case EConnectionState::NOT_CONNECTED:
889+
strState = "Not Connected";
890+
break;
891+
892+
case EConnectionState::CONNECTING_DIRECT:
893+
strState = "Connecting";
894+
break;
895+
case EConnectionState::FINDING_ROUTE:
896+
strState = "Connecting (Finding Route)";
897+
break;
898+
899+
case EConnectionState::CONNECTED_DIRECT:
900+
strState = "Connected";
901+
break;
902+
903+
case EConnectionState::CONNECTION_FAILED:
904+
strState = "Connection Failed";
905+
break;
906+
907+
case EConnectionState::CONNECTION_DISCONNECTED:
908+
strState = "Disconnected (Was Connected Previously)";
909+
break;
910+
911+
default:
912+
strState = "Unknown";
913+
break;
914+
}
915+
916+
UnicodeString strConnectionMessage;
917+
if (connState == EConnectionState::CONNECTING_DIRECT || connState == EConnectionState::FINDING_ROUTE)
918+
{
919+
strConnectionMessage.format(L"Connecting to %s", strDisplayName.c_str());
920+
921+
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, strConnectionMessage, GameMakeColor(255, 194, 15, 255), -1, -1);
922+
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);
923+
}
924+
else if (connState == EConnectionState::CONNECTED_DIRECT)
925+
{
926+
strConnectionMessage.format(L"Connected to %s", strDisplayName.c_str());
927+
928+
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, strConnectionMessage, GameMakeColor(255, 194, 15, 255), -1, -1);
929+
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);
930+
}
931+
else
932+
{
933+
if (connState == EConnectionState::CONNECTION_FAILED || connState == EConnectionState::CONNECTION_DISCONNECTED)
934+
{
935+
strConnectionMessage.format(L"Connection failed to %s", strDisplayName.c_str());
936+
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, strConnectionMessage, GameMakeColor(255, 194, 15, 255), -1, -1);
937+
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);
938+
}
939+
}
940+
});
941+
}
942+
943+
});
944+
}
721945
isInInit = TRUE;
722946
if (TheGameSpyGame && TheGameSpyGame->isGameInProgress())
723947
{
@@ -972,7 +1196,9 @@ static void shutdownComplete( WindowLayout *layout )
9721196
//-------------------------------------------------------------------------------------------------
9731197
void WOLQuickMatchMenuShutdown( WindowLayout *layout, void *userData )
9741198
{
1199+
#if !defined(GENERALS_ONLINE)
9751200
TheGameSpyInfo->unregisterTextWindow(quickmatchTextWindow);
1201+
#endif
9761202

9771203
if (!TheGameEngine->getQuitting())
9781204
saveQuickMatchOptions();
@@ -1068,7 +1294,7 @@ void WOLQuickMatchMenuUpdate( WindowLayout * layout, void *userData)
10681294
RaiseGSMessageBox();
10691295
raiseMessageBoxes = false;
10701296
}
1071-
1297+
10721298
/// @todo: MDC handle disconnects in-game the same way as Custom Match!
10731299

10741300
if (TheShell->isAnimFinished() && !buttonPushed && TheGameSpyPeerMessageQueue)
@@ -1734,8 +1960,6 @@ WindowMsgHandledType WOLQuickMatchMenuSystem( GameWindow *window, UnsignedInt ms
17341960
// TODO_QUICKMATCH: Chat has a sound effect in TheGameSpyInfo, re-eanble it
17351961
if (bSuccess)
17361962
{
1737-
Int index = GadgetListBoxAddEntryText(quickmatchTextWindow, UnicodeString(L"Started matchmaking... searching for players"), GameSpyColor[GSCOLOR_DEFAULT], -1, -1);
1738-
GadgetListBoxSetItemData(quickmatchTextWindow, (void*)-1, index);
17391963

17401964
// buttons
17411965
buttonWiden->winEnable(FALSE);
@@ -1938,8 +2162,10 @@ WindowMsgHandledType WOLQuickMatchMenuSystem( GameWindow *window, UnsignedInt ms
19382162
}
19392163
else if ( controlID == buttonBackID )
19402164
{
1941-
buttonPushed = true;
2165+
#if !defined(GENERALS_ONLINE)
19422166
TheGameSpyInfo->leaveGroupRoom();
2167+
#endif
2168+
buttonPushed = true;
19432169
nextScreen = "Menus/WOLWelcomeMenu.wnd";
19442170
TheShell->pop();
19452171
} //if ( controlID == buttonBack )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ void NGMP_OnlineServicesManager::Init()
365365
m_pLobbyInterface = new NGMP_OnlineServices_LobbyInterface();
366366
m_pRoomInterface = new NGMP_OnlineServices_RoomsInterface();
367367
m_pStatsInterface = new NGMP_OnlineServices_StatsInterface();
368+
m_pMatchmakingInterface = new NGMP_OnlineServices_MatchmakingInterface();
368369

369370
m_pHTTPManager = new HTTPManager();
370371
m_pHTTPManager->Initialize();

0 commit comments

Comments
 (0)