@@ -161,56 +161,49 @@ void NGMP_OnlineServices_AuthInterface::BeginLogin()
161161
162162 NGMP_OnlineServicesManager::GetInstance ()->GetHTTPManager ()->SendPOSTRequest (strLoginURI.c_str (), EIPProtocolVersion::DONT_CARE , mapHeaders, strPostData.c_str (), [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq)
163163 {
164- try
164+ // if 4XX, just log in again
165+ if (statusCode >= 400 && statusCode < 500 )
165166 {
166- nlohmann::json jsonObject = nlohmann::json::parse (strBody, nullptr , false , true );
167- AuthResponse authResp = jsonObject.get <AuthResponse>();
168-
169- if (authResp.result == EAuthResponseResult::SUCCEEDED )
167+ NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Login failed due to 4XX code, trying to re-auth" );
168+ DoReAuth ();
169+ }
170+ else
171+ {
172+ try
170173 {
171- ClearGSMessageBoxes ( );
172- GSMessageBoxNoButtons ( UnicodeString ( L" Logging In " ), UnicodeString ( L" Logged in! " ), true );
174+ nlohmann::json jsonObject = nlohmann::json::parse (strBody, nullptr , false , true );
175+ AuthResponse authResp = jsonObject. get <AuthResponse>( );
173176
174- NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Logged in" );
175- m_bWaitingLogin = false ;
177+ if (authResp.result == EAuthResponseResult::SUCCEEDED )
178+ {
179+ ClearGSMessageBoxes ();
180+ GSMessageBoxNoButtons (UnicodeString (L" Logging In" ), UnicodeString (L" Logged in!" ), true );
176181
177- SaveCredentials (authResp.refresh_token .c_str ());
182+ NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Logged in" );
183+ m_bWaitingLogin = false ;
178184
179- // store data locally
180- m_strToken = authResp.session_token ;
181- m_userID = authResp.user_id ;
182- m_strDisplayName = authResp.display_name ;
185+ SaveCredentials (authResp.refresh_token .c_str ());
186+
187+ // store data locally
188+ m_strToken = authResp.session_token ;
189+ m_userID = authResp.user_id ;
190+ m_strDisplayName = authResp.display_name ;
183191
184- // trigger callback
185- OnLoginComplete (true , authResp.ws_uri .c_str ());
192+ // trigger callback
193+ OnLoginComplete (true , authResp.ws_uri .c_str ());
194+ }
195+ else if (authResp.result == EAuthResponseResult::FAILED )
196+ {
197+ NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Login failed, trying to re-auth" );
198+ DoReAuth ();
199+ }
186200 }
187- else if (authResp. result == EAuthResponseResult:: FAILED )
201+ catch (... )
188202 {
189- ClearGSMessageBoxes ();
190- GSMessageBoxNoButtons (UnicodeString (L" Logging In" ), UnicodeString (L" Please continue in your web browser" ), true );
191-
192- NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Login failed, trying to re-auth" );
193-
194- // do normal login flow, token is bad or expired etc
195- m_bWaitingLogin = true ;
196- m_lastCheckCode = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::utc_clock::now ().time_since_epoch ()).count ();
197- m_strCode = GenerateGamecode ();
198-
199- #if defined(USE_TEST_ENV)
200- std::string strURI = std::format (" http://www.playgenerals.online/login/?gamecode={}&env=test" , m_strCode.c_str ());
201- #else
202- std::string strURI = std::format (" http://www.playgenerals.online/login/?gamecode={}" , m_strCode.c_str ());
203- #endif
204-
205- #if !_DEBUG
206- ShellExecuteA (NULL , " open" , strURI.c_str (), NULL , NULL , SW_SHOWNORMAL );
207- #endif
203+ NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: Resp parse failed, trying to re-auth" );
204+ DoReAuth ();
208205 }
209206 }
210- catch (...)
211- {
212-
213- }
214207
215208 }, nullptr );
216209 }
@@ -239,6 +232,28 @@ void NGMP_OnlineServices_AuthInterface::BeginLogin()
239232 }
240233}
241234
235+ void NGMP_OnlineServices_AuthInterface::DoReAuth ()
236+ {
237+ NetworkLog (ELogVerbosity::LOG_RELEASE , " LOGIN: DoReAuth" );
238+ ClearGSMessageBoxes ();
239+ GSMessageBoxNoButtons (UnicodeString (L" Logging In" ), UnicodeString (L" Please continue in your web browser" ), true );
240+
241+ // do normal login flow, token is bad or expired etc
242+ m_bWaitingLogin = true ;
243+ m_lastCheckCode = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::utc_clock::now ().time_since_epoch ()).count ();
244+ m_strCode = GenerateGamecode ();
245+
246+ #if defined(USE_TEST_ENV)
247+ std::string strURI = std::format (" http://www.playgenerals.online/login/?gamecode={}&env=test" , m_strCode.c_str ());
248+ #else
249+ std::string strURI = std::format (" http://www.playgenerals.online/login/?gamecode={}" , m_strCode.c_str ());
250+ #endif
251+
252+ #if !_DEBUG
253+ ShellExecuteA (NULL , " open" , strURI.c_str (), NULL , NULL , SW_SHOWNORMAL );
254+ #endif
255+ }
256+
242257void NGMP_OnlineServices_AuthInterface::Tick ()
243258{
244259 if (m_bWaitingLogin)
0 commit comments