From 925f2cf562bf90b0cdf6f629e434db1c1c54fada Mon Sep 17 00:00:00 2001 From: HungDK <> Date: Thu, 7 May 2026 15:51:33 +0700 Subject: [PATCH] Fix logout flow, reentry instead half logout because sdk only except that --- .../Scripts/Network/CSNetwork/GameSession.cs | 7 +-- .../Scripts/Network/UnityGameSession.cs | 7 ++- .../Scripts/UI/Login/LoginScreenUI.cs | 46 ++++++++++++++++--- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs index 4bcd7bb5a8..2f91fcde21 100644 --- a/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs @@ -830,11 +830,8 @@ namespace CSNetwork // a_LogOutput(1, "CECGameSession::OnPrtcPlayerLogout, LogoutFlag=1 replaced by 2."); // g_pGame->GetGameRun()->SetLogoutFlag(2); // } - if (!IsConnected && EC_Game.GetGameRun().GetLogoutFlag() == 1) - { - // _logger.Log(LogType.Log, "CECGameSession::OnPrtcPlayerLogout, LogoutFlag=1 replaced by 2."); - EC_Game.GetGameRun().SetLogoutFlag(2); - } + // Keep half logout as role-select even if the server closes the socket. + // LoginScene will reconnect with saved credentials if needed. } /// Format parsed PLAYER_EQUIP_DETAIL with real game data: slot names and item names from element data. diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index ddc7c0b716..03dc90ee87 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -264,8 +264,11 @@ namespace BrewMonster.Network // Force the login UI to refresh to the correct entry state immediately. ApplyLoginEntryToUI(entryTarget); - // now we have to logout from Tech3C SDK - Tech3CSDKWrapper.Instance.Logout(); + if (entryTarget == LogoutFlowState.LoginEntryTarget.LoginUI) + { + // Account logout only; half logout keeps SDK credentials so LoginScene can reopen role select. + Tech3CSDKWrapper.Instance.Logout(); + } } private static void ApplyLoginEntryToUI(LogoutFlowState.LoginEntryTarget entryTarget) diff --git a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs index 5cbde28ad9..c6e873bc5c 100644 --- a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs +++ b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs @@ -84,11 +84,8 @@ namespace BrewMonster.UI _passwordInputField.text = PlayerPrefs.GetString("password", ""); #endif - // Default: login UI first, select-role hidden until login succeeds. - if (_selectCharacterScreen != null) - _selectCharacterScreen.gameObject.SetActive(false); - - // ApplyLoginEntry(LogoutFlowState.ConsumeNextLoginEntry()); + // Default is login UI, unless a logout flow asked us to return directly to role select. + ApplyLoginEntry(LogoutFlowState.ConsumeNextLoginEntry()); } private AudioClip PickLoginBGM() @@ -181,8 +178,43 @@ namespace BrewMonster.UI await UnityGameSession.Login(username, password, OnLoginComplete); } - // NOTE: Previously had an ApplyLoginEntry helper that referenced LogoutFlowState. - // It was unused and caused build/lint issues on some platforms, so it's been removed. + public async void ApplyLoginEntry(LogoutFlowState.LoginEntryTarget entryTarget) + { + if (entryTarget != LogoutFlowState.LoginEntryTarget.SelectRole) + { + if (_selectCharacterScreen != null) + _selectCharacterScreen.gameObject.SetActive(false); + + _loginInProgress = false; + if (_loginButton != null) + _loginButton.interactable = true; + return; + } + + if (_selectCharacterScreen != null) + _selectCharacterScreen.gameObject.SetActive(true); + + _loginInProgress = true; + if (_loginButton != null) + _loginButton.interactable = false; + + var session = UnityGameSession.Instance?.GameSession; + if (session != null && session.IsConnected) + { + UnityGameSession.GetRoleListAsync(OnGetRoleListComplete); + return; + } + + string username = PlayerPrefs.GetString("username", ""); + string password = PlayerPrefs.GetString("password", ""); + if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) + { + await BeginGameLoginAsync(username, password); + return; + } + + OnExitCharacterSelect(); + } /// /// Callback when the login is complete.