diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Common/Network/GameNetworkManager.cpp index e5280fe4..bd1d73c3 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Common/Network/GameNetworkManager.cpp @@ -54,6 +54,8 @@ int64_t CGameNetworkManager::messageQueue[512]; int64_t CGameNetworkManager::byteQueue[512]; int CGameNetworkManager::messageQueuePos = 0; +CRITICAL_SECTION bCancelRequestedCS; + CGameNetworkManager::CGameNetworkManager() { m_bInitialised = false; @@ -80,9 +82,12 @@ void CGameNetworkManager::Initialise() #else s_pPlatformNetworkManager = new CPlatformNetworkManagerStub(); #endif + m_bCancelRequested = false; s_pPlatformNetworkManager->Initialise( this, flagIndexSize ); m_bNetworkThreadRunning = false; m_bInitialised = true; + + InitializeCriticalSection(&bCancelRequestedCS); } void CGameNetworkManager::Terminate() @@ -435,6 +440,24 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft *minecraft, LPVOID lpParame app.DebugPrintf("ticking connection A\n"); connection->tick(); + EnterCriticalSection(&bCancelRequestedCS); + bool bCancelled = g_NetworkManager.m_bCancelRequested; + + if (bCancelled) + { + if (!app.GetGameStarted()) + { + app.DebugPrintf("Cancel requested, closing connection\n"); + g_NetworkManager.m_bCancelRequested = false; + LeaveCriticalSection(&bCancelRequestedCS); + connection->close(); + + break; + } + } + LeaveCriticalSection(&bCancelRequestedCS); + + // 4J Stu - We were ticking this way too fast which could cause the connection to time out // The connections should tick at 20 per second Sleep(50); @@ -552,6 +575,10 @@ bool CGameNetworkManager::StartNetworkGame(Minecraft *minecraft, LPVOID lpParame else if ( connection->isClosed() || !IsInSession()) { // assert(false); + // Set to NULL because we're returning to home + // The level is not reset when you leave the progress UI which causes a crash + Minecraft::GetInstance()->setLevel(NULL); + MinecraftServer::HaltServer(); return false; } @@ -769,6 +796,9 @@ CGameNetworkManager::eJoinGameResult CGameNetworkManager::JoinGame(FriendSession void CGameNetworkManager::CancelJoinGame(LPVOID lpParam) { + EnterCriticalSection(&bCancelRequestedCS); + g_NetworkManager.m_bCancelRequested = true; + LeaveCriticalSection(&bCancelRequestedCS); #ifdef _XBOX_ONE s_pPlatformNetworkManager->CancelJoinGame(); #endif @@ -1452,6 +1482,9 @@ void CGameNetworkManager::StateChange_AnyToStarting() LoadingInputParams *loadingParams = new LoadingInputParams(); loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc; loadingParams->lpParam = nullptr; + loadingParams->cancelText = IDS_TOOLTIPS_CANCEL_JOIN; + loadingParams->cancelFunc = &CGameNetworkManager::CancelJoinGame; + loadingParams->waitForThreadToDelete = TRUE; UIFullscreenProgressCompletionData *completionData = new UIFullscreenProgressCompletionData(); completionData->bShowBackground=TRUE; diff --git a/Minecraft.Client/Common/Network/GameNetworkManager.h b/Minecraft.Client/Common/Network/GameNetworkManager.h index c9316f73..740313a5 100644 --- a/Minecraft.Client/Common/Network/GameNetworkManager.h +++ b/Minecraft.Client/Common/Network/GameNetworkManager.h @@ -213,6 +213,7 @@ private: int GetJoiningReadyPercentage(); bool m_bLastDisconnectWasLostRoomOnly; bool m_bFullSessionMessageOnNextSessionChange; + bool m_bCancelRequested; #if defined __PS3__ || defined __PSVITA__ || defined __ORBIS__ bool m_bSignedOutofPSN; #endif diff --git a/Minecraft.Client/Common/UI/UIScene_FullscreenProgress.cpp b/Minecraft.Client/Common/UI/UIScene_FullscreenProgress.cpp index 8330ae8e..f8e10a4e 100644 --- a/Minecraft.Client/Common/UI/UIScene_FullscreenProgress.cpp +++ b/Minecraft.Client/Common/UI/UIScene_FullscreenProgress.cpp @@ -287,7 +287,11 @@ void UIScene_FullscreenProgress::handleInput(int iPad, int key, bool repeat, boo case ACTION_MENU_CANCEL: if( pressed && m_cancelFunc != nullptr && !m_bWasCancelled ) { + m_cancelText = -1; + updateTooltips(); + m_bWasCancelled = true; + m_cancelFunc( m_cancelFuncParam ); } break;