aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-01-06 22:43:45 +0000
committerJustin Clarke Casey2008-01-06 22:43:45 +0000
commit35a63c64f601459805f2eba839ce19eccf9b8592 (patch)
tree18110faf257fdd8f4d53005930c619fb7f5c33bc /OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
parentFor CharlieO: new folders created for new asset set stuff. Mantis 313 (diff)
downloadopensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.zip
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.gz
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.bz2
opensim-SC_OLD-35a63c64f601459805f2eba839ce19eccf9b8592.tar.xz
Factor out inventory related code in SceneObjectPart into separate class
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs244
1 files changed, 244 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
new file mode 100644
index 0000000..aab2291
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -0,0 +1,244 @@
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*/
28
29using System;
30using System.Collections.Generic;
31using System.Xml.Serialization;
32
33using libsecondlife;
34
35using OpenSim.Framework;
36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes.Scripting;
38
39namespace OpenSim.Region.Environment.Scenes
40{
41 public partial class SceneObjectPart : IScriptHost
42 {
43 private string m_inventoryFileName = "";
44
45 /// <summary>
46 /// The inventory folder for this prim
47 /// </summary>
48 private LLUUID m_folderID = LLUUID.Zero;
49
50 /// <summary>
51 /// Exposing this is not particularly good, but it's one of the least evils at the moment to see
52 /// folder id from prim inventory item data, since it's not (yet) actually stored with the prim.
53 /// </summary>
54 public LLUUID FolderID
55 {
56 get { return m_folderID; }
57 set { m_folderID = value; }
58 }
59
60 /// <summary>
61 /// Holds in memory prim inventory
62 /// </summary>
63 protected IDictionary<LLUUID, TaskInventoryItem> m_taskInventory
64 = new Dictionary<LLUUID, TaskInventoryItem>();
65
66 [XmlIgnore]
67 public IDictionary<LLUUID, TaskInventoryItem> TaskInventory
68 {
69 get { return m_taskInventory; }
70 }
71
72 /// <summary>
73 /// Serial count for inventory file , used to tell if inventory has changed
74 /// no need for this to be part of Database backup
75 /// </summary>
76 protected uint m_inventorySerial = 0;
77
78 public uint InventorySerial
79 {
80 get { return m_inventorySerial; }
81 }
82
83 /// <summary>
84 /// Add an item to this prim's inventory.
85 /// </summary>
86 /// <param name="item"></param>
87 public void AddInventoryItem(TaskInventoryItem item)
88 {
89 item.parent_id = m_folderID;
90 item.creation_date = 1000;
91 item.ParentPartID = UUID;
92 m_taskInventory.Add(item.item_id, item);
93 m_inventorySerial++;
94 }
95
96 /// <summary>
97 /// Add a whole collection of items to the prim's inventory at once. We assume that the items already
98 /// have all their fields correctly filled out.
99 /// </summary>
100 /// <param name="items"></param>
101 public void AddInventoryItems(ICollection<TaskInventoryItem> items)
102 {
103 foreach (TaskInventoryItem item in items)
104 {
105 m_taskInventory.Add(item.item_id, item);
106 }
107
108 m_inventorySerial++;
109 }
110
111 public int RemoveInventoryItem(IClientAPI remoteClient, uint localID, LLUUID itemID)
112 {
113 if (localID == LocalID)
114 {
115 if (m_taskInventory.ContainsKey(itemID))
116 {
117 string type = m_taskInventory[itemID].inv_type;
118 m_taskInventory.Remove(itemID);
119 m_inventorySerial++;
120 if (type == "lsl_text")
121 {
122 return 10;
123 }
124 else
125 {
126 return 0;
127 }
128 }
129 }
130 return -1;
131 }
132
133 /// <summary>
134 ///
135 /// </summary>
136 /// <param name="client"></param>
137 /// <param name="localID"></param>
138 public bool GetInventoryFileName(IClientAPI client, uint localID)
139 {
140 if (m_inventorySerial > 0)
141 {
142 client.SendTaskInventory(m_uuid, (short) m_inventorySerial,
143 Helpers.StringToField(m_inventoryFileName));
144 return true;
145 }
146 else
147 {
148 client.SendTaskInventory(m_uuid, 0, new byte[0]);
149 return false;
150 }
151 }
152
153 public void RequestInventoryFile(IXfer xferManager)
154 {
155 byte[] fileData = new byte[0];
156 InventoryStringBuilder invString = new InventoryStringBuilder(m_folderID, UUID);
157 foreach (TaskInventoryItem item in m_taskInventory.Values)
158 {
159 invString.AddItemStart();
160 invString.AddNameValueLine("item_id", item.item_id.ToString());
161 invString.AddNameValueLine("parent_id", item.parent_id.ToString());
162
163 invString.AddPermissionsStart();
164 invString.AddNameValueLine("base_mask", "0x7FFFFFFF");
165 invString.AddNameValueLine("owner_mask", "0x7FFFFFFF");
166 invString.AddNameValueLine("group_mask", "0x7FFFFFFF");
167 invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF");
168 invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF");
169 invString.AddNameValueLine("creator_id", item.creator_id.ToString());
170 invString.AddNameValueLine("owner_id", item.owner_id.ToString());
171 invString.AddNameValueLine("last_owner_id", item.last_owner_id.ToString());
172 invString.AddNameValueLine("group_id", item.group_id.ToString());
173 invString.AddSectionEnd();
174
175 invString.AddNameValueLine("asset_id", item.asset_id.ToString());
176 invString.AddNameValueLine("type", item.type);
177 invString.AddNameValueLine("inv_type", item.inv_type);
178 invString.AddNameValueLine("flags", "0x00");
179 invString.AddNameValueLine("name", item.name + "|");
180 invString.AddNameValueLine("desc", item.desc + "|");
181 invString.AddNameValueLine("creation_date", item.creation_date.ToString());
182 invString.AddSectionEnd();
183 }
184
185 fileData = Helpers.StringToField(invString.BuildString);
186
187// MainLog.Instance.Verbose(
188// "PRIMINVENTORY", "RequestInventoryFile fileData: {0}", Helpers.FieldToUTF8String(fileData));
189
190 if (fileData.Length > 2)
191 {
192 xferManager.AddNewFile(m_inventoryFileName, fileData);
193 }
194 }
195
196 public class InventoryStringBuilder
197 {
198 public string BuildString = "";
199
200 public InventoryStringBuilder(LLUUID folderID, LLUUID parentID)
201 {
202 BuildString += "\tinv_object\t0\n\t{\n";
203 AddNameValueLine("obj_id", folderID.ToString());
204 AddNameValueLine("parent_id", parentID.ToString());
205 AddNameValueLine("type", "category");
206 AddNameValueLine("name", "Contents");
207 AddSectionEnd();
208 }
209
210 public void AddItemStart()
211 {
212 BuildString += "\tinv_item\t0\n";
213 BuildString += "\t{\n";
214 }
215
216 public void AddPermissionsStart()
217 {
218 BuildString += "\tpermissions 0\n";
219 BuildString += "\t{\n";
220 }
221
222 public void AddSectionEnd()
223 {
224 BuildString += "\t}\n";
225 }
226
227 public void AddLine(string addLine)
228 {
229 BuildString += addLine;
230 }
231
232 public void AddNameValueLine(string name, string value)
233 {
234 BuildString += "\t\t";
235 BuildString += name + "\t";
236 BuildString += value + "\n";
237 }
238
239 public void Close()
240 {
241 }
242 }
243 }
244}