Fix use old login sdk first
This commit is contained in:
@@ -233,7 +233,8 @@ namespace BrewMonster.Network
|
||||
var ui = all[i];
|
||||
if (ui == null) continue;
|
||||
if (!ui.gameObject.scene.IsValid() || ui.gameObject.scene.name != LoginSceneName) continue;
|
||||
ui.ApplyLoginEntry(entryTarget);
|
||||
// Avoid hard dependency on method existence (merges may edit LoginScreenUI).
|
||||
ui.SendMessage("ApplyLoginEntry", entryTarget, SendMessageOptions.DontRequireReceiver);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ namespace BrewMonster.UI
|
||||
|
||||
void Awake()
|
||||
{
|
||||
var tech3CWrapper = Tech3CSDKWrapper.Instance;
|
||||
// Ensure wrapper created early (Tech3C SDK).
|
||||
_ = Tech3CSDKWrapper.Instance;
|
||||
}
|
||||
|
||||
void Start()
|
||||
@@ -47,11 +48,24 @@ namespace BrewMonster.UI
|
||||
_loginButton.onClick.AddListener(OnLoginButtonClicked);
|
||||
context = SynchronizationContext.Current;
|
||||
|
||||
// Requirement: Login UI should also have a61 loaded.
|
||||
var world = SceneManager.GetSceneByName("a61");
|
||||
if (!world.IsValid() || !world.isLoaded)
|
||||
{
|
||||
SceneManager.LoadSceneAsync("a61", LoadSceneMode.Additive);
|
||||
}
|
||||
|
||||
_usernameInputField.text = PlayerPrefs.GetString("username", "");
|
||||
_passwordInputField.text = PlayerPrefs.GetString("password", "");
|
||||
|
||||
// Default: login UI first, select-role hidden until login succeeds.
|
||||
if (_selectCharacterScreen != null)
|
||||
_selectCharacterScreen.gameObject.SetActive(false);
|
||||
|
||||
Tech3CSDKWrapper.Instance.SetLoginCallback(OnLoginCallback);
|
||||
Tech3CSDKWrapper.Instance.SetLogoutCallback(OnLogoutCallback);
|
||||
|
||||
ApplyLoginEntry(BrewMonster.Network.LogoutFlowState.ConsumeNextLoginEntry());
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -88,7 +102,72 @@ namespace BrewMonster.UI
|
||||
|
||||
public async void OnLoginButtonClicked()
|
||||
{
|
||||
Tech3CSDKWrapper.Instance.Login();
|
||||
if (_loginInProgress)
|
||||
{
|
||||
BMLogger.LogWarning("[LoginScreenUI] Login already in progress (ignored click).");
|
||||
return;
|
||||
}
|
||||
|
||||
_loginInProgress = true;
|
||||
if (_loginButton != null) _loginButton.interactable = false;
|
||||
|
||||
// Use Tech3C SDK login UI.
|
||||
bool started = Tech3CSDKWrapper.Instance.Login();
|
||||
if (!started)
|
||||
{
|
||||
// Fallback: manual username/password login (useful in dev if SDK not configured).
|
||||
BMLogger.LogWarning("[LoginScreenUI] Tech3CSDKWrapper.Login() failed, fallback to manual login.");
|
||||
await BeginGameLoginAsync(_usernameInputField.text, _passwordInputField.text);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BeginGameLoginAsync(string username, string password)
|
||||
{
|
||||
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
BMLogger.LogError("[LoginScreenUI] Username/password empty.");
|
||||
_loginInProgress = false;
|
||||
if (_loginButton != null) _loginButton.interactable = true;
|
||||
return;
|
||||
}
|
||||
|
||||
BMLogger.Log("OnLoginButtonClicked");
|
||||
UnityGameSession.SetConnectionInfo("103.51.120.195", 29000);
|
||||
PlayerPrefs.SetString("username", username);
|
||||
PlayerPrefs.SetString("password", password);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
BMLogger.Log($"[LoginScreenUI] Connecting+login start user='{username}'");
|
||||
await UnityGameSession.Login(username, password, OnLoginComplete);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply how LoginScene should look after a logout flow.
|
||||
/// Call this when LoginScene is already loaded (additive) and you need to switch UI without reloading the scene.
|
||||
/// </summary>
|
||||
public void ApplyLoginEntry(BrewMonster.Network.LogoutFlowState.LoginEntryTarget entry)
|
||||
{
|
||||
_loginInProgress = false;
|
||||
if (_loginButton != null) _loginButton.interactable = true;
|
||||
|
||||
// Always refresh fields from PlayerPrefs (LogoutAccount clears them).
|
||||
if (_usernameInputField != null) _usernameInputField.text = PlayerPrefs.GetString("username", "");
|
||||
if (_passwordInputField != null) _passwordInputField.text = PlayerPrefs.GetString("password", "");
|
||||
|
||||
if (_selectCharacterScreen != null)
|
||||
_selectCharacterScreen.gameObject.SetActive(false);
|
||||
|
||||
if (entry == BrewMonster.Network.LogoutFlowState.LoginEntryTarget.SelectRole)
|
||||
{
|
||||
// Auto-login to reach Select Role like the original client, without showing Tech3C auth UI again.
|
||||
if (!string.IsNullOrEmpty(_usernameInputField.text) && !string.IsNullOrEmpty(_passwordInputField.text))
|
||||
{
|
||||
BMLogger.Log("[LoginScreenUI] Auto-login triggered (return-to-select-role).");
|
||||
_loginInProgress = true;
|
||||
if (_loginButton != null) _loginButton.interactable = false;
|
||||
_ = BeginGameLoginAsync(_usernameInputField.text, _passwordInputField.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -97,6 +176,7 @@ namespace BrewMonster.UI
|
||||
/// </summary>
|
||||
private void OnLoginComplete(bool result)
|
||||
{
|
||||
BMLogger.Log($"[LoginScreenUI] OnLoginComplete result={result}");
|
||||
if (!result)
|
||||
{
|
||||
BMLogger.LogError("Login failed");
|
||||
@@ -308,13 +388,14 @@ namespace BrewMonster.UI
|
||||
PlayerPrefs.SetString("username", userId);
|
||||
PlayerPrefs.SetString("password", password);
|
||||
PlayerPrefs.Save();
|
||||
await UnityGameSession.Login(userId, password, OnLoginComplete);
|
||||
_selectCharacterScreen.gameObject.SetActive(true);
|
||||
await BeginGameLoginAsync(userId, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if it failed, the userId will be the error message
|
||||
BMLogger.LogError($"Login failed -- errorCode: {errorCode}: {userId}");
|
||||
_loginInProgress = false;
|
||||
if (_loginButton != null) _loginButton.interactable = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user