private void SaveConfig() { Settings s = instance.GlobalSettings; SavedLogin sl = new SavedLogin(); string username = cbxUsername.Text; if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin) { username = ((SavedLogin)cbxUsername.SelectedItem).Username; } if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri { sl.GridID = "custom_login_uri"; sl.CustomURI = txtCustomLoginUri.Text; } else { sl.GridID = (cbxGrid.SelectedItem as Grid).ID; sl.CustomURI = string.Empty; } string savedLoginsKey = string.Format("{0}%{1}", username, sl.GridID); if (!(s["saved_logins"] is OSDMap)) { s["saved_logins"] = new OSDMap(); } if (cbRemember.Checked) { sl.Username = s["username"] = username; if (LoginOptions.IsPasswordMD5(txtPassword.Text)) { sl.Password = txtPassword.Text; s["password"] = txtPassword.Text; } else { sl.Password = Utils.MD5(txtPassword.Text); s["password"] = Utils.MD5(txtPassword.Text); } if (cbxLocation.SelectedIndex == -1) { sl.CustomStartLocation = cbxLocation.Text; } else { sl.CustomStartLocation = string.Empty; } sl.StartLocationType = cbxLocation.SelectedIndex; ((OSDMap)s["saved_logins"])[savedLoginsKey] = sl.ToOSD(); } else if (((OSDMap)s["saved_logins"]).ContainsKey(savedLoginsKey)) { ((OSDMap)s["saved_logins"]).Remove(savedLoginsKey); } s["login_location_type"] = OSD.FromInteger(cbxLocation.SelectedIndex); s["login_location"] = OSD.FromString(cbxLocation.Text); s["login_grid"] = OSD.FromInteger(cbxGrid.SelectedIndex); s["login_uri"] = OSD.FromString(txtCustomLoginUri.Text); s["remember_login"] = cbRemember.Checked; }
public void Login() { IsLoggingIn = true; // Report crashes only once and not on relogs/reconnects LastExecStatus execStatus = instance.GetLastExecStatus(); if (!instance.AnotherInstanceRunning() && execStatus != LastExecStatus.Normal && (!instance.ReportedCrash)) { instance.ReportedCrash = true; loginOptions.LastExecEvent = execStatus; Logger.Log("Reporting crash of the last application run to the grid login service", Helpers.LogLevel.Warning); } else { loginOptions.LastExecEvent = LastExecStatus.Normal; Logger.Log("Reporting normal shutdown of the last application run to the grid login service", Helpers.LogLevel.Info); } instance.MarkStartExecution(); OverrideEventArgs ea = new OverrideEventArgs(); OnClientLoggingIn(ea); if (ea.Cancel) { IsLoggingIn = false; return; } if (string.IsNullOrEmpty(loginOptions.FirstName) || string.IsNullOrEmpty(loginOptions.LastName) || string.IsNullOrEmpty(loginOptions.Password)) { OnClientLoginStatus( new LoginProgressEventArgs(LoginStatus.Failed, "One or more fields are blank.", string.Empty)); } string startLocation = string.Empty; string loginLocation = string.Empty; switch (loginOptions.StartLocation) { case StartLocationType.Home: startLocation = "home"; break; case StartLocationType.Last: startLocation = "last"; break; case StartLocationType.Custom: var parser = new LocationParser(loginOptions.StartLocationCustom.Trim()); startLocation = parser.GetStartLocationUri(); break; } string password; if (LoginOptions.IsPasswordMD5(loginOptions.Password)) { password = loginOptions.Password; } else { password = Utils.MD5(loginOptions.Password.Length > 16 ? loginOptions.Password.Substring(0, 16) : loginOptions.Password); } LoginParams loginParams = client.Network.DefaultLoginParams( loginOptions.FirstName, loginOptions.LastName, password, loginOptions.Channel, loginOptions.Version); Grid = loginOptions.Grid; loginParams.Start = startLocation; loginParams.LoginLocation = loginLocation; loginParams.AgreeToTos = AgreeToTos; loginParams.URI = Grid.LoginURI; loginParams.LastExecEvent = loginOptions.LastExecEvent; loginParams.MfaEnabled = true; loginParams.MfaHash = loginOptions.MfaHash; loginParams.Token = loginOptions.MfaToken; client.Network.BeginLogin(loginParams); }
private void SaveConfig() { var globalSettings = instance.GlobalSettings; var savedLogin = new SavedLogin(); var username = cbxUsername.Text; var passTxt = txtPassword.Text; if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin login) { username = login.Username; } if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri { savedLogin.GridID = "custom_login_uri"; savedLogin.CustomURI = txtCustomLoginUri.Text; } else { savedLogin.GridID = (cbxGrid.SelectedItem as Grid)?.ID; savedLogin.CustomURI = string.Empty; } var savedLoginsKey = $"{username}%{savedLogin.GridID}"; if (!(globalSettings["saved_logins"] is OSDMap)) { globalSettings["saved_logins"] = new OSDMap(); } if (cbRemember.Checked) { savedLogin.Username = globalSettings["username"] = username; if (LoginOptions.IsPasswordMD5(passTxt)) { savedLogin.Password = passTxt; globalSettings["password"] = passTxt; } else { var passwd = Utils.MD5(passTxt.Length > 16 ? passTxt.Substring(0, 16) : passTxt); savedLogin.Password = passwd; globalSettings["password"] = passwd; } savedLogin.CustomStartLocation = cbxLocation.SelectedIndex == -1 ? cbxLocation.Text : string.Empty; savedLogin.StartLocationType = cbxLocation.SelectedIndex; var savedLogins = (OSDMap)globalSettings["saved_logins"]; if (savedLogins.ContainsKey(savedLoginsKey)) { var sl = SavedLogin.FromOSD(savedLogins[savedLoginsKey]); if (!string.IsNullOrWhiteSpace(sl.MfaHash)) { savedLogin.MfaHash = sl.MfaHash; } } ((OSDMap)globalSettings["saved_logins"])[savedLoginsKey] = savedLogin.ToOSD(); } else if (((OSDMap)globalSettings["saved_logins"]).ContainsKey(savedLoginsKey)) { ((OSDMap)globalSettings["saved_logins"]).Remove(savedLoginsKey); } globalSettings["login_location_type"] = OSD.FromInteger(cbxLocation.SelectedIndex); globalSettings["login_location"] = OSD.FromString(cbxLocation.Text); globalSettings["login_grid"] = OSD.FromString(savedLogin.GridID); globalSettings["login_grid_idx"] = OSD.FromInteger(cbxGrid.SelectedIndex); globalSettings["login_uri"] = OSD.FromString(txtCustomLoginUri.Text); globalSettings["remember_login"] = cbRemember.Checked; }