aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs401
1 files changed, 0 insertions, 401 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
deleted file mode 100644
index 053e0da..0000000
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs
+++ /dev/null
@@ -1,401 +0,0 @@
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 OpenSim 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;
29using System.IO;
30using System.Reflection;
31using OpenMetaverse;
32using log4net;
33using OpenSim.Framework;
34using OpenSim.Region.Environment.Interfaces;
35using System.Collections.Generic;
36using System.Xml;
37
38namespace OpenSim.Region.Environment.Scenes
39{
40 public partial class SceneObjectGroup : EntityBase
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43
44 /// <summary>
45 /// Force all task inventories of prims in the scene object to persist
46 /// </summary>
47 public void ForceInventoryPersistence()
48 {
49 lock (m_parts)
50 {
51 foreach (SceneObjectPart part in m_parts.Values)
52 {
53 part.Inventory.ForceInventoryPersistence();
54 }
55 }
56 }
57
58 /// <summary>
59 /// Start the scripts contained in all the prims in this group.
60 /// </summary>
61 public void CreateScriptInstances(int startParam, bool postOnRez,
62 string engine, int stateSource)
63 {
64 // Don't start scripts if they're turned off in the region!
65 if (!m_scene.RegionInfo.RegionSettings.DisableScripts)
66 {
67 foreach (SceneObjectPart part in m_parts.Values)
68 {
69 part.Inventory.CreateScriptInstances(startParam, postOnRez, engine, stateSource);
70 }
71 }
72 }
73
74 /// <summary>
75 /// Stop the scripts contained in all the prims in this group
76 /// </summary>
77 public void RemoveScriptInstances()
78 {
79 lock (m_parts)
80 {
81 foreach (SceneObjectPart part in m_parts.Values)
82 {
83 part.Inventory.RemoveScriptInstances();
84 }
85 }
86 }
87
88 /// <summary>
89 ///
90 /// </summary>
91 /// <param name="remoteClient"></param>
92 /// <param name="localID"></param>
93 public bool GetPartInventoryFileName(IClientAPI remoteClient, uint localID)
94 {
95 SceneObjectPart part = GetChildPart(localID);
96 if (part != null)
97 {
98 return part.Inventory.GetInventoryFileName(remoteClient, localID);
99 }
100 else
101 {
102 m_log.ErrorFormat(
103 "[PRIM INVENTORY]: " +
104 "Couldn't find part {0} in object group {1}, {2} to retreive prim inventory",
105 localID, Name, UUID);
106 }
107 return false;
108 }
109
110 /// <summary>
111 /// Return serialized inventory metadata for the given constituent prim
112 /// </summary>
113 /// <param name="localID"></param>
114 /// <param name="xferManager"></param>
115 public void RequestInventoryFile(IClientAPI client, uint localID, IXfer xferManager)
116 {
117 SceneObjectPart part = GetChildPart(localID);
118 if (part != null)
119 {
120 part.Inventory.RequestInventoryFile(client, xferManager);
121 }
122 else
123 {
124 m_log.ErrorFormat(
125 "[PRIM INVENTORY]: " +
126 "Couldn't find part {0} in object group {1}, {2} to request inventory data",
127 localID, Name, UUID);
128 }
129 }
130
131 /// <summary>
132 /// Add an inventory item to a prim in this group.
133 /// </summary>
134 /// <param name="remoteClient"></param>
135 /// <param name="localID"></param>
136 /// <param name="item"></param>
137 /// <param name="copyItemID">The item UUID that should be used by the new item.</param>
138 /// <returns></returns>
139 public bool AddInventoryItem(IClientAPI remoteClient, uint localID,
140 InventoryItemBase item, UUID copyItemID)
141 {
142 UUID newItemId = (copyItemID != UUID.Zero) ? copyItemID : item.ID;
143
144 SceneObjectPart part = GetChildPart(localID);
145 if (part != null)
146 {
147 TaskInventoryItem taskItem = new TaskInventoryItem();
148
149 taskItem.ItemID = newItemId;
150 taskItem.AssetID = item.AssetID;
151 taskItem.Name = item.Name;
152 taskItem.Description = item.Description;
153 taskItem.OwnerID = part.OwnerID; // Transfer ownership
154 taskItem.CreatorID = item.Creator;
155 taskItem.Type = item.AssetType;
156 taskItem.InvType = item.InvType;
157
158 if (remoteClient != null &&
159 remoteClient.AgentId != part.OwnerID &&
160 m_scene.Permissions.PropagatePermissions())
161 {
162 taskItem.BasePermissions = item.BasePermissions &
163 item.NextPermissions;
164 taskItem.CurrentPermissions = item.CurrentPermissions &
165 item.NextPermissions;
166 taskItem.EveryonePermissions = item.EveryOnePermissions &
167 item.NextPermissions;
168 taskItem.GroupPermissions = item.GroupPermissions &
169 item.NextPermissions;
170 taskItem.NextPermissions = item.NextPermissions;
171 taskItem.CurrentPermissions |= 8;
172 } else {
173 taskItem.BasePermissions = item.BasePermissions;
174 taskItem.CurrentPermissions = item.CurrentPermissions;
175 taskItem.CurrentPermissions |= 8;
176 taskItem.EveryonePermissions = item.EveryOnePermissions;
177 taskItem.GroupPermissions = item.GroupPermissions;
178 taskItem.NextPermissions = item.NextPermissions;
179 }
180
181 taskItem.Flags = item.Flags;
182 // TODO: These are pending addition of those fields to TaskInventoryItem
183// taskItem.SalePrice = item.SalePrice;
184// taskItem.SaleType = item.SaleType;
185 taskItem.CreationDate = (uint)item.CreationDate;
186
187 bool addFromAllowedDrop = false;
188 if (remoteClient!=null)
189 {
190 addFromAllowedDrop = remoteClient.AgentId != part.OwnerID;
191 }
192
193 part.Inventory.AddInventoryItem(taskItem, addFromAllowedDrop);
194
195 return true;
196 }
197 else
198 {
199 m_log.ErrorFormat(
200 "[PRIM INVENTORY]: " +
201 "Couldn't find prim local ID {0} in group {1}, {2} to add inventory item ID {3}",
202 localID, Name, UUID, newItemId);
203 }
204
205 return false;
206 }
207
208 /// <summary>
209 /// Returns an existing inventory item. Returns the original, so any changes will be live.
210 /// </summary>
211 /// <param name="primID"></param>
212 /// <param name="itemID"></param>
213 /// <returns>null if the item does not exist</returns>
214 public TaskInventoryItem GetInventoryItem(uint primID, UUID itemID)
215 {
216 SceneObjectPart part = GetChildPart(primID);
217 if (part != null)
218 {
219 return part.Inventory.GetInventoryItem(itemID);
220 }
221 else
222 {
223 m_log.ErrorFormat(
224 "[PRIM INVENTORY]: " +
225 "Couldn't find prim local ID {0} in prim {1}, {2} to get inventory item ID {3}",
226 primID, part.Name, part.UUID, itemID);
227 }
228
229 return null;
230 }
231
232 /// <summary>
233 /// Update an existing inventory item.
234 /// </summary>
235 /// <param name="item">The updated item. An item with the same id must already exist
236 /// in this prim's inventory</param>
237 /// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
238 public bool UpdateInventoryItem(TaskInventoryItem item)
239 {
240 SceneObjectPart part = GetChildPart(item.ParentPartID);
241 if (part != null)
242 {
243 part.Inventory.UpdateInventoryItem(item);
244
245 return true;
246 }
247 else
248 {
249 m_log.ErrorFormat(
250 "[PRIM INVENTORY]: " +
251 "Couldn't find prim ID {0} to update item {1}, {2}",
252 item.ParentPartID, item.Name, item.ItemID);
253 }
254
255 return false;
256 }
257
258 public int RemoveInventoryItem(uint localID, UUID itemID)
259 {
260 SceneObjectPart part = GetChildPart(localID);
261 if (part != null)
262 {
263 int type = part.Inventory.RemoveInventoryItem(itemID);
264
265 return type;
266 }
267
268 return -1;
269 }
270
271 public uint GetEffectivePermissions()
272 {
273 uint perms=(uint)(PermissionMask.Modify |
274 PermissionMask.Copy |
275 PermissionMask.Move |
276 PermissionMask.Transfer) | 7;
277
278 uint ownerMask = 0x7ffffff;
279 foreach (SceneObjectPart part in m_parts.Values)
280 {
281 ownerMask &= part.OwnerMask;
282 perms &= part.Inventory.MaskEffectivePermissions();
283 }
284
285 if ((ownerMask & (uint)PermissionMask.Modify) == 0)
286 perms &= ~(uint)PermissionMask.Modify;
287 if ((ownerMask & (uint)PermissionMask.Copy) == 0)
288 perms &= ~(uint)PermissionMask.Copy;
289 if ((ownerMask & (uint)PermissionMask.Transfer) == 0)
290 perms &= ~(uint)PermissionMask.Transfer;
291
292 if ((ownerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Modify) == 0)
293 perms &= ~((uint)PermissionMask.Modify >> 13);
294 if ((ownerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Copy) == 0)
295 perms &= ~((uint)PermissionMask.Copy >> 13);
296 if ((ownerMask & RootPart.NextOwnerMask & (uint)PermissionMask.Transfer) == 0)
297 perms &= ~((uint)PermissionMask.Transfer >> 13);
298
299 return perms;
300 }
301
302 public void ApplyNextOwnerPermissions()
303 {
304 foreach (SceneObjectPart part in m_parts.Values)
305 {
306 part.ApplyNextOwnerPermissions();
307 }
308 }
309
310 public string GetStateSnapshot()
311 {
312 List<string> assemblies = new List<string>();
313 Dictionary<UUID, string> states = new Dictionary<UUID, string>();
314
315 foreach (SceneObjectPart part in m_parts.Values)
316 {
317 foreach (string a in part.Inventory.GetScriptAssemblies())
318 {
319 if (a != "" && !assemblies.Contains(a))
320 assemblies.Add(a);
321 }
322
323 foreach (KeyValuePair<UUID, string> s in part.Inventory.GetScriptStates())
324 {
325 states[s.Key] = s.Value;
326 }
327 }
328
329 if (states.Count < 1 || assemblies.Count < 1)
330 return "";
331
332 XmlDocument xmldoc = new XmlDocument();
333
334 XmlNode xmlnode = xmldoc.CreateNode(XmlNodeType.XmlDeclaration,
335 "", "");
336
337 xmldoc.AppendChild(xmlnode);
338 XmlElement rootElement = xmldoc.CreateElement("", "ScriptData",
339 "");
340
341 xmldoc.AppendChild(rootElement);
342
343 XmlElement wrapper = xmldoc.CreateElement("", "Assemblies",
344 "");
345
346 rootElement.AppendChild(wrapper);
347
348 foreach (string assembly in assemblies)
349 {
350 string fn = Path.GetFileName(assembly);
351 if (fn == String.Empty)
352 continue;
353
354 FileInfo fi = new FileInfo(assembly);
355
356 if (fi == null)
357 continue;
358
359 Byte[] data = new Byte[fi.Length];
360
361 FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read);
362 fs.Read(data, 0, data.Length);
363 fs.Close();
364
365 XmlElement assemblyData = xmldoc.CreateElement("", "Assembly", "");
366 XmlAttribute assemblyName = xmldoc.CreateAttribute("", "Filename", "");
367 assemblyName.Value = fn;
368 assemblyData.Attributes.Append(assemblyName);
369
370 assemblyData.InnerText = System.Convert.ToBase64String(data);
371
372 wrapper.AppendChild(assemblyData);
373 }
374
375 wrapper = xmldoc.CreateElement("", "ScriptStates",
376 "");
377
378 rootElement.AppendChild(wrapper);
379
380 foreach (KeyValuePair<UUID, string> state in states)
381 {
382 XmlElement stateData = xmldoc.CreateElement("", "State", "");
383
384 XmlAttribute stateID = xmldoc.CreateAttribute("", "UUID", "");
385 stateID.Value = state.Key.ToString();
386 stateData.Attributes.Append(stateID);
387
388 XmlDocument sdoc = new XmlDocument();
389 sdoc.LoadXml(state.Value);
390 XmlNodeList rootL = sdoc.GetElementsByTagName("ScriptState");
391 XmlNode rootNode = rootL[0];
392
393 XmlNode newNode = xmldoc.ImportNode(rootNode, true);
394 stateData.AppendChild(newNode);
395 wrapper.AppendChild(stateData);
396 }
397
398 return xmldoc.InnerXml;
399 }
400 }
401}