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