aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/General/AgentInventory.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/General/AgentInventory.cs')
-rw-r--r--OpenSim/Framework/General/AgentInventory.cs265
1 files changed, 265 insertions, 0 deletions
diff --git a/OpenSim/Framework/General/AgentInventory.cs b/OpenSim/Framework/General/AgentInventory.cs
new file mode 100644
index 0000000..e45a0cd
--- /dev/null
+++ b/OpenSim/Framework/General/AgentInventory.cs
@@ -0,0 +1,265 @@
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*/
28using System.Collections.Generic;
29using libsecondlife;
30using libsecondlife.Packets;
31using OpenSim.Framework.Types;
32using OpenSim.Framework.Utilities;
33
34namespace OpenSim.Framework.Inventory
35{
36 public class AgentInventory
37 {
38 //Holds the local copy of Inventory info for a agent
39 public Dictionary<LLUUID, InventoryFolder> InventoryFolders;
40 public Dictionary<LLUUID, InventoryItem> InventoryItems;
41 public InventoryFolder InventoryRoot;
42 public int LastCached; //maybe used by opensim app, time this was last stored/compared to user server
43 public LLUUID AgentID;
44 public AvatarWearable[] Wearables;
45
46 public AgentInventory()
47 {
48 InventoryFolders = new Dictionary<LLUUID, InventoryFolder>();
49 InventoryItems = new Dictionary<LLUUID, InventoryItem>();
50 this.Initialise();
51 }
52
53 public virtual void Initialise()
54 {
55 Wearables = new AvatarWearable[13]; //should be 12 of these
56 for (int i = 0; i < 13; i++)
57 {
58 Wearables[i] = new AvatarWearable();
59 }
60
61 }
62
63 public bool CreateNewFolder(LLUUID folderID, ushort type)
64 {
65 InventoryFolder Folder = new InventoryFolder();
66 Folder.FolderID = folderID;
67 Folder.OwnerID = this.AgentID;
68 Folder.DefaultType = type;
69 this.InventoryFolders.Add(Folder.FolderID, Folder);
70 return (true);
71 }
72
73 public void CreateRootFolder(LLUUID newAgentID, bool createTextures)
74 {
75 this.AgentID = newAgentID;
76 InventoryRoot = new InventoryFolder();
77 InventoryRoot.FolderID = LLUUID.Random();
78 InventoryRoot.ParentID = new LLUUID();
79 InventoryRoot.Version = 1;
80 InventoryRoot.DefaultType = 8;
81 InventoryRoot.OwnerID = this.AgentID;
82 InventoryRoot.FolderName = "My Inventory";
83 InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot);
84 InventoryRoot.OwnerID = this.AgentID;
85 if (createTextures)
86 {
87 this.CreateNewFolder(LLUUID.Random(), 0, "Textures", InventoryRoot.FolderID);
88 }
89 }
90
91 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName)
92 {
93 InventoryFolder Folder = new InventoryFolder();
94 Folder.FolderID = folderID;
95 Folder.OwnerID = this.AgentID;
96 Folder.DefaultType = type;
97 Folder.FolderName = folderName;
98 this.InventoryFolders.Add(Folder.FolderID, Folder);
99
100 return (true);
101 }
102
103 public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName, LLUUID parent)
104 {
105 if (!this.InventoryFolders.ContainsKey(folderID))
106 {
107 System.Console.WriteLine("creating new folder called " + folderName + " in agents inventory");
108 InventoryFolder Folder = new InventoryFolder();
109 Folder.FolderID = folderID;
110 Folder.OwnerID = this.AgentID;
111 Folder.DefaultType = type;
112 Folder.FolderName = folderName;
113 Folder.ParentID = parent;
114 this.InventoryFolders.Add(Folder.FolderID, Folder);
115 }
116
117 return (true);
118 }
119
120 public bool HasFolder(LLUUID folderID)
121 {
122 if (this.InventoryFolders.ContainsKey(folderID))
123 {
124 return true;
125 }
126 return false;
127 }
128
129 public LLUUID GetFolderID(string folderName)
130 {
131 foreach (InventoryFolder inv in this.InventoryFolders.Values)
132 {
133 if (inv.FolderName == folderName)
134 {
135 return inv.FolderID;
136 }
137 }
138
139 return LLUUID.Zero;
140 }
141
142 public bool UpdateItemAsset(LLUUID itemID, AssetBase asset)
143 {
144 if(this.InventoryItems.ContainsKey(itemID))
145 {
146 InventoryItem Item = this.InventoryItems[itemID];
147 Item.AssetID = asset.FullID;
148 System.Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated() + " so it now is set to asset " + asset.FullID.ToStringHyphenated());
149 //TODO need to update the rest of the info
150 }
151 return true;
152 }
153
154 public bool UpdateItemDetails(LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet)
155 {
156 System.Console.WriteLine("updating inventory item details");
157 if (this.InventoryItems.ContainsKey(itemID))
158 {
159 System.Console.WriteLine("changing name to "+ Util.FieldToString(packet.Name));
160 InventoryItem Item = this.InventoryItems[itemID];
161 Item.Name = Util.FieldToString(packet.Name);
162 System.Console.WriteLine("updated inventory item " + itemID.ToStringHyphenated());
163 //TODO need to update the rest of the info
164 }
165 return true;
166 }
167
168 public LLUUID AddToInventory(LLUUID folderID, AssetBase asset)
169 {
170 if (this.InventoryFolders.ContainsKey(folderID))
171 {
172 LLUUID NewItemID = LLUUID.Random();
173
174 InventoryItem Item = new InventoryItem();
175 Item.FolderID = folderID;
176 Item.OwnerID = AgentID;
177 Item.AssetID = asset.FullID;
178 Item.ItemID = NewItemID;
179 Item.Type = asset.Type;
180 Item.Name = asset.Name;
181 Item.Description = asset.Description;
182 Item.InvType = asset.InvType;
183 this.InventoryItems.Add(Item.ItemID, Item);
184 InventoryFolder Folder = InventoryFolders[Item.FolderID];
185 Folder.Items.Add(Item);
186 return (Item.ItemID);
187 }
188 else
189 {
190 return (null);
191 }
192 }
193
194 public bool DeleteFromInventory(LLUUID itemID)
195 {
196 bool res = false;
197 if (this.InventoryItems.ContainsKey(itemID))
198 {
199 InventoryItem item = this.InventoryItems[itemID];
200 this.InventoryItems.Remove(itemID);
201 foreach (InventoryFolder fold in InventoryFolders.Values)
202 {
203 if (fold.Items.Contains(item))
204 {
205 fold.Items.Remove(item);
206 break;
207 }
208 }
209 res = true;
210
211 }
212 return res;
213 }
214 }
215
216 public class InventoryFolder
217 {
218 public List<InventoryItem> Items;
219 //public List<InventoryFolder> Subfolders;
220 public LLUUID FolderID;
221 public LLUUID OwnerID;
222 public LLUUID ParentID = LLUUID.Zero;
223 public string FolderName;
224 public ushort DefaultType;
225 public ushort Version;
226
227 public InventoryFolder()
228 {
229 Items = new List<InventoryItem>();
230 //Subfolders = new List<InventoryFolder>();
231 }
232
233 }
234
235 public class InventoryItem
236 {
237 public LLUUID FolderID;
238 public LLUUID OwnerID;
239 public LLUUID ItemID;
240 public LLUUID AssetID;
241 public LLUUID CreatorID;
242 public sbyte InvType;
243 public sbyte Type;
244 public string Name ="";
245 public string Description;
246
247 public InventoryItem()
248 {
249 this.CreatorID = LLUUID.Zero;
250 }
251
252 public string ExportString()
253 {
254 string typ = "notecard";
255 string result = "";
256 result += "\tinv_object\t0\n\t{\n";
257 result += "\t\tobj_id\t%s\n";
258 result += "\t\tparent_id\t"+ ItemID.ToString() +"\n";
259 result += "\t\ttype\t"+ typ +"\n";
260 result += "\t\tname\t" + Name+"|\n";
261 result += "\t}\n";
262 return result;
263 }
264 }
265}