Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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;
        }