opensim-development – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 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 /// <summary>
44 /// Hypergrid inventory service. It serves the IInventoryService interface,
45 /// but implements it in ways that are appropriate for inter-grid
46 /// inventory exchanges. Specifically, it does not performs deletions
47 /// and it responds to GetRootFolder requests with the ID of the
48 /// Suitcase folder, not the actual "My Inventory" folder.
49 /// </summary>
50 public class HGInventoryService : XInventoryService, IInventoryService
51 {
52 private static readonly ILog m_log =
53 LogManager.GetLogger(
54 MethodBase.GetCurrentMethod().DeclaringType);
55  
56 private string m_HomeURL;
57 private IUserAccountService m_UserAccountService;
58  
59 private UserAccountCache m_Cache;
60  
61 public HGInventoryService(IConfigSource config, string configName)
62 : base(config, configName)
63 {
64 m_log.Debug("[HGInventory Service]: Starting");
65 if (configName != string.Empty)
66 m_ConfigName = configName;
67  
68 //
69 // Try reading the [InventoryService] section, if it exists
70 //
71 IConfig invConfig = config.Configs[m_ConfigName];
72 if (invConfig != null)
73 {
74 // realm = authConfig.GetString("Realm", realm);
75 string userAccountsDll = invConfig.GetString("UserAccountsService", string.Empty);
76 if (userAccountsDll == string.Empty)
77 throw new Exception("Please specify UserAccountsService in HGInventoryService configuration");
78  
79 Object[] args = new Object[] { config };
80 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
81 if (m_UserAccountService == null)
82 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
83  
84 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
85 new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
86  
87 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
88 }
89  
90 m_log.Debug("[HG INVENTORY SERVICE]: Starting...");
91 }
92  
93 public override bool CreateUserInventory(UUID principalID)
94 {
95 // NOGO
96 return false;
97 }
98  
99  
100 public override List<InventoryFolderBase> GetInventorySkeleton(UUID principalID)
101 {
102 // NOGO for this inventory service
103 return new List<InventoryFolderBase>();
104 }
105  
106 public override InventoryCollection GetUserInventory(UUID userID)
107 {
108 // NOGO for this inventory service
109 return null;
110 }
111  
112 public override InventoryFolderBase GetRootFolder(UUID principalID)
113 {
114 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
115 // Warp! Root folder for travelers
116 XInventoryFolder[] folders = m_Database.GetFolders(
117 new string[] { "agentID", "folderName"},
118 new string[] { principalID.ToString(), "My Suitcase" });
119  
120 if (folders.Length > 0)
121 return ConvertToOpenSim(folders[0]);
122  
123 // make one
124 XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Suitcase");
125 return ConvertToOpenSim(suitcase);
126 }
127  
128 //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase)
129 //{
130  
131 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations");
132 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts");
133 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards");
134 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing");
135 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures");
136 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks");
137 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
138 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards");
139 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects");
140 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album");
141 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts");
142 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds");
143 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures");
144 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash");
145  
146 // return true;
147 //}
148  
149  
150 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
151 {
152 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
153 return GetRootFolder(principalID);
154 }
155  
156 //
157 // Use the inherited methods
158 //
159 //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
160 //{
161 //}
162  
163 //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
164 //{
165 //}
166  
167 //public override bool AddFolder(InventoryFolderBase folder)
168 //{
169 // // Check if it's under the Suitcase folder
170 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
171 // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
172 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
173  
174 // foreach (InventoryFolderBase f in suitDescendents)
175 // if (folder.ParentID == f.ID)
176 // {
177 // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
178 // return m_Database.StoreFolder(xFolder);
179 // }
180 // return false;
181 //}
182  
183 private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
184 {
185 List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
186 if (direct == null)
187 return new List<InventoryFolderBase>();
188  
189 List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
190 foreach (InventoryFolderBase f in direct)
191 indirect.AddRange(GetDescendents(lst, f.ID));
192  
193 direct.AddRange(indirect);
194 return direct;
195 }
196  
197 // Use inherited method
198 //public bool UpdateFolder(InventoryFolderBase folder)
199 //{
200 //}
201  
202 //public override bool MoveFolder(InventoryFolderBase folder)
203 //{
204 // XInventoryFolder[] x = m_Database.GetFolders(
205 // new string[] { "folderID" },
206 // new string[] { folder.ID.ToString() });
207  
208 // if (x.Length == 0)
209 // return false;
210  
211 // // Check if it's under the Suitcase folder
212 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
213 // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
214 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
215  
216 // foreach (InventoryFolderBase f in suitDescendents)
217 // if (folder.ParentID == f.ID)
218 // {
219 // x[0].parentFolderID = folder.ParentID;
220 // return m_Database.StoreFolder(x[0]);
221 // }
222  
223 // return false;
224 //}
225  
226 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
227 {
228 // NOGO
229 return false;
230 }
231  
232 public override bool PurgeFolder(InventoryFolderBase folder)
233 {
234 // NOGO
235 return false;
236 }
237  
238 // Unfortunately we need to use the inherited method because of how DeRez works.
239 // The viewer sends the folderID hard-wired in the derez message
240 //public override bool AddItem(InventoryItemBase item)
241 //{
242 // // Check if it's under the Suitcase folder
243 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
244 // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
245 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
246  
247 // foreach (InventoryFolderBase f in suitDescendents)
248 // if (item.Folder == f.ID)
249 // return m_Database.StoreItem(ConvertFromOpenSim(item));
250  
251 // return false;
252 //}
253  
254 //public override bool UpdateItem(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 MoveItems(UUID principalID, List<InventoryItemBase> items)
269 //{
270 // // Principal is b0rked. *sigh*
271 // //
272 // // Let's assume they all have the same principal
273 // // Check if it's under the Suitcase folder
274 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
275 // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
276 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
277  
278 // foreach (InventoryItemBase i in items)
279 // {
280 // foreach (InventoryFolderBase f in suitDescendents)
281 // if (i.Folder == f.ID)
282 // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
283 // }
284  
285 // return true;
286 //}
287  
288 // Let these pass. Use inherited methods.
289 //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
290 //{
291 //}
292  
293 public override InventoryItemBase GetItem(InventoryItemBase item)
294 {
295 InventoryItemBase it = base.GetItem(item);
296 if (it != null)
297 {
298 UserAccount user = m_Cache.GetUser(it.CreatorId);
299  
300 // Adjust the creator data
301 if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
302 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
303 }
304 return it;
305 }
306  
307 //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
308 //{
309 //}
310  
311 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
312 //{
313 //}
314  
315 //public int GetAssetPermissions(UUID principalID, UUID assetID)
316 //{
317 //}
318  
319 }
320 }