aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs')
-rw-r--r--OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs336
1 files changed, 336 insertions, 0 deletions
diff --git a/OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs b/OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs
new file mode 100644
index 0000000..64a7a32
--- /dev/null
+++ b/OpenSim-Source/OpenSim.RegionServer/Assets/InventoryCache.cs
@@ -0,0 +1,336 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27
28using System;
29using System.Collections.Generic;
30using libsecondlife;
31using OpenSim;
32using libsecondlife.Packets;
33//using OpenSim.GridServers;
34using OpenSim.Framework.Inventory;
35using OpenSim.Framework.Types;
36using OpenSim.Framework.Interfaces;
37
38namespace OpenSim.Assets
39{
40 /// <summary>
41 /// Description of InventoryManager.
42 /// </summary>
43 public class InventoryCache
44 {
45 private Dictionary<LLUUID, AgentInventory> _agentsInventory;
46 private List<UserServerRequest> _serverRequests; //list of requests made to user server.
47 private System.Text.Encoding _enc = System.Text.Encoding.ASCII;
48 private const uint FULL_MASK_PERMISSIONS = 2147483647;
49
50 public InventoryCache()
51 {
52 _agentsInventory = new Dictionary<LLUUID, AgentInventory>();
53 _serverRequests = new List<UserServerRequest>();
54 }
55
56 public void AddNewAgentsInventory(AgentInventory agentInventory)
57 {
58 if (!this._agentsInventory.ContainsKey(agentInventory.AgentID))
59 {
60 this._agentsInventory.Add(agentInventory.AgentID, agentInventory);
61 }
62 }
63
64 public AgentInventory FetchAgentsInventory(LLUUID agentID, IUserServer userserver)
65 {
66 AgentInventory res = null;
67 if (!this._agentsInventory.ContainsKey(agentID))
68 {
69 res = userserver.RequestAgentsInventory(agentID);
70 this._agentsInventory.Add(agentID,res);
71 }
72 return res;
73 }
74
75 public AgentInventory GetAgentsInventory(LLUUID agentID)
76 {
77 if (this._agentsInventory.ContainsKey(agentID))
78 {
79 return this._agentsInventory[agentID];
80 }
81
82 return null;
83 }
84
85 public void ClientLeaving(LLUUID clientID, IUserServer userserver)
86 {
87 if (this._agentsInventory.ContainsKey(clientID))
88 {
89 if (userserver != null)
90 {
91 userserver.UpdateAgentsInventory(clientID, this._agentsInventory[clientID]);
92 }
93 this._agentsInventory.Remove(clientID);
94 }
95 }
96
97 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID)
98 {
99 return this.CreateNewInventoryFolder(remoteClient, folderID, 0);
100 }
101
102 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type)
103 {
104 bool res = false;
105 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
106 {
107 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
108 {
109 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type);
110 }
111 }
112 return res;
113 }
114
115 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type, string folderName, LLUUID parent)
116 {
117 bool res = false;
118 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
119 {
120 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
121 {
122 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type, folderName, parent);
123 }
124 }
125 return res;
126 }
127
128 public LLUUID AddNewInventoryItem(ClientView remoteClient, LLUUID folderID, OpenSim.Framework.Types.AssetBase asset)
129 {
130 LLUUID newItem = null;
131 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
132 {
133 newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset);
134 if (newItem != null)
135 {
136 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[newItem];
137 this.SendItemUpdateCreate(remoteClient, Item);
138 }
139 }
140
141 return newItem;
142 }
143 public bool DeleteInventoryItem(ClientView remoteClient, LLUUID itemID)
144 {
145 bool res = false;
146 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
147 {
148 res = this._agentsInventory[remoteClient.AgentID].DeleteFromInventory(itemID);
149 if (res)
150 {
151 RemoveInventoryItemPacket remove = new RemoveInventoryItemPacket();
152 remove.AgentData.AgentID = remoteClient.AgentID;
153 remove.AgentData.SessionID = remoteClient.SessionID;
154 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
155 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
156 remove.InventoryData[0].ItemID = itemID;
157 remoteClient.OutPacket(remove);
158 }
159 }
160
161 return res;
162 }
163
164 public bool UpdateInventoryItemAsset(ClientView remoteClient, LLUUID itemID, OpenSim.Framework.Types.AssetBase asset)
165 {
166 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
167 {
168 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemAsset(itemID, asset);
169 if (res)
170 {
171 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
172 this.SendItemUpdateCreate(remoteClient, Item);
173 }
174 return res;
175 }
176
177 return false;
178 }
179
180 public bool UpdateInventoryItemDetails(ClientView remoteClient, LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
181 {
182 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
183 {
184 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemDetails(itemID, packet);
185 if (res)
186 {
187 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
188 this.SendItemUpdateCreate(remoteClient, Item);
189 }
190 return res;
191 }
192
193 return false;
194 }
195
196 public void FetchInventoryDescendents(ClientView userInfo, FetchInventoryDescendentsPacket FetchDescend)
197 {
198 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
199 {
200 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
201 if (FetchDescend.InventoryData.FetchItems)
202 {
203 if (agentInventory.InventoryFolders.ContainsKey(FetchDescend.InventoryData.FolderID))
204 {
205 InventoryFolder Folder = agentInventory.InventoryFolders[FetchDescend.InventoryData.FolderID];
206 InventoryDescendentsPacket Descend = new InventoryDescendentsPacket();
207 Descend.AgentData.AgentID = userInfo.AgentID;
208 Descend.AgentData.OwnerID = Folder.OwnerID;
209 Descend.AgentData.FolderID = FetchDescend.InventoryData.FolderID;
210 Descend.AgentData.Descendents = Folder.Items.Count;
211 Descend.AgentData.Version = Folder.Items.Count;
212
213
214 Descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count];
215 for (int i = 0; i < Folder.Items.Count; i++)
216 {
217
218 InventoryItem Item = Folder.Items[i];
219 Descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
220 Descend.ItemData[i].ItemID = Item.ItemID;
221 Descend.ItemData[i].AssetID = Item.AssetID;
222 Descend.ItemData[i].CreatorID = Item.CreatorID;
223 Descend.ItemData[i].BaseMask = FULL_MASK_PERMISSIONS;
224 Descend.ItemData[i].CreationDate = 1000;
225 Descend.ItemData[i].Description = _enc.GetBytes(Item.Description + "\0");
226 Descend.ItemData[i].EveryoneMask = FULL_MASK_PERMISSIONS;
227 Descend.ItemData[i].Flags = 1;
228 Descend.ItemData[i].FolderID = Item.FolderID;
229 Descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
230 Descend.ItemData[i].GroupMask = FULL_MASK_PERMISSIONS;
231 Descend.ItemData[i].InvType = Item.InvType;
232 Descend.ItemData[i].Name = _enc.GetBytes(Item.Name + "\0");
233 Descend.ItemData[i].NextOwnerMask = FULL_MASK_PERMISSIONS;
234 Descend.ItemData[i].OwnerID = Item.OwnerID;
235 Descend.ItemData[i].OwnerMask = FULL_MASK_PERMISSIONS;
236 Descend.ItemData[i].SalePrice = 100;
237 Descend.ItemData[i].SaleType = 0;
238 Descend.ItemData[i].Type = Item.Type;
239 Descend.ItemData[i].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, Descend.ItemData[i].InvType, Descend.ItemData[i].Type, Descend.ItemData[i].AssetID, Descend.ItemData[i].GroupID, 100, Descend.ItemData[i].OwnerID, Descend.ItemData[i].CreatorID, Descend.ItemData[i].ItemID, Descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
240 }
241
242 userInfo.OutPacket(Descend);
243
244 }
245 }
246 else
247 {
248 Console.WriteLine("fetch subfolders");
249 }
250 }
251 }
252
253 public void FetchInventory(ClientView userInfo, FetchInventoryPacket FetchItems)
254 {
255 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
256 {
257 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
258
259 for (int i = 0; i < FetchItems.InventoryData.Length; i++)
260 {
261 if (agentInventory.InventoryItems.ContainsKey(FetchItems.InventoryData[i].ItemID))
262 {
263 InventoryItem Item = agentInventory.InventoryItems[FetchItems.InventoryData[i].ItemID];
264 FetchInventoryReplyPacket InventoryReply = new FetchInventoryReplyPacket();
265 InventoryReply.AgentData.AgentID = userInfo.AgentID;
266 InventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
267 InventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
268 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
269 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
270 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
271 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
272 InventoryReply.InventoryData[0].CreationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
273 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
274 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
275 InventoryReply.InventoryData[0].Flags = 0;
276 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
277 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
278 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
279 InventoryReply.InventoryData[0].InvType = Item.InvType;
280 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
281 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
282 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
283 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
284 InventoryReply.InventoryData[0].SalePrice = 100;
285 InventoryReply.InventoryData[0].SaleType = 0;
286 InventoryReply.InventoryData[0].Type = Item.Type;
287 InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
288 userInfo.OutPacket(InventoryReply);
289 }
290 }
291 }
292 }
293
294 private void SendItemUpdateCreate(ClientView remoteClient, InventoryItem Item)
295 {
296
297 UpdateCreateInventoryItemPacket InventoryReply = new UpdateCreateInventoryItemPacket();
298 InventoryReply.AgentData.AgentID = remoteClient.AgentID;
299 InventoryReply.AgentData.SimApproved = true;
300 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
301 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
302 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
303 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
304 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
305 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
306 InventoryReply.InventoryData[0].CreationDate = 1000;
307 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
308 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
309 InventoryReply.InventoryData[0].Flags = 0;
310 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
311 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
312 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
313 InventoryReply.InventoryData[0].InvType = Item.InvType;
314 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
315 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
316 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
317 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
318 InventoryReply.InventoryData[0].SalePrice = 100;
319 InventoryReply.InventoryData[0].SaleType = 0;
320 InventoryReply.InventoryData[0].Type = Item.Type;
321 InventoryReply.InventoryData[0].CRC = libsecondlife.Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS);
322
323 remoteClient.OutPacket(InventoryReply);
324 }
325 }
326
327
328
329 public class UserServerRequest
330 {
331 public UserServerRequest()
332 {
333
334 }
335 }
336}