public static SavedLogin FromOSD(OSD data) { if (!(data is OSDMap osd)) { return(null); } SavedLogin ret = new SavedLogin { Username = osd["username"], Password = osd["password"], GridID = osd["grid"], CustomURI = osd["custom_url"] }; if (osd.ContainsKey("mfa_hash")) { ret.MfaHash = osd["mfa_hash"]; } if (osd.ContainsKey("location_type")) { ret.StartLocationType = osd["location_type"]; } else { ret.StartLocationType = 1; } ret.CustomStartLocation = osd["custom_location"]; return(ret); }
public static SavedLogin FromOSD(OSD data) { if (!(data is OSDMap)) { return(null); } OSDMap map = (OSDMap)data; SavedLogin ret = new SavedLogin { Username = map["username"], Password = map["password"], GridID = map["grid"], CustomURI = map["custom_url"] }; if (map.ContainsKey("location_type")) { ret.StartLocationType = map["location_type"]; } else { ret.StartLocationType = 1; } ret.CustomStartLocation = map["custom_location"]; return(ret); }
private void cbxUsername_SelectedIndexChanged(object sender, EventArgs e) { cbxUsername.SelectedIndexChanged -= cbxUsername_SelectedIndexChanged; if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin) { SavedLogin sl = (SavedLogin)cbxUsername.SelectedItem; cbxUsername.Text = sl.Username; cbxUsername.Items[0] = sl.Username; cbxUsername.SelectedIndex = 0; txtPassword.Text = sl.Password; cbxLocation.SelectedIndex = sl.StartLocationType; if (sl.StartLocationType == -1) { cbxLocation.Text = sl.CustomStartLocation; } if (sl.GridID == "custom_login_uri") { cbxGrid.SelectedIndex = cbxGrid.Items.Count - 1; txtCustomLoginUri.Text = sl.CustomURI; } else { foreach (var item in cbxGrid.Items) { if (item is Grid && ((Grid)item).ID == sl.GridID) { cbxGrid.SelectedItem = item; break; } } } } cbxUsername.SelectedIndexChanged += cbxUsername_SelectedIndexChanged; }
public static SavedLogin FromOSD(OSD data) { if (!(data is OSDMap)) return null; OSDMap map = (OSDMap)data; SavedLogin ret = new SavedLogin(); ret.Username = map["username"]; ret.Password = map["password"]; ret.GridID = map["grid"]; ret.CustomURI = map["custom_url"]; if (map.ContainsKey("location_type")) { ret.StartLocationType = map["location_type"]; } else { ret.StartLocationType = 1; } ret.CustomStartLocation = map["custom_location"]; return ret; }
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; }
private void InitializeConfig() { // Initilize grid dropdown int gridIx = -1; cbxGrid.Items.Clear(); for (int i = 0; i < instance.GridManger.Count; i++) { cbxGrid.Items.Add(instance.GridManger[i]); if (MainProgram.CommandLine.Grid == instance.GridManger[i].ID) { gridIx = i; } } cbxGrid.Items.Add("Custom"); if (gridIx != -1) { cbxGrid.SelectedIndex = gridIx; } Settings s = instance.GlobalSettings; cbRemember.Checked = s["remember_login"]; // Setup login name string savedUsername; if (string.IsNullOrEmpty(MainProgram.CommandLine.Username)) { savedUsername = s["username"]; } else { savedUsername = MainProgram.CommandLine.Username; } cbxUsername.Items.Add(savedUsername); try { if (s["saved_logins"] is OSDMap) { OSDMap savedLogins = (OSDMap)s["saved_logins"]; foreach (string loginKey in savedLogins.Keys) { SavedLogin sl = SavedLogin.FromOSD(savedLogins[loginKey]); cbxUsername.Items.Add(sl); } } } catch { cbxUsername.Items.Clear(); cbxUsername.Text = string.Empty; } cbxUsername.SelectedIndex = 0; // Fill in saved password or use one specified on the command line if (string.IsNullOrEmpty(MainProgram.CommandLine.Password)) { txtPassword.Text = s["password"].AsString(); } else { txtPassword.Text = MainProgram.CommandLine.Password; } // Setup login location either from the last used or // override from the command line if (string.IsNullOrEmpty(MainProgram.CommandLine.Location)) { // Use last location as default if (s["login_location_type"].Type == OSDType.Unknown) { cbxLocation.SelectedIndex = 1; s["login_location_type"] = OSD.FromInteger(1); } else { cbxLocation.SelectedIndex = s["login_location_type"].AsInteger(); cbxLocation.Text = s["login_location"].AsString(); } } else { switch (MainProgram.CommandLine.Location) { case "home": cbxLocation.SelectedIndex = 0; break; case "last": cbxLocation.SelectedIndex = 1; break; default: cbxLocation.SelectedIndex = -1; cbxLocation.Text = MainProgram.CommandLine.Location; break; } } // Set grid dropdown to last used, or override from command line if (string.IsNullOrEmpty(MainProgram.CommandLine.Grid)) { cbxGrid.SelectedIndex = s["login_grid"].AsInteger(); } else if (gridIx == -1) // --grid specified but not found { MessageBox.Show(string.Format("Grid specified with --grid {0} not found", MainProgram.CommandLine.Grid), "Grid not found", MessageBoxButtons.OK, MessageBoxIcon.Warning ); } // Restore login uri from settings, or command line if (string.IsNullOrEmpty(MainProgram.CommandLine.LoginUri)) { txtCustomLoginUri.Text = s["login_uri"].AsString(); } else { txtCustomLoginUri.Text = MainProgram.CommandLine.LoginUri; cbxGrid.SelectedIndex = cbxGrid.Items.Count - 1; } // Start logging in if autologin enabled from command line if (MainProgram.CommandLine.AutoLogin) { BeginLogin(); } }
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; }
private void BeginLogin() { string username = cbxUsername.Text; if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin login) { username = login.Username; netcom.loginOptions.MfaHash = login.MfaHash; } string[] parts = System.Text.RegularExpressions.Regex.Split(username.Trim(), @"[. ]+"); if (parts.Length == 2) { netcom.LoginOptions.FirstName = parts[0]; netcom.LoginOptions.LastName = parts[1]; } else { netcom.LoginOptions.FirstName = username.Trim(); netcom.LoginOptions.LastName = "Resident"; } netcom.LoginOptions.Password = txtPassword.Text; netcom.LoginOptions.Channel = Properties.Resources.ProgramName; // Channel netcom.LoginOptions.Version = Properties.Resources.RadegastTitle; // Version netcom.AgreeToTos = cbTOS.Checked; switch (cbxLocation.SelectedIndex) { case -1: //Custom netcom.LoginOptions.StartLocation = StartLocationType.Custom; netcom.LoginOptions.StartLocationCustom = cbxLocation.Text; break; case 0: //Home netcom.LoginOptions.StartLocation = StartLocationType.Home; break; case 1: //Last netcom.LoginOptions.StartLocation = StartLocationType.Last; break; } if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri { if (txtCustomLoginUri.TextLength == 0 || txtCustomLoginUri.Text.Trim().Length == 0) { MessageBox.Show("You must specify the Login Uri to connect to a custom grid.", Properties.Resources.ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } netcom.LoginOptions.Grid = new Grid("custom", "Custom", txtCustomLoginUri.Text); netcom.LoginOptions.GridCustomLoginUri = txtCustomLoginUri.Text; } else { netcom.LoginOptions.Grid = cbxGrid.SelectedItem as Grid; } if (instance.GlobalSettings.ContainsKey("saved_logins")) { var logins = (OSDMap)instance.GlobalSettings["saved_logins"]; var gridId = cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1 ? "custom_login_uri" : (cbxGrid.SelectedItem as Grid)?.ID; var savedLoginsKey = $"{username}%{gridId}"; if (logins.ContainsKey(savedLoginsKey)) { var sl = SavedLogin.FromOSD(logins[savedLoginsKey]); netcom.LoginOptions.MfaHash = sl.MfaHash; } } if (netcom.LoginOptions.Grid?.Platform != "SecondLife") { instance.Client.Settings.MULTIPLE_SIMS = true; } netcom.Login(); SaveConfig(); }
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; }