@@ -84,6 +84,7 @@ static Bool s_inQM = FALSE;
8484extern 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
637638static 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// -------------------------------------------------------------------------------------------------
719725void 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// -------------------------------------------------------------------------------------------------
9731197void 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 )
0 commit comments