aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/InventoryManager.cs
diff options
context:
space:
mode:
authorMW2007-02-03 19:51:52 +0000
committerMW2007-02-03 19:51:52 +0000
commit3a157273da7de6caa098ac4af406e37be02a1171 (patch)
treeb30b6a30a7e84ebe2dcff80e9d0207b8495f1173 /InventoryManager.cs
parent(no commit message) (diff)
downloadopensim-SC-3a157273da7de6caa098ac4af406e37be02a1171.zip
opensim-SC-3a157273da7de6caa098ac4af406e37be02a1171.tar.gz
opensim-SC-3a157273da7de6caa098ac4af406e37be02a1171.tar.bz2
opensim-SC-3a157273da7de6caa098ac4af406e37be02a1171.tar.xz
Added Basic Inventory support
Diffstat (limited to 'InventoryManager.cs')
-rw-r--r--InventoryManager.cs240
1 files changed, 240 insertions, 0 deletions
diff --git a/InventoryManager.cs b/InventoryManager.cs
new file mode 100644
index 0000000..bbc340e
--- /dev/null
+++ b/InventoryManager.cs
@@ -0,0 +1,240 @@
1/*
2Copyright (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
27using System;
28using System.Collections.Generic;
29using libsecondlife;
30using libsecondlife.Packets;
31using libsecondlife.AssetSystem;
32using System.IO;
33
34namespace OpenSim
35{
36 /// <summary>
37 /// Description of InventoryManager.
38 /// </summary>
39 public class InventoryManager
40 {
41 private System.Text.Encoding enc = System.Text.Encoding.ASCII;
42 public Dictionary<LLUUID, InventoryFolder> Folders;
43 public Dictionary<LLUUID, InventoryItem> Items;
44 private Server server;
45
46 /// <summary>
47 ///
48 /// </summary>
49 /// <param name="serve"></param>
50 public InventoryManager(Server serve)
51 {
52 server=serve;
53 Folders=new Dictionary<LLUUID, InventoryFolder>();
54 Items=new Dictionary<LLUUID, InventoryItem>();
55 }
56
57 /// <summary>
58 ///
59 /// </summary>
60 /// <param name="UserInfo"></param>
61 /// <param name="FolderID"></param>
62 /// <param name="Asset"></param>
63 /// <returns></returns>
64 public LLUUID AddToInventory(User_Agent_info UserInfo, LLUUID FolderID,AssetBase Asset)
65 {
66 if(this.Folders.ContainsKey(FolderID))
67 {
68 LLUUID NewItemID=LLUUID.Random();
69
70 InventoryItem Item=new InventoryItem();
71 Item.FolderID=FolderID;
72 Item.OwnerID=UserInfo.AgentID;
73 Item.AssetID=Asset.Full_ID;
74 Item.ItemID=NewItemID;
75 Item.Type=Asset.Type;
76 Item.Name=Asset.Name;
77 Item.Description=Asset.Description;
78 Item.InvType=Asset.InvType;
79 this.Items.Add(Item.ItemID,Item);
80 InventoryFolder Folder=Folders[Item.FolderID];
81 Folder.Items.Add(Item);
82 return(Item.ItemID);
83 }
84 else
85 {
86 return(null);
87 }
88 }
89
90 /// <summary>
91 ///
92 /// </summary>
93 /// <param name="UserInfo"></param>
94 /// <param name="NewFolder"></param>
95 /// <returns></returns>
96 public bool CreateNewFolder(User_Agent_info UserInfo, LLUUID NewFolder)
97 {
98 InventoryFolder Folder=new InventoryFolder();
99 Folder.FolderID=NewFolder;
100 Folder.OwnerID=UserInfo.AgentID;
101 this.Folders.Add(Folder.FolderID,Folder);
102
103 return(true);
104 }
105
106 /// <summary>
107 ///
108 /// </summary>
109 /// <param name="User_info"></param>
110 /// <param name="FetchDescend"></param>
111 public void FetchInventoryDescendents(User_Agent_info User_info,FetchInventoryDescendentsPacket FetchDescend)
112 {
113 if(FetchDescend.InventoryData.FetchItems)
114 {
115 if(this.Folders.ContainsKey(FetchDescend.InventoryData.FolderID))
116 {
117
118 InventoryFolder Folder=this.Folders[FetchDescend.InventoryData.FolderID];
119 InventoryDescendentsPacket Descend=new InventoryDescendentsPacket();
120 Descend.AgentData.AgentID=User_info.AgentID;
121 Descend.AgentData.OwnerID=Folder.OwnerID;//User_info.AgentID;
122 Descend.AgentData.FolderID=FetchDescend.InventoryData.FolderID;//Folder.FolderID;//new LLUUID("4fb2dab6-a987-da66-05ee-96ca82bccbf1");
123 Descend.AgentData.Descendents=Folder.Items.Count;
124 Descend.AgentData.Version=Folder.Items.Count;
125
126 Descend.ItemData=new InventoryDescendentsPacket.ItemDataBlock[Folder.Items.Count];
127 for(int i=0; i<Folder.Items.Count ; i++)
128 {
129
130 InventoryItem Item=Folder.Items[i];
131 Descend.ItemData[i]=new InventoryDescendentsPacket.ItemDataBlock();
132 Descend.ItemData[i].ItemID=Item.ItemID;//new LLUUID("b7878441893b094917f791174bc8401c");
133 Descend.ItemData[i].AssetID=Item.AssetID;//new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
134 Descend.ItemData[i].CreatorID=Item.CreatorID;//User_info.AgentID;
135 Descend.ItemData[i].BaseMask=2147483647;
136 Descend.ItemData[i].CreationDate=1000;
137 Descend.ItemData[i].Description=enc.GetBytes(Item.Description+"\0");
138 Descend.ItemData[i].EveryoneMask=2147483647;;
139 Descend.ItemData[i].Flags=1;
140 Descend.ItemData[i].FolderID=Item.FolderID;//new LLUUID("4fb2dab6-a987-da66-05ee-96ca82bccbf1");
141 Descend.ItemData[i].GroupID=new LLUUID("00000000-0000-0000-0000-000000000000");
142 Descend.ItemData[i].GroupMask=2147483647;
143 Descend.ItemData[i].InvType=Item.InvType;
144 Descend.ItemData[i].Name=enc.GetBytes(Item.Name+"\0");
145 Descend.ItemData[i].NextOwnerMask=2147483647;
146 Descend.ItemData[i].OwnerID=Item.OwnerID;//User_info.AgentID;
147 Descend.ItemData[i].OwnerMask=2147483647;;
148 Descend.ItemData[i].SalePrice=100;
149 Descend.ItemData[i].SaleType=0;
150 Descend.ItemData[i].Type=Item.Type;//libsecondlife.AssetSystem.Asset.ASSET_TYPE_WEARABLE_BODY;
151 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,2147483647,1,2147483647,2147483647,2147483647);
152 }
153 server.SendPacket(Descend,true,User_info);
154
155 }
156 }
157 else
158 {
159 Console.WriteLine("fetch subfolders");
160 }
161 }
162
163 /// <summary>
164 ///
165 /// </summary>
166 /// <param name="User_info"></param>
167 public void FetchInventory(User_Agent_info User_info, FetchInventoryPacket FetchItems)
168 {
169
170 for(int i=0; i<FetchItems.InventoryData.Length; i++)
171 {
172 if(this.Items.ContainsKey(FetchItems.InventoryData[i].ItemID))
173 {
174
175 InventoryItem Item=Items[FetchItems.InventoryData[i].ItemID];
176 FetchInventoryReplyPacket InventoryReply=new FetchInventoryReplyPacket();
177 InventoryReply.AgentData.AgentID=User_info.AgentID;
178 InventoryReply.InventoryData=new FetchInventoryReplyPacket.InventoryDataBlock[1];
179 InventoryReply.InventoryData[0]=new FetchInventoryReplyPacket.InventoryDataBlock();
180 InventoryReply.InventoryData[0].ItemID=Item.ItemID;//new LLUUID("b7878441893b094917f791174bc8401c");
181 InventoryReply.InventoryData[0].AssetID=Item.AssetID;//new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
182 InventoryReply.InventoryData[0].CreatorID=Item.CreatorID;//User_info.AgentID;
183 InventoryReply.InventoryData[0].BaseMask=2147483647;
184 InventoryReply.InventoryData[0].CreationDate=1000;
185 InventoryReply.InventoryData[0].Description=enc.GetBytes( Item.Description+"\0");
186 InventoryReply.InventoryData[0].EveryoneMask=2147483647;;
187 InventoryReply.InventoryData[0].Flags=1;
188 InventoryReply.InventoryData[0].FolderID=Item.FolderID;//new LLUUID("4fb2dab6-a987-da66-05ee-96ca82bccbf1");
189 InventoryReply.InventoryData[0].GroupID=new LLUUID("00000000-0000-0000-0000-000000000000");
190 InventoryReply.InventoryData[0].GroupMask=2147483647;
191 InventoryReply.InventoryData[0].InvType=Item.InvType;
192 InventoryReply.InventoryData[0].Name=enc.GetBytes(Item.Name+"\0");
193 InventoryReply.InventoryData[0].NextOwnerMask=2147483647;
194 InventoryReply.InventoryData[0].OwnerID=Item.OwnerID;//User_info.AgentID;
195 InventoryReply.InventoryData[0].OwnerMask=2147483647;;
196 InventoryReply.InventoryData[0].SalePrice=100;
197 InventoryReply.InventoryData[0].SaleType=0;
198 InventoryReply.InventoryData[0].Type=Item.Type;//libsecondlife.AssetSystem.Asset.ASSET_TYPE_WEARABLE_BODY;
199 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,2147483647,1,2147483647,2147483647,2147483647);
200 server.SendPacket(InventoryReply,true,User_info);
201 }
202 }
203 }
204 }
205
206 public class InventoryFolder
207 {
208 public List<InventoryItem> Items;
209 //public List<InventoryFolder> Subfolders;
210
211 public LLUUID FolderID;
212 public LLUUID OwnerID;
213 public LLUUID ParentID;
214
215
216 public InventoryFolder()
217 {
218 Items=new List<InventoryItem>();
219 }
220
221 }
222
223 public class InventoryItem
224 {
225 public LLUUID FolderID;
226 public LLUUID OwnerID;
227 public LLUUID ItemID;
228 public LLUUID AssetID;
229 public LLUUID CreatorID=LLUUID.Zero;//new LLUUID("3d924400-038e-6ad9-920b-cfbb9b40585c");
230 public sbyte InvType;
231 public sbyte Type;
232 public string Name;
233 public string Description;
234
235 public InventoryItem()
236 {
237
238 }
239 }
240}