diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs
index 6ad6609e25..3a62ec2852 100644
--- a/OpenSim/Data/MySQL/MySQLManager.cs
+++ b/OpenSim/Data/MySQL/MySQLManager.cs
@@ -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;
+ }
+
///
/// Inserts a new row into the log database
///
@@ -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();
+ }
+ }
}
}
diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs
index f77d94740e..627bc0cf8d 100644
--- a/OpenSim/Data/MySQL/MySQLUserData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserData.cs
@@ -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);
+ }
}
}
diff --git a/OpenSim/Data/MySQL/Resources/005_UserStore.sql b/OpenSim/Data/MySQL/Resources/005_UserStore.sql
new file mode 100644
index 0000000000..55896bc9a0
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/005_UserStore.sql
@@ -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;
diff --git a/OpenSim/Data/SQLite/Resources/005_UserStore.sql b/OpenSim/Data/SQLite/Resources/005_UserStore.sql
new file mode 100644
index 0000000000..e45c09a493
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/005_UserStore.sql
@@ -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;
diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs
index 3133f83b5d..1c086d57d4 100644
--- a/OpenSim/Framework/AvatarAppearance.cs
+++ b/OpenSim/Framework/AvatarAppearance.cs
@@ -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 m_attachments = new Dictionary();
+
+ 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 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 GetAttachedPoints()
+ {
+ return new List(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;
+ }
}
}