aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs216
1 files changed, 216 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
new file mode 100644
index 0000000..530a21c
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs
@@ -0,0 +1,216 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Reflection;
29using log4net;
30using Nini.Config;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Framework;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36
37namespace OpenSim.Region.CoreModules.Avatar.Attachments
38{
39 public class AttachmentsModule : IAttachmentsModule, IRegionModule
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42
43 protected Scene m_scene = null;
44
45 public void Initialise(Scene scene, IConfigSource source)
46 {
47 scene.RegisterModuleInterface<IAttachmentsModule>(this);
48 m_scene = scene;
49 }
50
51 public void PostInitialise()
52 {
53 }
54
55 public void Close()
56 {
57 }
58
59 public string Name
60 {
61 get { return "Attachments Module"; }
62 }
63
64 public bool IsSharedModule
65 {
66 get { return false; }
67 }
68
69 public bool AttachObject(
70 IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, Quaternion rot, Vector3 attachPos, bool silent)
71 {
72 SceneObjectGroup group = m_scene.GetGroupByPrim(objectLocalID);
73 if (group != null)
74 {
75 if (m_scene.Permissions.CanTakeObject(group.UUID, remoteClient.AgentId))
76 {
77 // If the attachment point isn't the same as the one previously used
78 // set it's offset position = 0 so that it appears on the attachment point
79 // and not in a weird location somewhere unknown.
80 if (AttachmentPt != 0 && AttachmentPt != (uint)group.GetAttachmentPoint())
81 {
82 attachPos = Vector3.Zero;
83 }
84
85 // AttachmentPt 0 means the client chose to 'wear' the attachment.
86 if (AttachmentPt == 0)
87 {
88 // Check object for stored attachment point
89 AttachmentPt = (uint)group.GetAttachmentPoint();
90 }
91
92 // if we still didn't find a suitable attachment point.......
93 if (AttachmentPt == 0)
94 {
95 // Stick it on left hand with Zero Offset from the attachment point.
96 AttachmentPt = (uint)AttachmentPoint.LeftHand;
97 attachPos = Vector3.Zero;
98 }
99
100 group.SetAttachmentPoint((byte)AttachmentPt);
101 group.AbsolutePosition = attachPos;
102
103 // Saves and gets itemID
104 UUID itemId;
105
106 if (group.GetFromItemID() == UUID.Zero)
107 {
108 m_scene.attachObjectAssetStore(remoteClient, group, remoteClient.AgentId, out itemId);
109 }
110 else
111 {
112 itemId = group.GetFromItemID();
113 }
114
115 SetAttachmentInventoryStatus(remoteClient, AttachmentPt, itemId, group);
116
117 group.AttachToAgent(remoteClient.AgentId, AttachmentPt, attachPos, silent);
118
119 // In case it is later dropped again, don't let
120 // it get cleaned up
121 group.RootPart.RemFlag(PrimFlags.TemporaryOnRez);
122 group.HasGroupChanged = false;
123 }
124 else
125 {
126 remoteClient.SendAgentAlertMessage(
127 "You don't have sufficient permissions to attach this object", false);
128
129 return false;
130 }
131 }
132 else
133 {
134 m_log.DebugFormat("[SCENE GRAPH]: AttachObject found no such scene object {0}", objectLocalID);
135 return false;
136 }
137
138 return true;
139 }
140
141 /// <summary>
142 /// Update the user inventory to reflect an attachment
143 /// </summary>
144 /// <param name="att"></param>
145 /// <param name="remoteClient"></param>
146 /// <param name="itemID"></param>
147 /// <param name="AttachmentPt"></param>
148 /// <returns></returns>
149 public UUID SetAttachmentInventoryStatus(
150 SceneObjectGroup att, IClientAPI remoteClient, UUID itemID, uint AttachmentPt)
151 {
152 m_log.DebugFormat(
153 "[USER INVENTORY]: Updating inventory of {0} to show attachment of {1} (item ID {2})",
154 remoteClient.Name, att.Name, itemID);
155
156 if (!att.IsDeleted)
157 AttachmentPt = att.RootPart.AttachmentPoint;
158
159 ScenePresence presence;
160 if (m_scene.TryGetAvatar(remoteClient.AgentId, out presence))
161 {
162 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
163 item = m_scene.InventoryService.GetItem(item);
164
165 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /*att.UUID*/);
166 }
167
168 return att.UUID;
169 }
170
171 /// <summary>
172 /// Update the user inventory to reflect an attachment
173 /// </summary>
174 /// <param name="remoteClient"></param>
175 /// <param name="AttachmentPt"></param>
176 /// <param name="itemID"></param>
177 /// <param name="att"></param>
178 public void SetAttachmentInventoryStatus(
179 IClientAPI remoteClient, uint AttachmentPt, UUID itemID, SceneObjectGroup att)
180 {
181// m_log.DebugFormat(
182// "[USER INVENTORY]: Updating attachment {0} for {1} at {2} using item ID {3}",
183// att.Name, remoteClient.Name, AttachmentPt, itemID);
184
185 if (UUID.Zero == itemID)
186 {
187 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error inventory item ID.");
188 return;
189 }
190
191 if (0 == AttachmentPt)
192 {
193 m_log.Error("[SCENE INVENTORY]: Unable to save attachment. Error attachment point.");
194 return;
195 }
196
197 if (null == att.RootPart)
198 {
199 m_log.Error("[SCENE INVENTORY]: Unable to save attachment for a prim without the rootpart!");
200 return;
201 }
202
203 ScenePresence presence;
204 if (m_scene.TryGetAvatar(remoteClient.AgentId, out presence))
205 {
206 // XXYY!!
207 InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
208 item = m_scene.InventoryService.GetItem(item);
209 presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /* att.UUID */);
210
211 if (m_scene.AvatarFactory != null)
212 m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance);
213 }
214 }
215 }
216} \ No newline at end of file