diff options
Diffstat (limited to 'OpenSim/Services/HypergridService/HGInventoryService.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/HGInventoryService.cs | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs new file mode 100644 index 0000000..a04f0c4 --- /dev/null +++ b/OpenSim/Services/HypergridService/HGInventoryService.cs | |||
@@ -0,0 +1,333 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using System.Reflection; | ||
34 | using OpenSim.Services.Base; | ||
35 | using OpenSim.Services.Interfaces; | ||
36 | using OpenSim.Services.InventoryService; | ||
37 | using OpenSim.Data; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Server.Base; | ||
40 | |||
41 | namespace OpenSim.Services.HypergridService | ||
42 | { | ||
43 | public class HGInventoryService : XInventoryService, IInventoryService | ||
44 | { | ||
45 | private static readonly ILog m_log = | ||
46 | LogManager.GetLogger( | ||
47 | MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | protected new IXInventoryData m_Database; | ||
50 | |||
51 | private string m_ProfileServiceURL; | ||
52 | private IUserAccountService m_UserAccountService; | ||
53 | |||
54 | private UserAccountCache m_Cache; | ||
55 | |||
56 | public HGInventoryService(IConfigSource config) | ||
57 | : base(config) | ||
58 | { | ||
59 | m_log.Debug("[HGInventory Service]: Starting"); | ||
60 | |||
61 | string dllName = String.Empty; | ||
62 | string connString = String.Empty; | ||
63 | //string realm = "Inventory"; // OSG version doesn't use this | ||
64 | |||
65 | // | ||
66 | // Try reading the [DatabaseService] section, if it exists | ||
67 | // | ||
68 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
69 | if (dbConfig != null) | ||
70 | { | ||
71 | if (dllName == String.Empty) | ||
72 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
73 | if (connString == String.Empty) | ||
74 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
75 | } | ||
76 | |||
77 | // | ||
78 | // Try reading the [InventoryService] section, if it exists | ||
79 | // | ||
80 | IConfig invConfig = config.Configs["HGInventoryService"]; | ||
81 | if (invConfig != null) | ||
82 | { | ||
83 | dllName = invConfig.GetString("StorageProvider", dllName); | ||
84 | connString = invConfig.GetString("ConnectionString", connString); | ||
85 | |||
86 | // realm = authConfig.GetString("Realm", realm); | ||
87 | string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty); | ||
88 | if (userAccountsDll == string.Empty) | ||
89 | throw new Exception("Please specify UserAccountsService in HGInventoryService configuration"); | ||
90 | |||
91 | Object[] args = new Object[] { config }; | ||
92 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args); | ||
93 | if (m_UserAccountService == null) | ||
94 | throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll)); | ||
95 | |||
96 | m_ProfileServiceURL = invConfig.GetString("ProfileServerURI", string.Empty); | ||
97 | |||
98 | m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); | ||
99 | } | ||
100 | |||
101 | // | ||
102 | // We tried, but this doesn't exist. We can't proceed. | ||
103 | // | ||
104 | if (dllName == String.Empty) | ||
105 | throw new Exception("No StorageProvider configured"); | ||
106 | |||
107 | m_Database = LoadPlugin<IXInventoryData>(dllName, | ||
108 | new Object[] {connString, String.Empty}); | ||
109 | if (m_Database == null) | ||
110 | throw new Exception("Could not find a storage interface in the given module"); | ||
111 | |||
112 | m_log.Debug("[HG INVENTORY SERVICE]: Starting..."); | ||
113 | } | ||
114 | |||
115 | public override bool CreateUserInventory(UUID principalID) | ||
116 | { | ||
117 | // NOGO | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | |||
122 | public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID) | ||
123 | { | ||
124 | // NOGO for this inventory service | ||
125 | return new List<InventoryFolderBase>(); | ||
126 | } | ||
127 | |||
128 | public override InventoryFolderBase GetRootFolder(UUID principalID) | ||
129 | { | ||
130 | // Warp! Root folder for travelers | ||
131 | XInventoryFolder[] folders = m_Database.GetFolders( | ||
132 | new string[] { "agentID", "folderName"}, | ||
133 | new string[] { principalID.ToString(), "My Suitcase" }); | ||
134 | |||
135 | if (folders.Length > 0) | ||
136 | return ConvertToOpenSim(folders[0]); | ||
137 | |||
138 | // make one | ||
139 | XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Suitcase"); | ||
140 | return ConvertToOpenSim(suitcase); | ||
141 | } | ||
142 | |||
143 | //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase) | ||
144 | //{ | ||
145 | |||
146 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations"); | ||
147 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts"); | ||
148 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards"); | ||
149 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing"); | ||
150 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures"); | ||
151 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks"); | ||
152 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found"); | ||
153 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards"); | ||
154 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects"); | ||
155 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album"); | ||
156 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts"); | ||
157 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds"); | ||
158 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures"); | ||
159 | // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash"); | ||
160 | |||
161 | // return true; | ||
162 | //} | ||
163 | |||
164 | |||
165 | public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) | ||
166 | { | ||
167 | return GetRootFolder(principalID); | ||
168 | } | ||
169 | |||
170 | // | ||
171 | // Use the inherited methods | ||
172 | // | ||
173 | //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) | ||
174 | //{ | ||
175 | //} | ||
176 | |||
177 | //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) | ||
178 | //{ | ||
179 | //} | ||
180 | |||
181 | //public override bool AddFolder(InventoryFolderBase folder) | ||
182 | //{ | ||
183 | // // Check if it's under the Suitcase folder | ||
184 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner); | ||
185 | // InventoryFolderBase suitcase = GetRootFolder(folder.Owner); | ||
186 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
187 | |||
188 | // foreach (InventoryFolderBase f in suitDescendents) | ||
189 | // if (folder.ParentID == f.ID) | ||
190 | // { | ||
191 | // XInventoryFolder xFolder = ConvertFromOpenSim(folder); | ||
192 | // return m_Database.StoreFolder(xFolder); | ||
193 | // } | ||
194 | // return false; | ||
195 | //} | ||
196 | |||
197 | private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root) | ||
198 | { | ||
199 | List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; }); | ||
200 | if (direct == null) | ||
201 | return new List<InventoryFolderBase>(); | ||
202 | |||
203 | List<InventoryFolderBase> indirect = new List<InventoryFolderBase>(); | ||
204 | foreach (InventoryFolderBase f in direct) | ||
205 | indirect.AddRange(GetDescendents(lst, f.ID)); | ||
206 | |||
207 | direct.AddRange(indirect); | ||
208 | return direct; | ||
209 | } | ||
210 | |||
211 | // Use inherited method | ||
212 | //public bool UpdateFolder(InventoryFolderBase folder) | ||
213 | //{ | ||
214 | //} | ||
215 | |||
216 | //public override bool MoveFolder(InventoryFolderBase folder) | ||
217 | //{ | ||
218 | // XInventoryFolder[] x = m_Database.GetFolders( | ||
219 | // new string[] { "folderID" }, | ||
220 | // new string[] { folder.ID.ToString() }); | ||
221 | |||
222 | // if (x.Length == 0) | ||
223 | // return false; | ||
224 | |||
225 | // // Check if it's under the Suitcase folder | ||
226 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner); | ||
227 | // InventoryFolderBase suitcase = GetRootFolder(folder.Owner); | ||
228 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
229 | |||
230 | // foreach (InventoryFolderBase f in suitDescendents) | ||
231 | // if (folder.ParentID == f.ID) | ||
232 | // { | ||
233 | // x[0].parentFolderID = folder.ParentID; | ||
234 | // return m_Database.StoreFolder(x[0]); | ||
235 | // } | ||
236 | |||
237 | // return false; | ||
238 | //} | ||
239 | |||
240 | public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs) | ||
241 | { | ||
242 | // NOGO | ||
243 | return false; | ||
244 | } | ||
245 | |||
246 | public override bool PurgeFolder(InventoryFolderBase folder) | ||
247 | { | ||
248 | // NOGO | ||
249 | return false; | ||
250 | } | ||
251 | |||
252 | // Unfortunately we need to use the inherited method because of how DeRez works. | ||
253 | // The viewer sends the folderID hard-wired in the derez message | ||
254 | //public override bool AddItem(InventoryItemBase item) | ||
255 | //{ | ||
256 | // // Check if it's under the Suitcase folder | ||
257 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner); | ||
258 | // InventoryFolderBase suitcase = GetRootFolder(item.Owner); | ||
259 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
260 | |||
261 | // foreach (InventoryFolderBase f in suitDescendents) | ||
262 | // if (item.Folder == f.ID) | ||
263 | // return m_Database.StoreItem(ConvertFromOpenSim(item)); | ||
264 | |||
265 | // return false; | ||
266 | //} | ||
267 | |||
268 | //public override bool UpdateItem(InventoryItemBase item) | ||
269 | //{ | ||
270 | // // Check if it's under the Suitcase folder | ||
271 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner); | ||
272 | // InventoryFolderBase suitcase = GetRootFolder(item.Owner); | ||
273 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
274 | |||
275 | // foreach (InventoryFolderBase f in suitDescendents) | ||
276 | // if (item.Folder == f.ID) | ||
277 | // return m_Database.StoreItem(ConvertFromOpenSim(item)); | ||
278 | |||
279 | // return false; | ||
280 | //} | ||
281 | |||
282 | //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items) | ||
283 | //{ | ||
284 | // // Principal is b0rked. *sigh* | ||
285 | // // | ||
286 | // // Let's assume they all have the same principal | ||
287 | // // Check if it's under the Suitcase folder | ||
288 | // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner); | ||
289 | // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner); | ||
290 | // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID); | ||
291 | |||
292 | // foreach (InventoryItemBase i in items) | ||
293 | // { | ||
294 | // foreach (InventoryFolderBase f in suitDescendents) | ||
295 | // if (i.Folder == f.ID) | ||
296 | // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString()); | ||
297 | // } | ||
298 | |||
299 | // return true; | ||
300 | //} | ||
301 | |||
302 | // Let these pass. Use inherited methods. | ||
303 | //public bool DeleteItems(UUID principalID, List<UUID> itemIDs) | ||
304 | //{ | ||
305 | //} | ||
306 | |||
307 | public override InventoryItemBase GetItem(InventoryItemBase item) | ||
308 | { | ||
309 | InventoryItemBase it = base.GetItem(item); | ||
310 | |||
311 | UserAccount user = m_Cache.GetUser(it.CreatorId); | ||
312 | |||
313 | // Adjust the creator data | ||
314 | if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) | ||
315 | it.CreatorData = m_ProfileServiceURL + "/" + it.CreatorId + ";" + user.FirstName + " " + user.LastName; | ||
316 | |||
317 | return it; | ||
318 | } | ||
319 | |||
320 | //public InventoryFolderBase GetFolder(InventoryFolderBase folder) | ||
321 | //{ | ||
322 | //} | ||
323 | |||
324 | //public List<InventoryItemBase> GetActiveGestures(UUID principalID) | ||
325 | //{ | ||
326 | //} | ||
327 | |||
328 | //public int GetAssetPermissions(UUID principalID, UUID assetID) | ||
329 | //{ | ||
330 | //} | ||
331 | |||
332 | } | ||
333 | } | ||