Plumbs in attachment persistence and adds the tables. Currently MySQL only, no user functionality yet.0.6.0-stable
							parent
							
								
									ae3a1dd9a2
								
							
						
					
					
						commit
						05506cff49
					
				| 
						 | 
				
			
			@ -27,6 +27,7 @@
 | 
			
		|||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
| 
						 | 
				
			
			@ -660,6 +661,26 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        // Read attachment list from data reader
 | 
			
		||||
        public Hashtable readAttachments(IDataReader r)
 | 
			
		||||
        {
 | 
			
		||||
            Hashtable ret = new Hashtable();
 | 
			
		||||
 | 
			
		||||
            while(r.Read())
 | 
			
		||||
            {
 | 
			
		||||
                int attachpoint = Convert.ToInt32(r["attachpoint"]);
 | 
			
		||||
                if(ret.ContainsKey(attachpoint))
 | 
			
		||||
                    continue;
 | 
			
		||||
                Hashtable item = new Hashtable();
 | 
			
		||||
                item.Add("item", r["item"].ToString());
 | 
			
		||||
                item.Add("asset", r["asset"].ToString());
 | 
			
		||||
 | 
			
		||||
                ret.Add(attachpoint, item);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Inserts a new row into the log database
 | 
			
		||||
        /// </summary>
 | 
			
		||||
| 
						 | 
				
			
			@ -1176,5 +1197,35 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void writeAttachments(LLUUID agentID, Hashtable data)
 | 
			
		||||
        {
 | 
			
		||||
            string sql = "delete from avatarattachments where UUID = ?uuid";
 | 
			
		||||
 | 
			
		||||
            MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand();
 | 
			
		||||
            cmd.CommandText = sql;
 | 
			
		||||
            cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
 | 
			
		||||
            
 | 
			
		||||
            cmd.ExecuteNonQuery();
 | 
			
		||||
 | 
			
		||||
            sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attchpoint, ?item, ?asset)";
 | 
			
		||||
 | 
			
		||||
            cmd = (MySqlCommand) dbcon.CreateCommand();
 | 
			
		||||
            cmd.CommandText = sql;
 | 
			
		||||
 | 
			
		||||
            foreach(DictionaryEntry e in data)
 | 
			
		||||
            {
 | 
			
		||||
                int attachpoint = Convert.ToInt32(e.Key);
 | 
			
		||||
 | 
			
		||||
                Hashtable item = (Hashtable)e.Value;
 | 
			
		||||
 | 
			
		||||
                cmd.Parameters.Clear();
 | 
			
		||||
                cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
 | 
			
		||||
                cmd.Parameters.AddWithValue("?attachpoint", attachpoint);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?item",  item["item"]);
 | 
			
		||||
                cmd.Parameters.AddWithValue("?asset", item["asset"]);
 | 
			
		||||
 | 
			
		||||
                cmd.ExecuteNonQuery();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Data;
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +35,7 @@ using libsecondlife;
 | 
			
		|||
using log4net;
 | 
			
		||||
using OpenSim.Framework;
 | 
			
		||||
using OpenSim.Data.Base;
 | 
			
		||||
using MySql.Data.MySqlClient;
 | 
			
		||||
 | 
			
		||||
namespace OpenSim.Data.MySQL
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -737,6 +739,8 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
                    reader.Dispose();
 | 
			
		||||
                    result.Dispose();
 | 
			
		||||
 | 
			
		||||
                    appearance.SetAttachments(GetUserAttachments(user));
 | 
			
		||||
 | 
			
		||||
                    return appearance;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -762,6 +766,8 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
                {
 | 
			
		||||
                    appearance.Owner = user;
 | 
			
		||||
                    database.insertAppearanceRow(appearance);
 | 
			
		||||
 | 
			
		||||
                    UpdateUserAttachments(user, appearance.GetAttachments());
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception e)
 | 
			
		||||
| 
						 | 
				
			
			@ -818,5 +824,24 @@ namespace OpenSim.Data.MySQL
 | 
			
		|||
        {
 | 
			
		||||
            get {return "0.1";}
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Hashtable GetUserAttachments(LLUUID agentID)
 | 
			
		||||
        {
 | 
			
		||||
            MySqlCommand cmd = (MySqlCommand) (database.Connection.CreateCommand());
 | 
			
		||||
            cmd.CommandText = "select attachpoint, item, asset from avatarattachments where UUID = ?uuid";
 | 
			
		||||
            cmd.Parameters.AddWithValue("?uuid", agentID.ToString());
 | 
			
		||||
 | 
			
		||||
            IDataReader r = cmd.ExecuteReader();
 | 
			
		||||
 | 
			
		||||
            return database.readAttachments(r);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void UpdateUserAttachments(LLUUID agentID, Hashtable data)
 | 
			
		||||
        {
 | 
			
		||||
            if(data == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            database.writeAttachments(agentID, data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
BEGIN;
 | 
			
		||||
 | 
			
		||||
CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL, `attachpoint` int(11) NOT NULL, `item` char(36) NOT NULL, `asset` char(36) NOT NULL) ENGINE=InnoDB;
 | 
			
		||||
 | 
			
		||||
COMMIT;
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
BEGIN;
 | 
			
		||||
 | 
			
		||||
CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `attachpoint` int(11) NOT NULL DEFAULT 0, `item` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `asset` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000');
 | 
			
		||||
 | 
			
		||||
COMMIT;
 | 
			
		||||
| 
						 | 
				
			
			@ -361,6 +361,11 @@ namespace OpenSim.Framework
 | 
			
		|||
            h["underpants_asset"] = UnderPantsAsset.ToString();
 | 
			
		||||
            h["skirt_item"] = SkirtItem.ToString();
 | 
			
		||||
            h["skirt_asset"] = SkirtAsset.ToString();
 | 
			
		||||
 | 
			
		||||
            Hashtable attachments = GetAttachments();
 | 
			
		||||
            if(attachments != null)
 | 
			
		||||
                h["attachments"] = attachments;
 | 
			
		||||
 | 
			
		||||
            return h;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -405,6 +410,12 @@ namespace OpenSim.Framework
 | 
			
		|||
            UnderPantsAsset = new LLUUID((string)h["underpants_asset"]);
 | 
			
		||||
            SkirtItem = new LLUUID((string)h["skirt_item"]);
 | 
			
		||||
            SkirtAsset = new LLUUID((string)h["skirt_asset"]);
 | 
			
		||||
 | 
			
		||||
            if(h.ContainsKey("attachments"))
 | 
			
		||||
            {
 | 
			
		||||
                Hashtable attachments = (Hashtable) h["attachments"];
 | 
			
		||||
                SetAttachments(attachments);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [SecurityPermission(SecurityAction.LinkDemand,
 | 
			
		||||
| 
						 | 
				
			
			@ -424,5 +435,95 @@ namespace OpenSim.Framework
 | 
			
		|||
            info.AddValue("m_textureEntry", m_texture.ToBytes());
 | 
			
		||||
            info.AddValue("m_avatarHeight", m_avatarHeight);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private Dictionary<int, LLUUID[]> m_attachments = new Dictionary<int, LLUUID[]>();
 | 
			
		||||
 | 
			
		||||
        public void SetAttachments(Hashtable data)
 | 
			
		||||
        {
 | 
			
		||||
            m_attachments.Clear();
 | 
			
		||||
 | 
			
		||||
            if(data == null)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            foreach (DictionaryEntry e in data)
 | 
			
		||||
            {
 | 
			
		||||
                int attachpoint = Convert.ToInt32(e.Key);
 | 
			
		||||
 | 
			
		||||
                if (m_attachments.ContainsKey(attachpoint))
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                LLUUID item;
 | 
			
		||||
                LLUUID asset;
 | 
			
		||||
 | 
			
		||||
                Hashtable uuids = (Hashtable) e.Value;
 | 
			
		||||
                LLUUID.TryParse(uuids["item"].ToString(), out item);
 | 
			
		||||
                LLUUID.TryParse(uuids["asset"].ToString(), out asset);
 | 
			
		||||
 | 
			
		||||
                LLUUID[] attachment = new LLUUID[2];
 | 
			
		||||
                attachment[0] = item;
 | 
			
		||||
                attachment[1] = asset;
 | 
			
		||||
 | 
			
		||||
                m_attachments[attachpoint] = attachment;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public Hashtable GetAttachments()
 | 
			
		||||
        {
 | 
			
		||||
            if(m_attachments.Count == 0)
 | 
			
		||||
                return null;
 | 
			
		||||
 | 
			
		||||
            Hashtable ret = new Hashtable();
 | 
			
		||||
 | 
			
		||||
            foreach (KeyValuePair<int, LLUUID[]> kvp in m_attachments)
 | 
			
		||||
            {
 | 
			
		||||
                int attachpoint = kvp.Key;
 | 
			
		||||
                LLUUID[] uuids = kvp.Value;
 | 
			
		||||
 | 
			
		||||
                Hashtable data = new Hashtable();
 | 
			
		||||
                data["item"] = uuids[0].ToString();
 | 
			
		||||
                data["asset"] = uuids[1].ToString();
 | 
			
		||||
 | 
			
		||||
                ret[attachpoint] = data;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public List<int> GetAttachedPoints()
 | 
			
		||||
        {
 | 
			
		||||
            return new List<int>(m_attachments.Keys);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public LLUUID GetAttachedItem(int attachpoint)
 | 
			
		||||
        {
 | 
			
		||||
            if (!m_attachments.ContainsKey(attachpoint))
 | 
			
		||||
                return LLUUID.Zero;
 | 
			
		||||
 | 
			
		||||
            return m_attachments[attachpoint][0];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public LLUUID GetAttachedAsset(int attachpoint)
 | 
			
		||||
        {
 | 
			
		||||
            if (!m_attachments.ContainsKey(attachpoint))
 | 
			
		||||
                return LLUUID.Zero;
 | 
			
		||||
 | 
			
		||||
            return m_attachments[attachpoint][1];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void AddAttachment(int attachpoint, LLUUID item, LLUUID asset)
 | 
			
		||||
        {
 | 
			
		||||
            if (item == LLUUID.Zero || asset == LLUUID.Zero)
 | 
			
		||||
            {
 | 
			
		||||
                if (m_attachments.ContainsKey(attachpoint))
 | 
			
		||||
                    m_attachments.Remove(attachpoint);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!m_attachments.ContainsKey(attachpoint))
 | 
			
		||||
                m_attachments[attachpoint] = new LLUUID[2];
 | 
			
		||||
 | 
			
		||||
            m_attachments[attachpoint][0] = item;
 | 
			
		||||
            m_attachments[attachpoint][1] = asset;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue