From 6d2e1ad6ba73fb0eba51b3885ff0a4d7d1b5d611 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 19 Aug 2008 02:12:40 +0000 Subject: Attachment persistence!!! Patch #9169 (Mantis #1171) Attachments now save to MySQL. No reattach on login yet. --- OpenSim/Framework/AvatarAppearance.cs | 67 ++++++++++++++++++++-- OpenSim/Framework/Communications/IAvatarService.cs | 5 -- 2 files changed, 61 insertions(+), 11 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/AvatarAppearance.cs b/OpenSim/Framework/AvatarAppearance.cs index 1c086d5..67e26b1 100644 --- a/OpenSim/Framework/AvatarAppearance.cs +++ b/OpenSim/Framework/AvatarAppearance.cs @@ -362,8 +362,8 @@ namespace OpenSim.Framework h["skirt_item"] = SkirtItem.ToString(); h["skirt_asset"] = SkirtAsset.ToString(); - Hashtable attachments = GetAttachments(); - if(attachments != null) + string attachments = GetAttachmentsString(); + if(attachments != String.Empty) h["attachments"] = attachments; return h; @@ -413,8 +413,7 @@ namespace OpenSim.Framework if(h.ContainsKey("attachments")) { - Hashtable attachments = (Hashtable) h["attachments"]; - SetAttachments(attachments); + SetAttachmentsString(h["attachments"].ToString()); } } @@ -510,9 +509,12 @@ namespace OpenSim.Framework return m_attachments[attachpoint][1]; } - public void AddAttachment(int attachpoint, LLUUID item, LLUUID asset) + public void SetAttachment(int attachpoint, LLUUID item, LLUUID asset) { - if (item == LLUUID.Zero || asset == LLUUID.Zero) + if(attachpoint == 0) + return; + + if (item == LLUUID.Zero) { if (m_attachments.ContainsKey(attachpoint)) m_attachments.Remove(attachpoint); @@ -525,5 +527,58 @@ namespace OpenSim.Framework m_attachments[attachpoint][0] = item; m_attachments[attachpoint][1] = asset; } + + public void DetachAttachment(LLUUID itemID) + { + int attachpoint = 0; + + foreach (KeyValuePair kvp in m_attachments) + { + if(kvp.Value[0] == itemID) + { + attachpoint = kvp.Key; + break; + } + } + + if(attachpoint > 0) + m_attachments.Remove(attachpoint); + } + string GetAttachmentsString() + { + List strings = new List(); + + foreach (KeyValuePair e in m_attachments) + { + strings.Add(e.Key.ToString()); + strings.Add(e.Value[0].ToString()); + strings.Add(e.Value[1].ToString()); + } + + return String.Join(",", strings.ToArray()); + } + + void SetAttachmentsString(string data) + { + string[] strings = data.Split(new char[] {','}); + int i = 0; + + m_attachments.Clear(); + + while (strings.Length - i > 2) + { + int attachpoint = Int32.Parse(strings[i]); + LLUUID item = new LLUUID(strings[i+1]); + LLUUID asset = new LLUUID(strings[i+2]); + i += 3; + + if (!m_attachments.ContainsKey(attachpoint)) + { + m_attachments[attachpoint] = new LLUUID[2]; + m_attachments[attachpoint][0] = item; + m_attachments[attachpoint][1] = asset; + } + } + } } } diff --git a/OpenSim/Framework/Communications/IAvatarService.cs b/OpenSim/Framework/Communications/IAvatarService.cs index 0e4a349..6c033e1 100644 --- a/OpenSim/Framework/Communications/IAvatarService.cs +++ b/OpenSim/Framework/Communications/IAvatarService.cs @@ -39,10 +39,5 @@ namespace OpenSim.Framework.Communications void UpdateUserAppearance(LLUUID user, AvatarAppearance appearance); - void AddAttachment(LLUUID user, LLUUID attach); - - void RemoveAttachment(LLUUID user, LLUUID attach); - - List GetAttachments(LLUUID user); } } -- cgit v1.1