diff --git a/OpenMetaverse.GUI/AvatarList.cs b/OpenMetaverse.GUI/AvatarList.cs index 2957270f..0eaa82b8 100644 --- a/OpenMetaverse.GUI/AvatarList.cs +++ b/OpenMetaverse.GUI/AvatarList.cs @@ -304,18 +304,17 @@ namespace OpenMetaverse.GUI private void Avatars_OnAvatarAppearance(UUID avatarID, bool isTrial, Primitive.TextureEntryFace defaultTexture, Primitive.TextureEntryFace[] faceTextures, List visualParams) { - if (visualParams.Count > 105) + if (visualParams.Count > 80) { lock (_TrackedAvatars) { TrackedAvatar trackedAvatar; if (_TrackedAvatars.TryGetValue(avatarID, out trackedAvatar)) - { - + { this.BeginInvoke((MethodInvoker)delegate { byte param = visualParams[80]; - if (param > 117) + if (param > 93) trackedAvatar.ListViewItem.ForeColor = Color.Blue; else trackedAvatar.ListViewItem.ForeColor = Color.Magenta; diff --git a/OpenMetaverse.GUI/InventoryTree.cs b/OpenMetaverse.GUI/InventoryTree.cs index 02b4c2cf..cfef7048 100644 --- a/OpenMetaverse.GUI/InventoryTree.cs +++ b/OpenMetaverse.GUI/InventoryTree.cs @@ -155,7 +155,10 @@ namespace OpenMetaverse.GUI void Network_OnLogin(LoginStatus login, string message) { if (login == LoginStatus.Success) - UpdateFolder(Client.Inventory.Store.RootFolder.UUID); + { + if (Client.Inventory.Store != null) + UpdateFolder(Client.Inventory.Store.RootFolder.UUID); + } } void Inventory_OnFolderUpdated(UUID folderID) diff --git a/OpenMetaverse.GUI/LoginPanel.cs b/OpenMetaverse.GUI/LoginPanel.cs new file mode 100644 index 00000000..7603f7d7 --- /dev/null +++ b/OpenMetaverse.GUI/LoginPanel.cs @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2007-2009, openmetaverse.org + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.org nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; + +namespace OpenMetaverse.GUI +{ + public class LoginPanel : Panel + { + private GridClient _Client; + private LoginParams _LoginParams = new LoginParams(); + private Dictionary _Accounts = new Dictionary(); + private Button btnLogin = new Button(); + private Label label1 = new Label(); + private Label label2 = new Label(); + private Label label3 = new Label(); + private ComboBox listNames = new ComboBox(); + private ComboBox listStart = new ComboBox(); + private TextBox txtPass = new TextBox(); + + /// + /// Gets or sets the GridClient associated with this control + /// + public GridClient Client + { + get { return _Client; } + set { if (value != null) InitializeClient(value); } + } + + /// + /// Gets or sets the LoginParams associated with this control's GridClient object + /// + public LoginParams LoginParams + { + get { return _LoginParams; } + set { _LoginParams = value; } + } + + /// + /// First name parsed from the textbox control + /// + public string FirstName + { + get + { + string[] names = listNames.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); + return names.Length > 0 ? names[0] : String.Empty; + } + } + + /// + /// Last name parsed from the textbox control + /// + public string LastName + { + get + { + string[] names = listNames.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); + return names.Length > 1 ? names[1] : String.Empty; + } + } + + /// + /// Password value returned from the textbox control + /// + public string Password + { + get { return txtPass.Text; } + } + + /// + /// Complete start URI based on textbox value + /// + public string StartURI + { + get + { + if (listStart.Text == String.Empty) + return "last"; + + if (listStart.Text == "Last" || listStart.Text == "Home") + return listStart.Text.ToLower(); + + else + { + string[] start = listStart.Text.Split(new char[] { '/' }); + int x; int y; int z; + + if (start.Length < 2 || int.TryParse(start[1], out x)) x = 128; + if (start.Length < 3 || int.TryParse(start[2], out y)) y = 128; + if (start.Length < 4 || int.TryParse(start[3], out z)) z = 0; + + return NetworkManager.StartLocation(start[0], x, y, z); + } + } + } + + + /// + /// Panel control for an unspecified client's login preferences + /// + public LoginPanel() + { + btnLogin.Text = "Login"; + btnLogin.Size = new Size(50, 23); + btnLogin.Location = new Point(6, 7); + btnLogin.TabIndex = 0; + + label1.Text = "Name:"; + label1.AutoSize = true; + label1.Location = new Point(60, 12); + + label2.Text = "Pass:"; + label2.AutoSize = true; + label2.Location = new Point(266, 12); + + label3.Text = "Start:"; + label3.AutoSize = true; + label3.Location = new Point(428, 12); + + listNames.Location = new Point(100, 8); + listNames.Size = new Size(160, 18); + listNames.TabIndex = 1; + listNames.SelectedIndexChanged += new EventHandler(listNames_SelectedIndexChanged); + + txtPass.Location = new Point(302, 8); + txtPass.PasswordChar = '*'; + txtPass.Size = new Size(120, 18); + txtPass.TabIndex = 2; + + listStart.Items.Add("Last"); + listStart.Items.Add("Home"); + listStart.SelectedIndex = 0; + listStart.Location = new Point(463, 8); + listStart.Size = new Size(120, 18); + listStart.TabIndex = 3; + + this.Dock = DockStyle.Top; + this.Height = 50; + + this.Controls.Add(btnLogin); + this.Controls.Add(label1); + this.Controls.Add(label2); + this.Controls.Add(label3); + this.Controls.Add(listNames); + this.Controls.Add(listStart); + this.Controls.Add(txtPass); + + btnLogin.Click += new EventHandler(btnLogin_Click); + } + + private void InitializeClient(GridClient client) + { + _Client = client; + + _Client.Network.OnDisconnected += new NetworkManager.DisconnectedCallback(Network_OnDisconnected); + _Client.Network.OnLogin += new NetworkManager.LoginCallback(Network_OnLogin); + } + + private void btnLogin_Click(object sender, EventArgs e) + { + if (btnLogin.Text == "Login") + { + if (FirstName == String.Empty || LastName == String.Empty) + { + MessageBox.Show("Please enter a valid first and last name.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + return; + } + + btnLogin.Text = "Logout"; + + _LoginParams.FirstName = FirstName; + _LoginParams.LastName = LastName; + _LoginParams.Password = Password; + _LoginParams.Start = StartURI; + + _Client.Network.BeginLogin(_LoginParams); + } + else if (btnLogin.Text == "Logout") + { + if (_Client != null) + { + if (_Client.Network.Connected) + _Client.Network.Logout(); + } + + btnLogin.Text = "Login"; + } + } + + private void listNames_SelectedIndexChanged(object sender, EventArgs e) + { + if (listNames.SelectedIndex > -1) + { + lock (_Accounts) + { + string pass; + if (_Accounts.TryGetValue(listNames.Text, out pass)) + txtPass.Text = pass; + } + } + else txtPass.Text = String.Empty; + } + + private void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message) + { + this.BeginInvoke((MethodInvoker)delegate + { + btnLogin.Text = "Login"; + }); + } + + private void Network_OnLogin(LoginStatus login, string message) + { + if (login == LoginStatus.Success) + { + lock (_Accounts) + { + _Accounts[_Client.Self.Name] = _LoginParams.Password; + + if (!listNames.Items.Contains(_Client.Self.Name)) + { + this.BeginInvoke((MethodInvoker)delegate + { + listNames.Items.Add(_Client.Self.Name); + }); + } + } + } + else if (login == LoginStatus.Failed) + { + this.BeginInvoke((MethodInvoker)delegate + { + btnLogin.Text = "Login"; + + if (MessageBox.Show(this, "Login failed. Try again?", "Login", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) + { + Client.Network.BeginLogin(_LoginParams); + } + }); + } + } + + } +} diff --git a/OpenMetaverse.GUI/StatusOutput.cs b/OpenMetaverse.GUI/StatusOutput.cs index b59b33cc..3e9e2c14 100644 --- a/OpenMetaverse.GUI/StatusOutput.cs +++ b/OpenMetaverse.GUI/StatusOutput.cs @@ -88,7 +88,10 @@ namespace OpenMetaverse.GUI void Network_OnCurrentSimChanged(Simulator PreviousSimulator) { - LogText("Entered region \"" + Client.Network.CurrentSim.Name + "\".", Color.Black); + if (Client.Network.CurrentSim != null) + { + LogText("Entered region \"" + Client.Network.CurrentSim.Name + "\".", Color.Black); + } } void Network_OnDisconnected(NetworkManager.DisconnectType reason, string message)