Skip to content

Commit 91e65cf

Browse files
committed
- Improved online startup and tear down flows
- improved version check flow
1 parent 09abbad commit 91e65cf

9 files changed

Lines changed: 125 additions & 42 deletions

File tree

GeneralsMD/Code/GameEngine/Include/Common/GameEngine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class Radar;
5555
class WebBrowser;
5656
class ParticleSystemManager;
5757

58+
void InitGeneralsOnline();
59+
void TearDownGeneralsOnline();
60+
5861
/**
5962
* The implementation of the game engine
6063
*/

GeneralsMD/Code/GameEngine/Include/GameNetwork/GeneralsOnline/HTTP/HTTPManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class HTTPManager
9191
std::string m_strProxyAddr;
9292
uint16_t m_proxyPort;
9393

94+
bool m_bExitRequested = false;
95+
9496
std::thread* m_backgroundThread = nullptr;
9597

9698
std::recursive_mutex m_mutex;

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class WebSocket
3434
void Connect(const char* url);
3535
void Disconnect();
3636

37+
void Shutdown();
38+
3739
void SendData_RoomChatMessage(const char* szMessage);
3840
void SendData_JoinNetworkRoom(int roomID);
3941
void SendData_MarkReady(bool bReady);
@@ -105,6 +107,7 @@ class NGMP_OnlineServicesManager
105107
return m_pOnlineServicesManager;
106108
}
107109

110+
void Shutdown();
108111

109112
~NGMP_OnlineServicesManager()
110113
{
@@ -125,9 +128,21 @@ class NGMP_OnlineServicesManager
125128
delete m_pRoomInterface;
126129
m_pRoomInterface = nullptr;
127130
}
131+
132+
if (m_pHTTPManager != nullptr)
133+
{
134+
delete m_pHTTPManager;
135+
m_pHTTPManager = nullptr;
136+
}
137+
138+
if (m_pWebSocket != nullptr)
139+
{
140+
delete m_pWebSocket;
141+
m_pWebSocket = nullptr;
142+
}
128143
}
129144

130-
void StartVersionCheck(std::function<void(bool bNeedsUpdate)> fnCallback);
145+
void StartVersionCheck(std::function<void(bool bSuccess, bool bNeedsUpdate)> fnCallback);
131146

132147
WebSocket* GetWebSocket() const { return m_pWebSocket; }
133148
HTTPManager* GetHTTPManager() const { return m_pHTTPManager; }

GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,20 @@
111111
// GENERALS ONLINE
112112
#include "../OnlineServices_Init.h"
113113
static NGMP_OnlineServicesManager* g_pOnlineServicesMgr = nullptr;
114+
static bool g_bTearDownGeneralsOnlineRequested = false;
115+
void InitGeneralsOnline()
116+
{
117+
// GENERALS ONLINE
118+
if (g_pOnlineServicesMgr == nullptr)
119+
{
120+
g_pOnlineServicesMgr = new NGMP_OnlineServicesManager();
121+
}
122+
}
123+
124+
void TearDownGeneralsOnline()
125+
{
126+
g_bTearDownGeneralsOnlineRequested = true;
127+
}
114128

115129
#ifdef _INTERNAL
116130
// for occasional debugging...
@@ -712,12 +726,6 @@ void GameEngine::init( int argc, char *argv[] )
712726

713727
TheSubsystemList->resetAll();
714728
HideControlBar();
715-
716-
// GENERALS ONLINE
717-
if (g_pOnlineServicesMgr == nullptr)
718-
{
719-
g_pOnlineServicesMgr = new NGMP_OnlineServicesManager();
720-
}
721729
} // end init
722730

723731
/** -----------------------------------------------------------------------------------------------
@@ -778,6 +786,18 @@ void GameEngine::update( void )
778786
TheGameClient->UPDATE();
779787
TheMessageStream->propagateMessages();
780788

789+
if (g_bTearDownGeneralsOnlineRequested) // delayed tear down
790+
{
791+
g_bTearDownGeneralsOnlineRequested = false;
792+
793+
if (g_pOnlineServicesMgr != nullptr)
794+
{
795+
g_pOnlineServicesMgr->Shutdown();
796+
delete g_pOnlineServicesMgr;
797+
g_pOnlineServicesMgr = nullptr;
798+
}
799+
800+
}
781801
if (g_pOnlineServicesMgr != nullptr)
782802
{
783803
g_pOnlineServicesMgr->Tick();

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ WindowMsgHandledType WOLWelcomeMenuSystem( GameWindow *window, UnsignedInt msg,
868868

869869
case GBM_SELECTED:
870870
{
871+
// TODO_NGMP: Support exiting online again
871872
if (buttonPushed)
872873
break;
873874

@@ -879,22 +880,10 @@ WindowMsgHandledType WOLWelcomeMenuSystem( GameWindow *window, UnsignedInt msg,
879880
//DEBUG_ASSERTCRASH(TheGameSpyChat->getPeer(), ("No GameSpy Peer object!"));
880881
//TheGameSpyChat->disconnectFromChat();
881882

882-
PeerRequest req;
883-
req.peerRequestType = PeerRequest::PEERREQUEST_LOGOUT;
884-
TheGameSpyPeerMessageQueue->addRequest( req );
885-
BuddyRequest breq;
886-
breq.buddyRequestType = BuddyRequest::BUDDYREQUEST_LOGOUT;
887-
TheGameSpyBuddyMessageQueue->addRequest( breq );
883+
// NGMP: Don't need to logout here, just kill the WS connection, that triggers a log out
884+
TearDownGeneralsOnline();
888885

889-
DEBUG_LOG(("Tearing down GameSpy from WOLWelcomeMenuSystem(GBM_SELECTED)\n"));
890-
TearDownGameSpy();
891-
892-
/*
893-
if (TheGameSpyChat->getPeer())
894-
{
895-
peerDisconnect(TheGameSpyChat->getPeer());
896-
}
897-
*/
886+
DEBUG_LOG(("Tearing down GeneralsOnline from WOLWelcomeMenuSystem(GBM_SELECTED)\n"));
898887

899888
buttonPushed = TRUE;
900889

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

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "WWDownload/Registry.h"
5555
#include "WWDownload/urlBuilder.h"
5656
#include "../OnlineServices_Init.h"
57+
#include "Common/GameEngine.h"
5758

5859
#ifdef _INTERNAL
5960
// for occasional debugging...
@@ -772,6 +773,9 @@ void StopAsyncDNSCheck( void )
772773

773774
void StartPatchCheck( void )
774775
{
776+
// GENERALS ONLINE
777+
InitGeneralsOnline();
778+
775779
checkingForPatchBeforeGameSpy = TRUE;
776780
cantConnectBeforeOnline = FALSE;
777781
timeThroughOnline++;
@@ -784,23 +788,43 @@ void StartPatchCheck( void )
784788
// TODO_NGMP: Uninit this when leaving MP, waste of resources and cycles
785789
NGMP_OnlineServicesManager::GetInstance()->Init();
786790

787-
NGMP_OnlineServicesManager::GetInstance()->StartVersionCheck([](bool bNeedsUpdate)
791+
NGMP_OnlineServicesManager::GetInstance()->StartVersionCheck([](bool bSuccess, bool bNeedsUpdate)
788792
{
789-
if (!bNeedsUpdate)
790-
{
791-
startOnline();
792-
}
793-
else
793+
cantConnectBeforeOnline = !bSuccess;
794+
mustDownloadPatch = bNeedsUpdate;
795+
796+
if (!bSuccess)
794797
{
795-
// TODO_NGMP: Later we should allow in-game updates
796798
if (onlineCancelWindow)
797799
{
798800
TheWindowManager->winDestroy(onlineCancelWindow);
799801
onlineCancelWindow = NULL;
800802
}
801803

802-
onlineCancelWindow = MessageBoxOk(TheGameText->fetch("GUI:PatchAvailable"),
803-
UnicodeString(L"An update is required.\n\nPlease visit www.playgenerals.online to download the latest update"), CancelPatchCheckCallbackAndReopenDropdown);
804+
TearDownGeneralsOnline();
805+
806+
MessageBoxOk(TheGameText->fetch("GUI:CannotConnectToServservTitle"),
807+
TheGameText->fetch("GUI:CannotConnectToServserv"),
808+
noPatchBeforeOnlineCallback);
809+
}
810+
else
811+
{
812+
if (!bNeedsUpdate)
813+
{
814+
startOnline();
815+
}
816+
else
817+
{
818+
// TODO_NGMP: Later we should allow in-game updates
819+
if (onlineCancelWindow)
820+
{
821+
TheWindowManager->winDestroy(onlineCancelWindow);
822+
onlineCancelWindow = NULL;
823+
}
824+
825+
onlineCancelWindow = MessageBoxOk(TheGameText->fetch("GUI:PatchAvailable"),
826+
UnicodeString(L"An update is required.\n\nPlease visit www.playgenerals.online to download the latest update"), CancelPatchCheckCallbackAndReopenDropdown);
827+
}
804828
}
805829
});
806830

GeneralsMD/Code/GameEngine/Source/GameNetwork/GeneralsOnline/HTTP/HTTPManager.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,20 @@ void HTTPManager::PlatformThreadedTick_Locked()
7272

7373
void HTTPManager::Shutdown()
7474
{
75+
m_mutex.lock();
76+
curl_multi_cleanup(m_pCurl);
77+
m_pCurl = nullptr;
7578

79+
m_mutex.unlock();
80+
81+
// TODO_HTTP: Wait for background thread to finish
82+
m_bExitRequested = true;
7683
}
7784

7885
void HTTPManager::BackgroundThreadRun()
7986
{
8087
// TODO_HTTP: While should be until core is existing
81-
while (true)
88+
while (!m_bExitRequested)
8289
{
8390
PlatformThreadedTick_PreLock();
8491

@@ -123,7 +130,7 @@ HTTPRequest* HTTPManager::PlatformCreateRequest(EHTTPVerb httpVerb, EIPProtocolV
123130

124131
HTTPManager::~HTTPManager()
125132
{
126-
curl_multi_cleanup(m_pCurl);
133+
Shutdown();
127134
}
128135

129136
void HTTPManager::MainThreadTick()

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,20 @@ std::string NGMP_OnlineServicesManager::GetAPIEndpoint(const char* szEndpoint, b
5353
}
5454
}
5555

56-
void NGMP_OnlineServicesManager::StartVersionCheck(std::function<void(bool bNeedsUpdate)> fnCallback)
56+
void NGMP_OnlineServicesManager::Shutdown()
57+
{
58+
if (m_pHTTPManager != nullptr)
59+
{
60+
m_pHTTPManager->Shutdown();
61+
}
62+
63+
if (m_pWebSocket != nullptr)
64+
{
65+
m_pWebSocket->Shutdown();
66+
}
67+
}
68+
69+
void NGMP_OnlineServicesManager::StartVersionCheck(std::function<void(bool bSuccess, bool bNeedsUpdate)> fnCallback)
5770
{
5871
std::string strURI = NGMP_OnlineServicesManager::GetAPIEndpoint("VersionCheck", false);
5972

@@ -74,16 +87,17 @@ void NGMP_OnlineServicesManager::StartVersionCheck(std::function<void(bool bNeed
7487
if (authResp.result == EVersionCheckResponseResult::OK)
7588
{
7689
NetworkLog("VERSION CHECK: Up To Date");
77-
fnCallback(false);
90+
fnCallback(true, false);
7891
}
7992
else
8093
{
81-
fnCallback(true);
94+
fnCallback(true, true);
8295
}
8396
}
8497
catch (...)
8598
{
8699
NetworkLog("VERSION CHECK: Failed to parse response");
100+
fnCallback(false, false);
87101
}
88102
});
89103
}
@@ -317,3 +331,8 @@ void NGMP_OnlineServicesManager::Tick()
317331
}
318332
};
319333
}
334+
335+
void WebSocket::Shutdown()
336+
{
337+
Disconnect();
338+
}

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WebSocket::WebSocket()
1313

1414
WebSocket::~WebSocket()
1515
{
16-
Disconnect();
16+
Shutdown();
1717
}
1818

1919
int WebSocket::Ping()
@@ -103,12 +103,16 @@ void WebSocket::Disconnect()
103103
return;
104104
}
105105

106-
// send close
107-
size_t sent;
108-
(void)curl_ws_send(m_pCurl, "", 0, &sent, 0, CURLWS_CLOSE);
106+
if (m_pCurl != nullptr)
107+
{
108+
// send close
109+
size_t sent;
110+
(void)curl_ws_send(m_pCurl, "", 0, &sent, 0, CURLWS_CLOSE);
109111

110-
// cleanup
111-
curl_easy_cleanup(m_pCurl);
112+
// cleanup
113+
curl_easy_cleanup(m_pCurl);
114+
m_pCurl = nullptr;
115+
}
112116
}
113117

114118
void WebSocket::Send(const char* send_payload)

0 commit comments

Comments
 (0)