public void ActivateLogin() { ConnectionChecker connChecker = MainGameHandler.GetConnectionChecker(); if (connChecker == null) { MainGameHandler.ShowMessageBox("Login button handler - ActivateLogin() - no reference to connection checker!", "Critical error", null); return; } ConnectionChecker.LoginState loginState = connChecker.ClientLoginState; if (loginState == ConnectionChecker.LoginState.WaitingForResponse) { return; } string login = _loginInputField.text; string pass = _passInputField.text; if (String.IsNullOrWhiteSpace(login)) { MainGameHandler.ShowMessageBox("Your login cannot be empty!"); return; } connChecker.SetLoginState(ConnectionChecker.LoginState.WaitingForResponse); CommandHandler.Send(new LoginRequestCmdBuilder(login, pass)); }
public bool Execute() { bool executed = false; try { bool loginSuccess = false; string info = ""; ConnectionChecker connChecker = MainGameHandler.GetConnectionChecker(); if (_cmdElements.Length >= 2) { loginSuccess = _cmdElements[1].Equals("true", GlobalData.InputDataStringComparison); } if (_cmdElements.Length > 2) { for (int i = 2; i < _cmdElements.Length; i++) { if (i > 2) { info += ' '; } info += _cmdElements[i]; } } connChecker.SetLoginState(loginSuccess ? ConnectionChecker.LoginState.Logged : ConnectionChecker.LoginState.NotLoggedInOrLoginFailed); if (info.Length > 0) { MainGameHandler.ShowMessageBox(info, "Server login message", null); } executed = true; } catch (Exception exception) { MainGameHandler.ShowMessageBox($"Cannot execute login command: {exception.Message}", "Login error", null); } return(executed); }