aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs')
-rw-r--r--OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs338
1 files changed, 0 insertions, 338 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs b/OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs
deleted file mode 100644
index 9ed5dcb..0000000
--- a/OpenSim/OpenSim.RegionServer/Assets/InventoryCache.cs
+++ /dev/null
@@ -1,338 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 libsecondlife;
32using OpenSim;
33using libsecondlife.Packets;
34
35using OpenSim.Framework.Inventory;
36using OpenSim.Framework.Types;
37using OpenSim.Framework.Interfaces;
38using OpenSim.RegionServer.Client;
39
40namespace OpenSim.RegionServer.Assets
41{
42 /// <summary>
43 /// Description of InventoryManager.
44 /// </summary>
45 public class InventoryCache
46 {
47 private Dictionary<LLUUID, AgentInventory> _agentsInventory;
48 private List<UserServerRequest> _serverRequests; //list of requests made to user server.
49 private System.Text.Encoding _enc = System.Text.Encoding.ASCII;
50 private const uint FULL_MASK_PERMISSIONS = 2147483647;
51
52 public InventoryCache()
53 {
54 _agentsInventory = new Dictionary<LLUUID, AgentInventory>();
55 _serverRequests = new List<UserServerRequest>();
56 }
57
58 public void AddNewAgentsInventory(AgentInventory agentInventory)
59 {
60 if (!this._agentsInventory.ContainsKey(agentInventory.AgentID))
61 {
62 this._agentsInventory.Add(agentInventory.AgentID, agentInventory);
63 }
64 }
65
66 public AgentInventory FetchAgentsInventory(LLUUID agentID, IUserServer userserver)
67 {
68 AgentInventory res = null;
69 if (!this._agentsInventory.ContainsKey(agentID))
70 {
71 res = userserver.RequestAgentsInventory(agentID);
72 this._agentsInventory.Add(agentID,res);
73 }
74 return res;
75 }
76
77 public AgentInventory GetAgentsInventory(LLUUID agentID)
78 {
79 if (this._agentsInventory.ContainsKey(agentID))
80 {
81 return this._agentsInventory[agentID];
82 }
83
84 return null;
85 }
86
87 public void ClientLeaving(LLUUID clientID, IUserServer userserver)
88 {
89 if (this._agentsInventory.ContainsKey(clientID))
90 {
91 if (userserver != null)
92 {
93 userserver.UpdateAgentsInventory(clientID, this._agentsInventory[clientID]);
94 }
95 this._agentsInventory.Remove(clientID);
96 }
97 }
98
99 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID)
100 {
101 return this.CreateNewInventoryFolder(remoteClient, folderID, 0);
102 }
103
104 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type)
105 {
106 bool res = false;
107 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
108 {
109 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
110 {
111 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type);
112 }
113 }
114 return res;
115 }
116
117 public bool CreateNewInventoryFolder(ClientView remoteClient, LLUUID folderID, ushort type, string folderName, LLUUID parent)
118 {
119 bool res = false;
120 if (folderID != LLUUID.Zero) //don't create a folder with a zero id
121 {
122 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
123 {
124 res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type, folderName, parent);
125 }
126 }
127 return res;
128 }
129
130 public LLUUID AddNewInventoryItem(ClientView remoteClient, LLUUID folderID, OpenSim.Framework.Types.AssetBase asset)
131 {
132 LLUUID newItem = null;
133 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
134 {
135 newItem = this._agentsInventory[remoteClient.AgentID].AddToInventory(folderID, asset);
136 if (newItem != null)
137 {
138 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[newItem];
139 this.SendItemUpdateCreate(remoteClient, Item);
140 }
141 }
142
143 return newItem;
144 }
145 public bool DeleteInventoryItem(ClientView remoteClient, LLUUID itemID)
146 {
147 bool res = false;
148 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
149 {
150 res = this._agentsInventory[remoteClient.AgentID].DeleteFromInventory(itemID);
151 if (res)
152 {
153 RemoveInventoryItemPacket remove = new RemoveInventoryItemPacket();
154 remove.AgentData.AgentID = remoteClient.AgentID;
155 remove.AgentData.SessionID = remoteClient.SessionID;
156 remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1];
157 remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock();
158 remove.InventoryData[0].ItemID = itemID;
159 remoteClient.OutPacket(remove);
160 }
161 }
162
163 return res;
164 }
165
166 public bool UpdateInventoryItemAsset(ClientView remoteClient, LLUUID itemID, OpenSim.Framework.Types.AssetBase asset)
167 {
168 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
169 {
170 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemAsset(itemID, asset);
171 if (res)
172 {
173 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
174 this.SendItemUpdateCreate(remoteClient, Item);
175 }
176 return res;
177 }
178
179 return false;
180 }
181
182 public bool UpdateInventoryItemDetails(ClientView remoteClient, LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
183 {
184 if (this._agentsInventory.ContainsKey(remoteClient.AgentID))
185 {
186 bool res = _agentsInventory[remoteClient.AgentID].UpdateItemDetails(itemID, packet);
187 if (res)
188 {
189 InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID];
190 this.SendItemUpdateCreate(remoteClient, Item);
191 }
192 return res;
193 }
194
195 return false;
196 }
197
198 public void FetchInventoryDescendents(ClientView userInfo, FetchInventoryDescendentsPacket FetchDescend)
199 {
200 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
201 {
202 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
203 if (FetchDescend.InventoryData.FetchItems)
204 {
205 if (agentInventory.InventoryFolders.ContainsKey(FetchDescend.InventoryData.FolderID))
206 {
207 InventoryFolder Folder = agentInventory.InventoryFolders[FetchDescend.InventoryData.FolderID];
208 InventoryDescendentsPacket Descend = new InventoryDescendentsPacket();
209 Descend.AgentData.AgentID = userInfo.AgentID;
210 Descend.AgentData.OwnerID = Folder.OwnerID;
211 Descend.AgentData.FolderID = FetchDescend.InventoryData.FolderID;
212 Descend.AgentData.Descendents = Folder.Items.Count;
213 Descend.AgentData.Version = Folder.Items.Count;
214
215
216 Descend.ItemData = new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count];
217 for (int i = 0; i < Folder.Items.Count; i++)
218 {
219
220 InventoryItem Item = Folder.Items[i];
221 Descend.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock();
222 Descend.ItemData[i].ItemID = Item.ItemID;
223 Descend.ItemData[i].AssetID = Item.AssetID;
224 Descend.ItemData[i].CreatorID = Item.CreatorID;
225 Descend.ItemData[i].BaseMask = FULL_MASK_PERMISSIONS;
226 Descend.ItemData[i].CreationDate = 1000;
227 Descend.ItemData[i].Description = _enc.GetBytes(Item.Description + "\0");
228 Descend.ItemData[i].EveryoneMask = FULL_MASK_PERMISSIONS;
229 Descend.ItemData[i].Flags = 1;
230 Descend.ItemData[i].FolderID = Item.FolderID;
231 Descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
232 Descend.ItemData[i].GroupMask = FULL_MASK_PERMISSIONS;
233 Descend.ItemData[i].InvType = Item.InvType;
234 Descend.ItemData[i].Name = _enc.GetBytes(Item.Name + "\0");
235 Descend.ItemData[i].NextOwnerMask = FULL_MASK_PERMISSIONS;
236 Descend.ItemData[i].OwnerID = Item.OwnerID;
237 Descend.ItemData[i].OwnerMask = FULL_MASK_PERMISSIONS;
238 Descend.ItemData[i].SalePrice = 100;
239 Descend.ItemData[i].SaleType = 0;
240 Descend.ItemData[i].Type = Item.Type;
241 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);
242 }
243
244 userInfo.OutPacket(Descend);
245
246 }
247 }
248 else
249 {
250 Console.WriteLine("fetch subfolders");
251 }
252 }
253 }
254
255 public void FetchInventory(ClientView userInfo, FetchInventoryPacket FetchItems)
256 {
257 if (this._agentsInventory.ContainsKey(userInfo.AgentID))
258 {
259 AgentInventory agentInventory = this._agentsInventory[userInfo.AgentID];
260
261 for (int i = 0; i < FetchItems.InventoryData.Length; i++)
262 {
263 if (agentInventory.InventoryItems.ContainsKey(FetchItems.InventoryData[i].ItemID))
264 {
265 InventoryItem Item = agentInventory.InventoryItems[FetchItems.InventoryData[i].ItemID];
266 FetchInventoryReplyPacket InventoryReply = new FetchInventoryReplyPacket();
267 InventoryReply.AgentData.AgentID = userInfo.AgentID;
268 InventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
269 InventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
270 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
271 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
272 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
273 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
274 InventoryReply.InventoryData[0].CreationDate = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
275 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
276 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
277 InventoryReply.InventoryData[0].Flags = 0;
278 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
279 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
280 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
281 InventoryReply.InventoryData[0].InvType = Item.InvType;
282 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
283 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
284 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
285 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
286 InventoryReply.InventoryData[0].SalePrice = 100;
287 InventoryReply.InventoryData[0].SaleType = 0;
288 InventoryReply.InventoryData[0].Type = Item.Type;
289 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);
290 userInfo.OutPacket(InventoryReply);
291 }
292 }
293 }
294 }
295
296 private void SendItemUpdateCreate(ClientView remoteClient, InventoryItem Item)
297 {
298
299 UpdateCreateInventoryItemPacket InventoryReply = new UpdateCreateInventoryItemPacket();
300 InventoryReply.AgentData.AgentID = remoteClient.AgentID;
301 InventoryReply.AgentData.SimApproved = true;
302 InventoryReply.InventoryData = new UpdateCreateInventoryItemPacket.InventoryDataBlock[1];
303 InventoryReply.InventoryData[0] = new UpdateCreateInventoryItemPacket.InventoryDataBlock();
304 InventoryReply.InventoryData[0].ItemID = Item.ItemID;
305 InventoryReply.InventoryData[0].AssetID = Item.AssetID;
306 InventoryReply.InventoryData[0].CreatorID = Item.CreatorID;
307 InventoryReply.InventoryData[0].BaseMask = FULL_MASK_PERMISSIONS;
308 InventoryReply.InventoryData[0].CreationDate = 1000;
309 InventoryReply.InventoryData[0].Description = _enc.GetBytes(Item.Description + "\0");
310 InventoryReply.InventoryData[0].EveryoneMask = FULL_MASK_PERMISSIONS;
311 InventoryReply.InventoryData[0].Flags = 0;
312 InventoryReply.InventoryData[0].FolderID = Item.FolderID;
313 InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000");
314 InventoryReply.InventoryData[0].GroupMask = FULL_MASK_PERMISSIONS;
315 InventoryReply.InventoryData[0].InvType = Item.InvType;
316 InventoryReply.InventoryData[0].Name = _enc.GetBytes(Item.Name + "\0");
317 InventoryReply.InventoryData[0].NextOwnerMask = FULL_MASK_PERMISSIONS;
318 InventoryReply.InventoryData[0].OwnerID = Item.OwnerID;
319 InventoryReply.InventoryData[0].OwnerMask = FULL_MASK_PERMISSIONS;
320 InventoryReply.InventoryData[0].SalePrice = 100;
321 InventoryReply.InventoryData[0].SaleType = 0;
322 InventoryReply.InventoryData[0].Type = Item.Type;
323 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);
324
325 remoteClient.OutPacket(InventoryReply);
326 }
327 }
328
329
330
331 public class UserServerRequest
332 {
333 public UserServerRequest()
334 {
335
336 }
337 }
338}