clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 InventoryFolderBase GetRootFolder(UUID principalID)
107 {
108 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
109 // Warp! Root folder for travelers
110 XInventoryFolder[] folders = m_Database.GetFolders(
111 new string[] { "agentID", "folderName"},
112 new string[] { principalID.ToString(), "My Suitcase" });
113  
114 if (folders.Length > 0)
115 return ConvertToOpenSim(folders[0]);
116  
117 // make one
118 XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Suitcase");
119 return ConvertToOpenSim(suitcase);
120 }
121  
122 //private bool CreateSystemFolders(UUID principalID, XInventoryFolder suitcase)
123 //{
124  
125 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Animation, "Animations");
126 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Bodypart, "Body Parts");
127 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.CallingCard, "Calling Cards");
128 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Clothing, "Clothing");
129 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Gesture, "Gestures");
130 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Landmark, "Landmarks");
131 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LostAndFoundFolder, "Lost And Found");
132 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Notecard, "Notecards");
133 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Object, "Objects");
134 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.SnapshotFolder, "Photo Album");
135 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.LSLText, "Scripts");
136 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Sound, "Sounds");
137 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.Texture, "Textures");
138 // CreateFolder(principalID, suitcase.folderID, (int)AssetType.TrashFolder, "Trash");
139  
140 // return true;
141 //}
142  
143  
144 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type)
145 {
146 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
147 return GetRootFolder(principalID);
148 }
149  
150 //
151 // Use the inherited methods
152 //
153 //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
154 //{
155 //}
156  
157 //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
158 //{
159 //}
160  
161 //public override bool AddFolder(InventoryFolderBase folder)
162 //{
163 // // Check if it's under the Suitcase folder
164 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
165 // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
166 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
167  
168 // foreach (InventoryFolderBase f in suitDescendents)
169 // if (folder.ParentID == f.ID)
170 // {
171 // XInventoryFolder xFolder = ConvertFromOpenSim(folder);
172 // return m_Database.StoreFolder(xFolder);
173 // }
174 // return false;
175 //}
176  
177 private List<InventoryFolderBase> GetDescendents(List<InventoryFolderBase> lst, UUID root)
178 {
179 List<InventoryFolderBase> direct = lst.FindAll(delegate(InventoryFolderBase f) { return f.ParentID == root; });
180 if (direct == null)
181 return new List<InventoryFolderBase>();
182  
183 List<InventoryFolderBase> indirect = new List<InventoryFolderBase>();
184 foreach (InventoryFolderBase f in direct)
185 indirect.AddRange(GetDescendents(lst, f.ID));
186  
187 direct.AddRange(indirect);
188 return direct;
189 }
190  
191 // Use inherited method
192 //public bool UpdateFolder(InventoryFolderBase folder)
193 //{
194 //}
195  
196 //public override bool MoveFolder(InventoryFolderBase folder)
197 //{
198 // XInventoryFolder[] x = m_Database.GetFolders(
199 // new string[] { "folderID" },
200 // new string[] { folder.ID.ToString() });
201  
202 // if (x.Length == 0)
203 // return false;
204  
205 // // Check if it's under the Suitcase folder
206 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(folder.Owner);
207 // InventoryFolderBase suitcase = GetRootFolder(folder.Owner);
208 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
209  
210 // foreach (InventoryFolderBase f in suitDescendents)
211 // if (folder.ParentID == f.ID)
212 // {
213 // x[0].parentFolderID = folder.ParentID;
214 // return m_Database.StoreFolder(x[0]);
215 // }
216  
217 // return false;
218 //}
219  
220 public override bool DeleteFolders(UUID principalID, List<UUID> folderIDs)
221 {
222 // NOGO
223 return false;
224 }
225  
226 public override bool PurgeFolder(InventoryFolderBase folder)
227 {
228 // NOGO
229 return false;
230 }
231  
232 // Unfortunately we need to use the inherited method because of how DeRez works.
233 // The viewer sends the folderID hard-wired in the derez message
234 //public override bool AddItem(InventoryItemBase item)
235 //{
236 // // Check if it's under the Suitcase folder
237 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
238 // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
239 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
240  
241 // foreach (InventoryFolderBase f in suitDescendents)
242 // if (item.Folder == f.ID)
243 // return m_Database.StoreItem(ConvertFromOpenSim(item));
244  
245 // return false;
246 //}
247  
248 //public override bool UpdateItem(InventoryItemBase item)
249 //{
250 // // Check if it's under the Suitcase folder
251 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(item.Owner);
252 // InventoryFolderBase suitcase = GetRootFolder(item.Owner);
253 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
254  
255 // foreach (InventoryFolderBase f in suitDescendents)
256 // if (item.Folder == f.ID)
257 // return m_Database.StoreItem(ConvertFromOpenSim(item));
258  
259 // return false;
260 //}
261  
262 //public override bool MoveItems(UUID principalID, List<InventoryItemBase> items)
263 //{
264 // // Principal is b0rked. *sigh*
265 // //
266 // // Let's assume they all have the same principal
267 // // Check if it's under the Suitcase folder
268 // List<InventoryFolderBase> skel = base.GetInventorySkeleton(items[0].Owner);
269 // InventoryFolderBase suitcase = GetRootFolder(items[0].Owner);
270 // List<InventoryFolderBase> suitDescendents = GetDescendents(skel, suitcase.ID);
271  
272 // foreach (InventoryItemBase i in items)
273 // {
274 // foreach (InventoryFolderBase f in suitDescendents)
275 // if (i.Folder == f.ID)
276 // m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString());
277 // }
278  
279 // return true;
280 //}
281  
282 // Let these pass. Use inherited methods.
283 //public bool DeleteItems(UUID principalID, List<UUID> itemIDs)
284 //{
285 //}
286  
287 public override InventoryItemBase GetItem(InventoryItemBase item)
288 {
289 InventoryItemBase it = base.GetItem(item);
290 if (it != null)
291 {
292 UserAccount user = m_Cache.GetUser(it.CreatorId);
293  
294 // Adjust the creator data
295 if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
296 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
297 }
298 return it;
299 }
300  
301 //public InventoryFolderBase GetFolder(InventoryFolderBase folder)
302 //{
303 //}
304  
305 //public List<InventoryItemBase> GetActiveGestures(UUID principalID)
306 //{
307 //}
308  
309 //public int GetAssetPermissions(UUID principalID, UUID assetID)
310 //{
311 //}
312  
313 }
314 }