aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/GatekeeperService.cs121
-rw-r--r--OpenSim/Services/HypergridService/HGAssetService.cs34
-rw-r--r--OpenSim/Services/HypergridService/HGFSAssetService.cs189
-rw-r--r--OpenSim/Services/HypergridService/HGFriendsService.cs3
-rw-r--r--OpenSim/Services/HypergridService/HGInstantMessageService.cs19
-rw-r--r--OpenSim/Services/HypergridService/HGInventoryService.cs27
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs258
-rw-r--r--OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs4
-rw-r--r--OpenSim/Services/HypergridService/UserAccountCache.cs7
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs259
-rw-r--r--OpenSim/Services/HypergridService/UserAgentServiceBase.cs84
11 files changed, 738 insertions, 267 deletions
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs
index 7b84d55..8e10125 100644
--- a/OpenSim/Services/HypergridService/GatekeeperService.cs
+++ b/OpenSim/Services/HypergridService/GatekeeperService.cs
@@ -1,4 +1,4 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
@@ -58,6 +58,7 @@ namespace OpenSim.Services.HypergridService
58 private static IUserAgentService m_UserAgentService; 58 private static IUserAgentService m_UserAgentService;
59 private static ISimulationService m_SimulationService; 59 private static ISimulationService m_SimulationService;
60 private static IGridUserService m_GridUserService; 60 private static IGridUserService m_GridUserService;
61 private static IBansService m_BansService;
61 62
62 private static string m_AllowedClients = string.Empty; 63 private static string m_AllowedClients = string.Empty;
63 private static string m_DeniedClients = string.Empty; 64 private static string m_DeniedClients = string.Empty;
@@ -87,6 +88,7 @@ namespace OpenSim.Services.HypergridService
87 string presenceService = serverConfig.GetString("PresenceService", String.Empty); 88 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
88 string simulationService = serverConfig.GetString("SimulationService", String.Empty); 89 string simulationService = serverConfig.GetString("SimulationService", String.Empty);
89 string gridUserService = serverConfig.GetString("GridUserService", String.Empty); 90 string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
91 string bansService = serverConfig.GetString("BansService", String.Empty);
90 92
91 // These are mandatory, the others aren't 93 // These are mandatory, the others aren't
92 if (gridService == string.Empty || presenceService == string.Empty) 94 if (gridService == string.Empty || presenceService == string.Empty)
@@ -96,7 +98,9 @@ namespace OpenSim.Services.HypergridService
96 UUID.TryParse(scope, out m_ScopeID); 98 UUID.TryParse(scope, out m_ScopeID);
97 //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!"); 99 //m_WelcomeMessage = serverConfig.GetString("WelcomeMessage", "Welcome to OpenSim!");
98 m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true); 100 m_AllowTeleportsToAnyRegion = serverConfig.GetBoolean("AllowTeleportsToAnyRegion", true);
99 m_ExternalName = serverConfig.GetString("ExternalName", string.Empty); 101 m_ExternalName = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
102 new string[] { "Startup", "Hypergrid", "GatekeeperService" }, String.Empty);
103 m_ExternalName = serverConfig.GetString("ExternalName", m_ExternalName);
100 if (m_ExternalName != string.Empty && !m_ExternalName.EndsWith("/")) 104 if (m_ExternalName != string.Empty && !m_ExternalName.EndsWith("/"))
101 m_ExternalName = m_ExternalName + "/"; 105 m_ExternalName = m_ExternalName + "/";
102 106
@@ -119,14 +123,19 @@ namespace OpenSim.Services.HypergridService
119 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args); 123 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
120 if (gridUserService != string.Empty) 124 if (gridUserService != string.Empty)
121 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args); 125 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
126 if (bansService != string.Empty)
127 m_BansService = ServerUtils.LoadPlugin<IBansService>(bansService, args);
122 128
123 if (simService != null) 129 if (simService != null)
124 m_SimulationService = simService; 130 m_SimulationService = simService;
125 else if (simulationService != string.Empty) 131 else if (simulationService != string.Empty)
126 m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args); 132 m_SimulationService = ServerUtils.LoadPlugin<ISimulationService>(simulationService, args);
127 133
128 m_AllowedClients = serverConfig.GetString("AllowedClients", string.Empty); 134 string[] possibleAccessControlConfigSections = new string[] { "AccessControl", "GatekeeperService" };
129 m_DeniedClients = serverConfig.GetString("DeniedClients", string.Empty); 135 m_AllowedClients = Util.GetConfigVarFromSections<string>(
136 config, "AllowedClients", possibleAccessControlConfigSections, string.Empty);
137 m_DeniedClients = Util.GetConfigVarFromSections<string>(
138 config, "DeniedClients", possibleAccessControlConfigSections, string.Empty);
130 m_ForeignAgentsAllowed = serverConfig.GetBoolean("ForeignAgentsAllowed", true); 139 m_ForeignAgentsAllowed = serverConfig.GetBoolean("ForeignAgentsAllowed", true);
131 140
132 LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_ForeignsAllowedExceptions); 141 LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_ForeignsAllowedExceptions);
@@ -165,7 +174,7 @@ namespace OpenSim.Services.HypergridService
165 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName); 174 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName);
166 if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty) 175 if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty)
167 { 176 {
168 List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); 177 List<GridRegion> defs = m_GridService.GetDefaultHypergridRegions(m_ScopeID);
169 if (defs != null && defs.Count > 0) 178 if (defs != null && defs.Count > 0)
170 { 179 {
171 region = defs[0]; 180 region = defs[0];
@@ -198,41 +207,75 @@ namespace OpenSim.Services.HypergridService
198 return true; 207 return true;
199 } 208 }
200 209
201 public GridRegion GetHyperlinkRegion(UUID regionID) 210 public GridRegion GetHyperlinkRegion(UUID regionID, UUID agentID, string agentHomeURI, out string message)
202 { 211 {
203 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to get hyperlink region {0}", regionID); 212 message = null;
204 213
205 if (!m_AllowTeleportsToAnyRegion) 214 if (!m_AllowTeleportsToAnyRegion)
215 {
206 // Don't even check the given regionID 216 // Don't even check the given regionID
217 m_log.DebugFormat(
218 "[GATEKEEPER SERVICE]: Returning gateway region {0} {1} @ {2} to user {3}{4} as teleporting to arbitrary regions is not allowed.",
219 m_DefaultGatewayRegion.RegionName,
220 m_DefaultGatewayRegion.RegionID,
221 m_DefaultGatewayRegion.ServerURI,
222 agentID,
223 agentHomeURI == null ? "" : " @ " + agentHomeURI);
224
225 message = "Teleporting to the default region.";
207 return m_DefaultGatewayRegion; 226 return m_DefaultGatewayRegion;
227 }
208 228
209 GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID); 229 GridRegion region = m_GridService.GetRegionByUUID(m_ScopeID, regionID);
230
231 if (region == null)
232 {
233 m_log.DebugFormat(
234 "[GATEKEEPER SERVICE]: Could not find region with ID {0} as requested by user {1}{2}. Returning null.",
235 regionID, agentID, (agentHomeURI == null) ? "" : " @ " + agentHomeURI);
236
237 message = "The teleport destination could not be found.";
238 return null;
239 }
240
241 m_log.DebugFormat(
242 "[GATEKEEPER SERVICE]: Returning region {0} {1} @ {2} to user {3}{4}.",
243 region.RegionName,
244 region.RegionID,
245 region.ServerURI,
246 agentID,
247 agentHomeURI == null ? "" : " @ " + agentHomeURI);
248
210 return region; 249 return region;
211 } 250 }
212 251
213 #region Login Agent 252 #region Login Agent
214 public bool LoginAgent(AgentCircuitData aCircuit, GridRegion destination, out string reason) 253 public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason)
215 { 254 {
216 reason = string.Empty; 255 reason = string.Empty;
217 256
218 string authURL = string.Empty; 257 string authURL = string.Empty;
219 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 258 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
220 authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); 259 authURL = aCircuit.ServiceURLs["HomeURI"].ToString();
221 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9} Teleport Flags {10}", 260
222 aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName, 261 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9}, Teleport Flags: {10}. From region {11}",
223 aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, aCircuit.teleportFlags.ToString()); 262 aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID,
224 263 aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags,
264 (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI));
265
266 string curViewer = Util.GetViewerName(aCircuit);
267
225 // 268 //
226 // Check client 269 // Check client
227 // 270 //
228 if (m_AllowedClients != string.Empty) 271 if (m_AllowedClients != string.Empty)
229 { 272 {
230 Regex arx = new Regex(m_AllowedClients); 273 Regex arx = new Regex(m_AllowedClients);
231 Match am = arx.Match(aCircuit.Viewer); 274 Match am = arx.Match(curViewer);
232 275
233 if (!am.Success) 276 if (!am.Success)
234 { 277 {
235 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", aCircuit.Viewer); 278 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer);
236 return false; 279 return false;
237 } 280 }
238 } 281 }
@@ -240,11 +283,11 @@ namespace OpenSim.Services.HypergridService
240 if (m_DeniedClients != string.Empty) 283 if (m_DeniedClients != string.Empty)
241 { 284 {
242 Regex drx = new Regex(m_DeniedClients); 285 Regex drx = new Regex(m_DeniedClients);
243 Match dm = drx.Match(aCircuit.Viewer); 286 Match dm = drx.Match(curViewer);
244 287
245 if (dm.Success) 288 if (dm.Success)
246 { 289 {
247 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", aCircuit.Viewer); 290 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer);
248 return false; 291 return false;
249 } 292 }
250 } 293 }
@@ -285,17 +328,16 @@ namespace OpenSim.Services.HypergridService
285 } 328 }
286 } 329 }
287 } 330 }
288 m_log.DebugFormat("[GATEKEEPER SERVICE]: User is ok");
289 331
290 // 332 //
291 // Foreign agents allowed? Exceptions? 333 // Foreign agents allowed? Exceptions?
292 // 334 //
293 if (account == null) 335 if (account == null)
294 { 336 {
295 bool allowed = m_ForeignAgentsAllowed; 337 bool allowed = m_ForeignAgentsAllowed;
296 338
297 if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions)) 339 if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions))
298 allowed = false; 340 allowed = false;
299 341
300 if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions)) 342 if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions))
301 allowed = true; 343 allowed = true;
@@ -309,6 +351,20 @@ namespace OpenSim.Services.HypergridService
309 } 351 }
310 } 352 }
311 353
354 //
355 // Is the user banned?
356 // This uses a Ban service that's more powerful than the configs
357 //
358 string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
359 if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
360 {
361 reason = "You are banned from this world";
362 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
363 return false;
364 }
365
366 m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name);
367
312 bool isFirstLogin = false; 368 bool isFirstLogin = false;
313 // 369 //
314 // Login the presence, if it's not there yet (by the login service) 370 // Login the presence, if it's not there yet (by the login service)
@@ -326,7 +382,8 @@ namespace OpenSim.Services.HypergridService
326 aCircuit.firstname, aCircuit.lastname); 382 aCircuit.firstname, aCircuit.lastname);
327 return false; 383 return false;
328 } 384 }
329 m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok"); 385
386 m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);
330 387
331 // Also login foreigners with GridUser service 388 // Also login foreigners with GridUser service
332 if (m_GridUserService != null && account == null) 389 if (m_GridUserService != null && account == null)
@@ -357,7 +414,9 @@ namespace OpenSim.Services.HypergridService
357 reason = "Destination region not found"; 414 reason = "Destination region not found";
358 return false; 415 return false;
359 } 416 }
360 m_log.DebugFormat("[GATEKEEPER SERVICE]: destination ok: {0}", destination.RegionName); 417
418 m_log.DebugFormat(
419 "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name);
361 420
362 // 421 //
363 // Adjust the visible name 422 // Adjust the visible name
@@ -374,7 +433,7 @@ namespace OpenSim.Services.HypergridService
374 try 433 try
375 { 434 {
376 Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString()); 435 Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString());
377 aCircuit.lastname = "@" + uri.Host; // + ":" + uri.Port; 436 aCircuit.lastname = "@" + uri.Authority;
378 } 437 }
379 catch 438 catch
380 { 439 {
@@ -391,8 +450,16 @@ namespace OpenSim.Services.HypergridService
391 // Preserve our TeleportFlags we have gathered so-far 450 // Preserve our TeleportFlags we have gathered so-far
392 loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags; 451 loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags;
393 452
394 m_log.DebugFormat("[GATEKEEPER SERVICE]: launching agent {0}", loginFlag); 453 m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag);
395 return m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, out reason); 454
455 EntityTransferContext ctx = new EntityTransferContext();
456
457 if (!m_SimulationService.QueryAccess(
458 destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(),
459 true, aCircuit.startpos, new List<UUID>(), ctx, out reason))
460 return false;
461
462 return m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, out reason);
396 } 463 }
397 464
398 protected bool Authenticate(AgentCircuitData aCircuit) 465 protected bool Authenticate(AgentCircuitData aCircuit)
@@ -400,6 +467,12 @@ namespace OpenSim.Services.HypergridService
400 if (!CheckAddress(aCircuit.ServiceSessionID)) 467 if (!CheckAddress(aCircuit.ServiceSessionID))
401 return false; 468 return false;
402 469
470 if (string.IsNullOrEmpty(aCircuit.IPAddress))
471 {
472 m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide a client IP address.");
473 return false;
474 }
475
403 string userURL = string.Empty; 476 string userURL = string.Empty;
404 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 477 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
405 userURL = aCircuit.ServiceURLs["HomeURI"].ToString(); 478 userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
diff --git a/OpenSim/Services/HypergridService/HGAssetService.cs b/OpenSim/Services/HypergridService/HGAssetService.cs
index 84dec8d..b83fb1e 100644
--- a/OpenSim/Services/HypergridService/HGAssetService.cs
+++ b/OpenSim/Services/HypergridService/HGAssetService.cs
@@ -76,10 +76,10 @@ namespace OpenSim.Services.HypergridService
76 if (m_UserAccountService == null) 76 if (m_UserAccountService == null)
77 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll)); 77 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
78 78
79 // legacy configuration [obsolete] 79 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
80 m_HomeURL = assetConfig.GetString("ProfileServerURI", string.Empty); 80 new string[] { "Startup", "Hypergrid", configName }, string.Empty);
81 // Preferred 81 if (m_HomeURL == string.Empty)
82 m_HomeURL = assetConfig.GetString("HomeURI", m_HomeURL); 82 throw new Exception("[HGAssetService] No HomeURI specified");
83 83
84 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); 84 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
85 85
@@ -100,7 +100,7 @@ namespace OpenSim.Services.HypergridService
100 return null; 100 return null;
101 101
102 if (asset.Metadata.Type == (sbyte)AssetType.Object) 102 if (asset.Metadata.Type == (sbyte)AssetType.Object)
103 asset.Data = AdjustIdentifiers(asset.Data); ; 103 asset.Data = AdjustIdentifiers(asset.Data);
104 104
105 AdjustIdentifiers(asset.Metadata); 105 AdjustIdentifiers(asset.Metadata);
106 106
@@ -129,6 +129,14 @@ namespace OpenSim.Services.HypergridService
129 if (!m_AssetPerms.AllowedExport(asset.Type)) 129 if (!m_AssetPerms.AllowedExport(asset.Type))
130 return null; 130 return null;
131 131
132 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
133 // Fix bad assets before sending them elsewhere
134 if (asset.Type == (int)AssetType.Object && asset.Data != null)
135 {
136 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
137 asset.Data = Utils.StringToBytes(xml);
138 }
139
132 return asset.Data; 140 return asset.Data;
133 } 141 }
134 142
@@ -139,6 +147,14 @@ namespace OpenSim.Services.HypergridService
139 if (!m_AssetPerms.AllowedImport(asset.Type)) 147 if (!m_AssetPerms.AllowedImport(asset.Type))
140 return string.Empty; 148 return string.Empty;
141 149
150 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
151 // Fix bad assets before storing on this server
152 if (asset.Type == (int)AssetType.Object && asset.Data != null)
153 {
154 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
155 asset.Data = Utils.StringToBytes(xml);
156 }
157
142 return base.Store(asset); 158 return base.Store(asset);
143 } 159 }
144 160
@@ -160,10 +176,16 @@ namespace OpenSim.Services.HypergridService
160 meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName; 176 meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName;
161 } 177 }
162 178
179 // Only for Object
163 protected byte[] AdjustIdentifiers(byte[] data) 180 protected byte[] AdjustIdentifiers(byte[] data)
164 { 181 {
165 string xml = Utils.BytesToString(data); 182 string xml = Utils.BytesToString(data);
166 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, m_HomeURL, m_Cache, UUID.Zero)); 183
184 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
185 // Fix bad assets before sending them elsewhere
186 xml = ExternalRepresentationUtils.SanitizeXml(xml);
187
188 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero));
167 } 189 }
168 190
169 } 191 }
diff --git a/OpenSim/Services/HypergridService/HGFSAssetService.cs b/OpenSim/Services/HypergridService/HGFSAssetService.cs
new file mode 100644
index 0000000..54e8ccb
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGFSAssetService.cs
@@ -0,0 +1,189 @@
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 */
27using System;
28using System.Reflection;
29
30using Nini.Config;
31using log4net;
32using OpenMetaverse;
33
34using OpenSim.Framework;
35using OpenSim.Framework.Serialization.External;
36using OpenSim.Server.Base;
37using OpenSim.Services.Interfaces;
38using OpenSim.Services.FSAssetService;
39
40namespace OpenSim.Services.HypergridService
41{
42 /// <summary>
43 /// Hypergrid asset service. It serves the IAssetService interface,
44 /// but implements it in ways that are appropriate for inter-grid
45 /// asset exchanges. This version is for FSAssets.
46 /// </summary>
47 public class HGFSAssetService : FSAssetConnector, IAssetService
48 {
49 private static readonly ILog m_log =
50 LogManager.GetLogger(
51 MethodBase.GetCurrentMethod().DeclaringType);
52
53 private string m_HomeURL;
54 private IUserAccountService m_UserAccountService;
55
56 private UserAccountCache m_Cache;
57
58 private AssetPermissions m_AssetPerms;
59
60 public HGFSAssetService(IConfigSource config, string configName) : base(config, "AssetService")
61 {
62 m_log.Debug("[HGAsset Service]: Starting in FSAsset mode");
63 IConfig assetConfig = config.Configs[configName];
64 if (assetConfig == null)
65 throw new Exception("No HGAssetService configuration");
66
67 string userAccountsDll = assetConfig.GetString("UserAccountsService", string.Empty);
68 if (userAccountsDll == string.Empty)
69 throw new Exception("Please specify UserAccountsService in HGAssetService configuration");
70
71 Object[] args = new Object[] { config };
72 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountsDll, args);
73 if (m_UserAccountService == null)
74 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
75
76 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
77 new string[] { "Startup", "Hypergrid", configName }, string.Empty);
78 if (m_HomeURL == string.Empty)
79 throw new Exception("[HGAssetService] No HomeURI specified");
80
81 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
82
83 // Permissions
84 m_AssetPerms = new AssetPermissions(assetConfig);
85 }
86
87 #region IAssetService overrides
88 public override AssetBase Get(string id)
89 {
90 AssetBase asset = base.Get(id);
91
92 if (asset == null)
93 return null;
94
95 if (!m_AssetPerms.AllowedExport(asset.Type))
96 return null;
97
98 if (asset.Metadata.Type == (sbyte)AssetType.Object)
99 asset.Data = AdjustIdentifiers(asset.Data);
100
101 AdjustIdentifiers(asset.Metadata);
102
103 return asset;
104 }
105
106 public override AssetMetadata GetMetadata(string id)
107 {
108 AssetMetadata meta = base.GetMetadata(id);
109
110 if (meta == null)
111 return null;
112
113 AdjustIdentifiers(meta);
114
115 return meta;
116 }
117
118 public override byte[] GetData(string id)
119 {
120 AssetBase asset = Get(id);
121
122 if (asset == null)
123 return null;
124
125 if (!m_AssetPerms.AllowedExport(asset.Type))
126 return null;
127
128 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
129 // Fix bad assets before sending them elsewhere
130 if (asset.Type == (int)AssetType.Object && asset.Data != null)
131 {
132 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
133 asset.Data = Utils.StringToBytes(xml);
134 }
135
136 return asset.Data;
137 }
138
139 //public virtual bool Get(string id, Object sender, AssetRetrieved handler)
140
141 public override string Store(AssetBase asset)
142 {
143 if (!m_AssetPerms.AllowedImport(asset.Type))
144 return string.Empty;
145
146 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
147 // Fix bad assets before storing on this server
148 if (asset.Type == (int)AssetType.Object && asset.Data != null)
149 {
150 string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
151 asset.Data = Utils.StringToBytes(xml);
152 }
153
154 return base.Store(asset);
155 }
156
157 public override bool Delete(string id)
158 {
159 // NOGO
160 return false;
161 }
162
163 #endregion
164
165 protected void AdjustIdentifiers(AssetMetadata meta)
166 {
167 if (meta == null || m_Cache == null)
168 return;
169
170 UserAccount creator = m_Cache.GetUser(meta.CreatorID);
171 if (creator != null)
172 meta.CreatorID = meta.CreatorID + ";" + m_HomeURL + "/" + creator.FirstName + " " + creator.LastName;
173 }
174
175 // Only for Object
176 protected byte[] AdjustIdentifiers(byte[] data)
177 {
178 string xml = Utils.BytesToString(data);
179
180 // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
181 // Fix bad assets before sending them elsewhere
182 xml = ExternalRepresentationUtils.SanitizeXml(xml);
183
184 return Utils.StringToBytes(ExternalRepresentationUtils.RewriteSOP(xml, "HGAssetService", m_HomeURL, m_Cache, UUID.Zero));
185 }
186
187 }
188
189}
diff --git a/OpenSim/Services/HypergridService/HGFriendsService.cs b/OpenSim/Services/HypergridService/HGFriendsService.cs
index a8bcfb2..6e35a88 100644
--- a/OpenSim/Services/HypergridService/HGFriendsService.cs
+++ b/OpenSim/Services/HypergridService/HGFriendsService.cs
@@ -198,7 +198,8 @@ namespace OpenSim.Services.HypergridService
198 // So let's send back the call, but start a thread to continue 198 // So let's send back the call, but start a thread to continue
199 // with the verification and the actual action. 199 // with the verification and the actual action.
200 200
201 Util.FireAndForget(delegate { ProcessFriendshipOffered(fromID, fromName, toID, message); }); 201 Util.FireAndForget(
202 o => ProcessFriendshipOffered(fromID, fromName, toID, message), null, "HGFriendsService.ProcessFriendshipOffered");
202 203
203 return true; 204 return true;
204 } 205 }
diff --git a/OpenSim/Services/HypergridService/HGInstantMessageService.cs b/OpenSim/Services/HypergridService/HGInstantMessageService.cs
index e8d7cca..32ca09a 100644
--- a/OpenSim/Services/HypergridService/HGInstantMessageService.cs
+++ b/OpenSim/Services/HypergridService/HGInstantMessageService.cs
@@ -101,7 +101,14 @@ namespace OpenSim.Services.HypergridService
101 Object[] args = new Object[] { config }; 101 Object[] args = new Object[] { config };
102 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args); 102 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
103 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args); 103 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
104 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(userAgentService, args); 104 try
105 {
106 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(userAgentService, args);
107 }
108 catch
109 {
110 m_log.WarnFormat("[HG IM SERVICE]: Unable to create User Agent Service. Missing config var in [HGInstantMessageService]?");
111 }
105 112
106 m_RegionCache = new ExpiringCache<UUID, GridRegion>(); 113 m_RegionCache = new ExpiringCache<UUID, GridRegion>();
107 114
@@ -215,7 +222,15 @@ namespace OpenSim.Services.HypergridService
215 { 222 {
216 // Let's check with the UAS if the user is elsewhere 223 // Let's check with the UAS if the user is elsewhere
217 m_log.DebugFormat("[HG IM SERVICE]: User is not present. Checking location with User Agent service"); 224 m_log.DebugFormat("[HG IM SERVICE]: User is not present. Checking location with User Agent service");
218 url = m_UserAgentService.LocateUser(toAgentID); 225 try
226 {
227 url = m_UserAgentService.LocateUser(toAgentID);
228 }
229 catch (Exception e)
230 {
231 m_log.Warn("[HG IM SERVICE]: LocateUser call failed ", e);
232 url = string.Empty;
233 }
219 } 234 }
220 235
221 // check if we've tried this before.. 236 // check if we've tried this before..
diff --git a/OpenSim/Services/HypergridService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs
index 2e9bd40..9158b41 100644
--- a/OpenSim/Services/HypergridService/HGInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGInventoryService.cs
@@ -81,10 +81,8 @@ namespace OpenSim.Services.HypergridService
81 if (m_UserAccountService == null) 81 if (m_UserAccountService == null)
82 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll)); 82 throw new Exception(String.Format("Unable to create UserAccountService from {0}", userAccountsDll));
83 83
84 // legacy configuration [obsolete] 84 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
85 m_HomeURL = invConfig.GetString("ProfileServerURI", string.Empty); 85 new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
86 // Preferred
87 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL);
88 86
89 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); 87 m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
90 } 88 }
@@ -105,12 +103,6 @@ namespace OpenSim.Services.HypergridService
105 return new List<InventoryFolderBase>(); 103 return new List<InventoryFolderBase>();
106 } 104 }
107 105
108 public override InventoryCollection GetUserInventory(UUID userID)
109 {
110 // NOGO for this inventory service
111 return null;
112 }
113
114 public override InventoryFolderBase GetRootFolder(UUID principalID) 106 public override InventoryFolderBase GetRootFolder(UUID principalID)
115 { 107 {
116 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID); 108 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
@@ -123,7 +115,7 @@ namespace OpenSim.Services.HypergridService
123 return ConvertToOpenSim(folders[0]); 115 return ConvertToOpenSim(folders[0]);
124 116
125 // make one 117 // make one
126 XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)AssetType.Folder, "My Suitcase"); 118 XInventoryFolder suitcase = CreateFolder(principalID, UUID.Zero, (int)FolderType.Suitcase, "My Suitcase");
127 return ConvertToOpenSim(suitcase); 119 return ConvertToOpenSim(suitcase);
128 } 120 }
129 121
@@ -149,7 +141,7 @@ namespace OpenSim.Services.HypergridService
149 //} 141 //}
150 142
151 143
152 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 144 public override InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
153 { 145 {
154 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 146 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
155 return GetRootFolder(principalID); 147 return GetRootFolder(principalID);
@@ -161,7 +153,14 @@ namespace OpenSim.Services.HypergridService
161 //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) 153 //public InventoryCollection GetFolderContent(UUID principalID, UUID folderID)
162 //{ 154 //{
163 //} 155 //}
164 156
157 // NOGO
158 //
159 public override InventoryCollection[] GetMultipleFoldersContent(UUID principalID, UUID[] folderID)
160 {
161 return new InventoryCollection[0];
162 }
163
165 //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID) 164 //public List<InventoryItemBase> GetFolderItems(UUID principalID, UUID folderID)
166 //{ 165 //{
167 //} 166 //}
@@ -300,7 +299,7 @@ namespace OpenSim.Services.HypergridService
300 UserAccount user = m_Cache.GetUser(it.CreatorId); 299 UserAccount user = m_Cache.GetUser(it.CreatorId);
301 300
302 // Adjust the creator data 301 // Adjust the creator data
303 if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) 302 if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
304 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; 303 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
305 } 304 }
306 return it; 305 return it;
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index 784f136..40eb6d4 100644
--- a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Services.HypergridService
54 LogManager.GetLogger( 54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType); 55 MethodBase.GetCurrentMethod().DeclaringType);
56 56
57 private string m_HomeURL; 57// private string m_HomeURL;
58 private IUserAccountService m_UserAccountService; 58 private IUserAccountService m_UserAccountService;
59 private IAvatarService m_AvatarService; 59 private IAvatarService m_AvatarService;
60 60
@@ -96,8 +96,8 @@ namespace OpenSim.Services.HypergridService
96 if (m_AvatarService == null) 96 if (m_AvatarService == null)
97 throw new Exception(String.Format("Unable to create m_AvatarService from {0}", avatarDll)); 97 throw new Exception(String.Format("Unable to create m_AvatarService from {0}", avatarDll));
98 98
99 // Preferred 99// m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
100 m_HomeURL = invConfig.GetString("HomeURI", m_HomeURL); 100// new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty);
101 101
102// m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService); 102// m_Cache = UserAccountCache.CreateUserAccountCache(m_UserAccountService);
103 } 103 }
@@ -115,8 +115,14 @@ namespace OpenSim.Services.HypergridService
115 { 115 {
116 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 116 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
117 117
118 if (suitcase == null)
119 {
120 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for inventory skeleton", principalID);
121 return null;
122 }
123
118 List<XInventoryFolder> tree = GetFolderTree(principalID, suitcase.folderID); 124 List<XInventoryFolder> tree = GetFolderTree(principalID, suitcase.folderID);
119 if (tree == null || (tree != null && tree.Count == 0)) 125 if (tree.Count == 0)
120 return null; 126 return null;
121 127
122 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 128 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
@@ -131,58 +137,13 @@ namespace OpenSim.Services.HypergridService
131 return folders; 137 return folders;
132 } 138 }
133 139
134 public override InventoryCollection GetUserInventory(UUID userID)
135 {
136 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
137 InventoryCollection userInventory = new InventoryCollection();
138 userInventory.UserID = userID;
139 userInventory.Folders = new List<InventoryFolderBase>();
140 userInventory.Items = new List<InventoryItemBase>();
141
142 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
143
144 List<XInventoryFolder> tree = GetFolderTree(userID, suitcase.folderID);
145 if (tree == null || (tree != null && tree.Count == 0))
146 {
147 SetAsNormalFolder(suitcase);
148 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
149 return userInventory;
150 }
151
152 List<InventoryItemBase> items;
153 foreach (XInventoryFolder f in tree)
154 {
155 // Add the items of this subfolder
156 items = GetFolderItems(userID, f.folderID);
157 if (items != null && items.Count > 0)
158 {
159 userInventory.Items.AddRange(items);
160 }
161
162 // Add the folder itself
163 userInventory.Folders.Add(ConvertToOpenSim(f));
164 }
165
166 items = GetFolderItems(userID, suitcase.folderID);
167 if (items != null && items.Count > 0)
168 {
169 userInventory.Items.AddRange(items);
170 }
171
172 SetAsNormalFolder(suitcase);
173 userInventory.Folders.Add(ConvertToOpenSim(suitcase));
174
175 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetUserInventory for user {0} returning {1} folders and {2} items",
176 userID, userInventory.Folders.Count, userInventory.Items.Count);
177 return userInventory;
178 }
179
180 public override InventoryFolderBase GetRootFolder(UUID principalID) 140 public override InventoryFolderBase GetRootFolder(UUID principalID)
181 { 141 {
182 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID); 142 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
183 143
184 // Let's find out the local root folder 144 // Let's find out the local root folder
185 XInventoryFolder root = GetRootXFolder(principalID); ; 145 XInventoryFolder root = GetRootXFolder(principalID);
146
186 if (root == null) 147 if (root == null)
187 { 148 {
188 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID); 149 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
@@ -195,14 +156,15 @@ namespace OpenSim.Services.HypergridService
195 if (suitcase == null) 156 if (suitcase == null)
196 { 157 {
197 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID); 158 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder. Creating it...", principalID);
198 // make one, and let's add it to the user's inventory as a direct child of the root folder 159 // Create the My Suitcase folder under the user's root folder.
199 // In the DB we tag it as type 100, but we use -1 (Unknown) outside 160 // In the DB we tag it as type 100, but we use type 8 (Folder) outside, as this affects the sort order.
200 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); 161 suitcase = CreateFolder(principalID, root.folderID, (int)FolderType.Suitcase, InventoryFolderBase.SUITCASE_FOLDER_NAME);
201 if (suitcase == null) 162 if (suitcase == null)
163 {
202 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); 164 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
203 m_Database.StoreFolder(suitcase); 165 return null;
166 }
204 167
205 // Create System folders
206 CreateSystemFolders(principalID, suitcase.folderID); 168 CreateSystemFolders(principalID, suitcase.folderID);
207 } 169 }
208 170
@@ -216,45 +178,51 @@ namespace OpenSim.Services.HypergridService
216 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase..."); 178 m_log.Debug("[HG SUITCASE INVENTORY SERVICE]: Creating System folders under Suitcase...");
217 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID); 179 XInventoryFolder[] sysFolders = GetSystemFolders(principalID, rootID);
218 180
219 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Animation) return true; return false; })) 181 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Animation) return true; return false; }))
220 CreateFolder(principalID, rootID, (int)AssetType.Animation, "Animations"); 182 CreateFolder(principalID, rootID, (int)FolderType.Animation, "Animations");
221 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Bodypart) return true; return false; })) 183 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.BodyPart) return true; return false; }))
222 CreateFolder(principalID, rootID, (int)AssetType.Bodypart, "Body Parts"); 184 CreateFolder(principalID, rootID, (int)FolderType.BodyPart, "Body Parts");
223 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CallingCard) return true; return false; })) 185 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.CallingCard) return true; return false; }))
224 CreateFolder(principalID, rootID, (int)AssetType.CallingCard, "Calling Cards"); 186 CreateFolder(principalID, rootID, (int)FolderType.CallingCard, "Calling Cards");
225 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Clothing) return true; return false; })) 187 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Clothing) return true; return false; }))
226 CreateFolder(principalID, rootID, (int)AssetType.Clothing, "Clothing"); 188 CreateFolder(principalID, rootID, (int)FolderType.Clothing, "Clothing");
227 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Gesture) return true; return false; })) 189 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.CurrentOutfit) return true; return false; }))
228 CreateFolder(principalID, rootID, (int)AssetType.Gesture, "Gestures"); 190 CreateFolder(principalID, rootID, (int)FolderType.CurrentOutfit, "Current Outfit");
229 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Landmark) return true; return false; })) 191 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Favorites) return true; return false; }))
230 CreateFolder(principalID, rootID, (int)AssetType.Landmark, "Landmarks"); 192 CreateFolder(principalID, rootID, (int)FolderType.Favorites, "Favorites");
231 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LostAndFoundFolder) return true; return false; })) 193 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Gesture) return true; return false; }))
232 CreateFolder(principalID, rootID, (int)AssetType.LostAndFoundFolder, "Lost And Found"); 194 CreateFolder(principalID, rootID, (int)FolderType.Gesture, "Gestures");
233 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Notecard) return true; return false; })) 195 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Landmark) return true; return false; }))
234 CreateFolder(principalID, rootID, (int)AssetType.Notecard, "Notecards"); 196 CreateFolder(principalID, rootID, (int)FolderType.Landmark, "Landmarks");
235 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Object) return true; return false; })) 197 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.LostAndFound) return true; return false; }))
236 CreateFolder(principalID, rootID, (int)AssetType.Object, "Objects"); 198 CreateFolder(principalID, rootID, (int)FolderType.LostAndFound, "Lost And Found");
237 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.SnapshotFolder) return true; return false; })) 199 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Notecard) return true; return false; }))
238 CreateFolder(principalID, rootID, (int)AssetType.SnapshotFolder, "Photo Album"); 200 CreateFolder(principalID, rootID, (int)FolderType.Notecard, "Notecards");
239 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.LSLText) return true; return false; })) 201 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Object) return true; return false; }))
240 CreateFolder(principalID, rootID, (int)AssetType.LSLText, "Scripts"); 202 CreateFolder(principalID, rootID, (int)FolderType.Object, "Objects");
241 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Sound) return true; return false; })) 203 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Snapshot) return true; return false; }))
242 CreateFolder(principalID, rootID, (int)AssetType.Sound, "Sounds"); 204 CreateFolder(principalID, rootID, (int)FolderType.Snapshot, "Photo Album");
243 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.Texture) return true; return false; })) 205 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.LSLText) return true; return false; }))
244 CreateFolder(principalID, rootID, (int)AssetType.Texture, "Textures"); 206 CreateFolder(principalID, rootID, (int)FolderType.LSLText, "Scripts");
245 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.TrashFolder) return true; return false; })) 207 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Sound) return true; return false; }))
246 CreateFolder(principalID, rootID, (int)AssetType.TrashFolder, "Trash"); 208 CreateFolder(principalID, rootID, (int)FolderType.Sound, "Sounds");
247 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.FavoriteFolder) return true; return false; })) 209 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Texture) return true; return false; }))
248 CreateFolder(principalID, rootID, (int)AssetType.FavoriteFolder, "Favorites"); 210 CreateFolder(principalID, rootID, (int)FolderType.Texture, "Textures");
249 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)AssetType.CurrentOutfitFolder) return true; return false; })) 211 if (!Array.Exists(sysFolders, delegate(XInventoryFolder f) { if (f.type == (int)FolderType.Trash) return true; return false; }))
250 CreateFolder(principalID, rootID, (int)AssetType.CurrentOutfitFolder, "Current Outfit"); 212 CreateFolder(principalID, rootID, (int)FolderType.Trash, "Trash");
251
252 } 213 }
253 214
254 public override InventoryFolderBase GetFolderForType(UUID principalID, AssetType type) 215 public override InventoryFolderBase GetFolderForType(UUID principalID, FolderType type)
255 { 216 {
256 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 217 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
257 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 218 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
219
220 if (suitcase == null)
221 {
222 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for child type folder {1}", principalID, type);
223 return null;
224 }
225
258 XInventoryFolder[] folders = m_Database.GetFolders( 226 XInventoryFolder[] folders = m_Database.GetFolders(
259 new string[] { "agentID", "type", "parentFolderID" }, 227 new string[] { "agentID", "type", "parentFolderID" },
260 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() }); 228 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
@@ -277,7 +245,10 @@ namespace OpenSim.Services.HypergridService
277 InventoryCollection coll = null; 245 InventoryCollection coll = null;
278 246
279 if (!IsWithinSuitcaseTree(principalID, folderID)) 247 if (!IsWithinSuitcaseTree(principalID, folderID))
248 {
249 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderContent: folder {0} (user {1}) is not within Suitcase tree", folderID, principalID);
280 return new InventoryCollection(); 250 return new InventoryCollection();
251 }
281 252
282 coll = base.GetFolderContent(principalID, folderID); 253 coll = base.GetFolderContent(principalID, folderID);
283 254
@@ -294,7 +265,10 @@ namespace OpenSim.Services.HypergridService
294 // Let's do a bit of sanity checking, more than the base service does 265 // Let's do a bit of sanity checking, more than the base service does
295 // make sure the given folder exists under the suitcase tree of this user 266 // make sure the given folder exists under the suitcase tree of this user
296 if (!IsWithinSuitcaseTree(principalID, folderID)) 267 if (!IsWithinSuitcaseTree(principalID, folderID))
268 {
269 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolderItems: folder {0} (user {1}) is not within Suitcase tree", folderID, principalID);
297 return new List<InventoryItemBase>(); 270 return new List<InventoryItemBase>();
271 }
298 272
299 return base.GetFolderItems(principalID, folderID); 273 return base.GetFolderItems(principalID, folderID);
300 } 274 }
@@ -306,7 +280,10 @@ namespace OpenSim.Services.HypergridService
306 // make sure the given folder's parent folder exists under the suitcase tree of this user 280 // make sure the given folder's parent folder exists under the suitcase tree of this user
307 281
308 if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID)) 282 if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID))
283 {
284 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder: folder {0} (user {1}) is not within Suitcase tree", folder.ParentID, folder.Owner);
309 return false; 285 return false;
286 }
310 287
311 // OK, it's legit 288 // OK, it's legit
312 if (base.AddFolder(folder)) 289 if (base.AddFolder(folder))
@@ -326,7 +303,7 @@ namespace OpenSim.Services.HypergridService
326 //m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version); 303 //m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Update folder {0}, version {1}", folder.ID, folder.Version);
327 if (!IsWithinSuitcaseTree(folder.Owner, folder.ID)) 304 if (!IsWithinSuitcaseTree(folder.Owner, folder.ID))
328 { 305 {
329 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: folder {0} not within Suitcase tree", folder.Name); 306 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: UpdateFolder: folder {0}/{1} (user {2}) is not within Suitcase tree", folder.Name, folder.ID, folder.Owner);
330 return false; 307 return false;
331 } 308 }
332 309
@@ -336,9 +313,17 @@ namespace OpenSim.Services.HypergridService
336 313
337 public override bool MoveFolder(InventoryFolderBase folder) 314 public override bool MoveFolder(InventoryFolderBase folder)
338 { 315 {
339 if (!IsWithinSuitcaseTree(folder.Owner, folder.ID) || 316 if (!IsWithinSuitcaseTree(folder.Owner, folder.ID))
340 !IsWithinSuitcaseTree(folder.Owner, folder.ParentID)) 317 {
318 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder: folder {0} (user {1}) is not within Suitcase tree", folder.ID, folder.Owner);
319 return false;
320 }
321
322 if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID))
323 {
324 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveFolder: folder {0} (user {1}) is not within Suitcase tree", folder.ParentID, folder.Owner);
341 return false; 325 return false;
326 }
342 327
343 return base.MoveFolder(folder); 328 return base.MoveFolder(folder);
344 } 329 }
@@ -360,7 +345,10 @@ namespace OpenSim.Services.HypergridService
360 // Let's do a bit of sanity checking, more than the base service does 345 // Let's do a bit of sanity checking, more than the base service does
361 // make sure the given folder's parent folder exists under the suitcase tree of this user 346 // make sure the given folder's parent folder exists under the suitcase tree of this user
362 if (!IsWithinSuitcaseTree(item.Owner, item.Folder)) 347 if (!IsWithinSuitcaseTree(item.Owner, item.Folder))
348 {
349 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddItem: folder {0} (user {1}) is not within Suitcase tree", item.Folder, item.Owner);
363 return false; 350 return false;
351 }
364 352
365 // OK, it's legit 353 // OK, it's legit
366 return base.AddItem(item); 354 return base.AddItem(item);
@@ -370,7 +358,10 @@ namespace OpenSim.Services.HypergridService
370 public override bool UpdateItem(InventoryItemBase item) 358 public override bool UpdateItem(InventoryItemBase item)
371 { 359 {
372 if (!IsWithinSuitcaseTree(item.Owner, item.Folder)) 360 if (!IsWithinSuitcaseTree(item.Owner, item.Folder))
361 {
362 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: UpdateItem: folder {0} (user {1}) is not within Suitcase tree", item.Folder, item.Owner);
373 return false; 363 return false;
364 }
374 365
375 return base.UpdateItem(item); 366 return base.UpdateItem(item);
376 } 367 }
@@ -379,11 +370,28 @@ namespace OpenSim.Services.HypergridService
379 { 370 {
380 // Principal is b0rked. *sigh* 371 // Principal is b0rked. *sigh*
381 372
382 if (!IsWithinSuitcaseTree(items[0].Owner, items[0].Folder)) 373 // Check the items' destination folders
383 return false; 374 foreach (InventoryItemBase item in items)
375 {
376 if (!IsWithinSuitcaseTree(item.Owner, item.Folder))
377 {
378 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItems: folder {0} (user {1}) is not within Suitcase tree", item.Folder, item.Owner);
379 return false;
380 }
381 }
384 382
385 return base.MoveItems(principalID, items); 383 // Check the items' current folders
384 foreach (InventoryItemBase item in items)
385 {
386 InventoryItemBase originalItem = base.GetItem(item);
387 if (!IsWithinSuitcaseTree(originalItem.Owner, originalItem.Folder))
388 {
389 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: MoveItems: folder {0} (user {1}) is not within Suitcase tree", item.Folder, item.Owner);
390 return false;
391 }
392 }
386 393
394 return base.MoveItems(principalID, items);
387 } 395 }
388 396
389 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs) 397 public override bool DeleteItems(UUID principalID, List<UUID> itemIDs)
@@ -403,8 +411,8 @@ namespace OpenSim.Services.HypergridService
403 411
404 if (!IsWithinSuitcaseTree(it.Owner, it.Folder) && !IsPartOfAppearance(it.Owner, it.ID)) 412 if (!IsWithinSuitcaseTree(it.Owner, it.Folder) && !IsPartOfAppearance(it.Owner, it.ID))
405 { 413 {
406 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Item {0} (folder {1}) is not within Suitcase", 414 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetItem: item {0}/{1} (folder {2}) (user {3}) is not within Suitcase tree or Appearance",
407 it.Name, it.Folder); 415 it.Name, it.ID, it.Folder, it.Owner);
408 return null; 416 return null;
409 } 417 }
410 418
@@ -425,7 +433,11 @@ namespace OpenSim.Services.HypergridService
425 if (f != null) 433 if (f != null)
426 { 434 {
427 if (!IsWithinSuitcaseTree(f.Owner, f.ID)) 435 if (!IsWithinSuitcaseTree(f.Owner, f.ID))
436 {
437 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetFolder: folder {0}/{1} (user {2}) is not within Suitcase tree",
438 f.Name, f.ID, f.Owner);
428 return null; 439 return null;
440 }
429 } 441 }
430 442
431 return f; 443 return f;
@@ -456,7 +468,7 @@ namespace OpenSim.Services.HypergridService
456 { 468 {
457 XInventoryFolder[] folders = m_Database.GetFolders( 469 XInventoryFolder[] folders = m_Database.GetFolders(
458 new string[] { "agentID", "folderName", "type" }, 470 new string[] { "agentID", "folderName", "type" },
459 new string[] { principalID.ToString(), "My Inventory", ((int)AssetType.RootFolder).ToString() }); 471 new string[] { principalID.ToString(), InventoryFolderBase.ROOT_FOLDER_NAME, ((int)FolderType.Root).ToString() });
460 472
461 if (folders != null && folders.Length > 0) 473 if (folders != null && folders.Length > 0)
462 return folders[0]; 474 return folders[0];
@@ -464,7 +476,7 @@ namespace OpenSim.Services.HypergridService
464 // OK, so the RootFolder type didn't work. Let's look for any type with parent UUID.Zero. 476 // OK, so the RootFolder type didn't work. Let's look for any type with parent UUID.Zero.
465 folders = m_Database.GetFolders( 477 folders = m_Database.GetFolders(
466 new string[] { "agentID", "folderName", "parentFolderID" }, 478 new string[] { "agentID", "folderName", "parentFolderID" },
467 new string[] { principalID.ToString(), "My Inventory", UUID.Zero.ToString() }); 479 new string[] { principalID.ToString(), InventoryFolderBase.ROOT_FOLDER_NAME, UUID.Zero.ToString() });
468 480
469 if (folders != null && folders.Length > 0) 481 if (folders != null && folders.Length > 0)
470 return folders[0]; 482 return folders[0];
@@ -472,12 +484,28 @@ namespace OpenSim.Services.HypergridService
472 return null; 484 return null;
473 } 485 }
474 486
487 private XInventoryFolder GetCurrentOutfitXFolder(UUID userID)
488 {
489 XInventoryFolder root = GetRootXFolder(userID);
490 if (root == null)
491 return null;
492
493 XInventoryFolder[] folders = m_Database.GetFolders(
494 new string[] { "agentID", "type", "parentFolderID" },
495 new string[] { userID.ToString(), ((int)FolderType.CurrentOutfit).ToString(), root.folderID.ToString() });
496
497 if (folders.Length == 0)
498 return null;
499
500 return folders[0];
501 }
502
475 private XInventoryFolder GetSuitcaseXFolder(UUID principalID) 503 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
476 { 504 {
477 // Warp! Root folder for travelers 505 // Warp! Root folder for travelers
478 XInventoryFolder[] folders = m_Database.GetFolders( 506 XInventoryFolder[] folders = m_Database.GetFolders(
479 new string[] { "agentID", "type" }, 507 new string[] { "agentID", "type" },
480 new string[] { principalID.ToString(), "100" }); // This is a special folder type... 508 new string[] { principalID.ToString(), ((int)FolderType.Suitcase).ToString() });
481 509
482 if (folders != null && folders.Length > 0) 510 if (folders != null && folders.Length > 0)
483 return folders[0]; 511 return folders[0];
@@ -485,13 +513,13 @@ namespace OpenSim.Services.HypergridService
485 // check to see if we have the old Suitcase folder 513 // check to see if we have the old Suitcase folder
486 folders = m_Database.GetFolders( 514 folders = m_Database.GetFolders(
487 new string[] { "agentID", "folderName", "parentFolderID" }, 515 new string[] { "agentID", "folderName", "parentFolderID" },
488 new string[] { principalID.ToString(), "My Suitcase", UUID.Zero.ToString() }); 516 new string[] { principalID.ToString(), InventoryFolderBase.SUITCASE_FOLDER_NAME, UUID.Zero.ToString() });
489 if (folders != null && folders.Length > 0) 517 if (folders != null && folders.Length > 0)
490 { 518 {
491 // Move it to under the root folder 519 // Move it to under the root folder
492 XInventoryFolder root = GetRootXFolder(principalID); 520 XInventoryFolder root = GetRootXFolder(principalID);
493 folders[0].parentFolderID = root.folderID; 521 folders[0].parentFolderID = root.folderID;
494 folders[0].type = 100; 522 folders[0].type = (int)FolderType.Suitcase;
495 m_Database.StoreFolder(folders[0]); 523 m_Database.StoreFolder(folders[0]);
496 return folders[0]; 524 return folders[0];
497 } 525 }
@@ -501,17 +529,18 @@ namespace OpenSim.Services.HypergridService
501 529
502 private void SetAsNormalFolder(XInventoryFolder suitcase) 530 private void SetAsNormalFolder(XInventoryFolder suitcase)
503 { 531 {
504 suitcase.type = (short)AssetType.Folder; 532 //suitcase.type = InventoryItemBase.SUITCASE_FOLDER_FAKE_TYPE;
505 } 533 }
506 534
507 private List<XInventoryFolder> GetFolderTree(UUID principalID, UUID folder) 535 private List<XInventoryFolder> GetFolderTree(UUID principalID, UUID folder)
508 { 536 {
509 List<XInventoryFolder> t = null; 537 List<XInventoryFolder> t;
510 if (m_SuitcaseTrees.TryGetValue(principalID, out t)) 538 if (m_SuitcaseTrees.TryGetValue(principalID, out t))
511 return t; 539 return t;
512 540
541 // Get the tree of the suitcase folder
513 t = GetFolderTreeRecursive(folder); 542 t = GetFolderTreeRecursive(folder);
514 m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes 543 m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5 minutes
515 return t; 544 return t;
516 } 545 }
517 546
@@ -522,8 +551,10 @@ namespace OpenSim.Services.HypergridService
522 new string[] { "parentFolderID" }, 551 new string[] { "parentFolderID" },
523 new string[] { root.ToString() }); 552 new string[] { root.ToString() });
524 553
525 if (folders == null || (folders != null && folders.Length == 0)) 554 if (folders == null || folders.Length == 0)
555 {
526 return tree; // empty tree 556 return tree; // empty tree
557 }
527 else 558 else
528 { 559 {
529 foreach (XInventoryFolder f in folders) 560 foreach (XInventoryFolder f in folders)
@@ -546,6 +577,7 @@ namespace OpenSim.Services.HypergridService
546 private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID) 577 private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID)
547 { 578 {
548 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 579 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
580
549 if (suitcase == null) 581 if (suitcase == null)
550 { 582 {
551 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID); 583 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID);
@@ -555,14 +587,18 @@ namespace OpenSim.Services.HypergridService
555 List<XInventoryFolder> tree = new List<XInventoryFolder>(); 587 List<XInventoryFolder> tree = new List<XInventoryFolder>();
556 tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder 588 tree.Add(suitcase); // Warp! the tree is the real root folder plus the children of the suitcase folder
557 tree.AddRange(GetFolderTree(principalID, suitcase.folderID)); 589 tree.AddRange(GetFolderTree(principalID, suitcase.folderID));
590
591 // Also add the Current Outfit folder to the list of available folders
592 XInventoryFolder folder = GetCurrentOutfitXFolder(principalID);
593 if (folder != null)
594 tree.Add(folder);
595
558 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) 596 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
559 { 597 {
560 if (fl.folderID == folderID) return true; 598 return (fl.folderID == folderID);
561 else return false;
562 }); 599 });
563 600
564 if (f == null) return false; 601 return (f != null);
565 else return true;
566 } 602 }
567 #endregion 603 #endregion
568 604
diff --git a/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs b/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs
index 49f2176..9999237 100644
--- a/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs
+++ b/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
29// Build Number 29// Build Number
30// Revision 30// Revision
31// 31//
32[assembly: AssemblyVersion("0.7.5.*")] 32[assembly: AssemblyVersion("0.8.3.*")]
33[assembly: AssemblyFileVersion("1.0.0.0")] 33
diff --git a/OpenSim/Services/HypergridService/UserAccountCache.cs b/OpenSim/Services/HypergridService/UserAccountCache.cs
index 65f9dd5..fa7dd0b 100644
--- a/OpenSim/Services/HypergridService/UserAccountCache.cs
+++ b/OpenSim/Services/HypergridService/UserAccountCache.cs
@@ -1,4 +1,4 @@
1using System; 1using System;
2using System.Collections.Generic; 2using System.Collections.Generic;
3using System.Reflection; 3using System.Reflection;
4 4
@@ -95,6 +95,11 @@ namespace OpenSim.Services.HypergridService
95 return null; 95 return null;
96 } 96 }
97 97
98 public void InvalidateCache(UUID userID)
99 {
100 m_UUIDCache.Remove(userID);
101 }
102
98 public bool StoreUserAccount(UserAccount data) 103 public bool StoreUserAccount(UserAccount data)
99 { 104 {
100 return false; 105 return false;
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index a26a922..c65122a 100644
--- a/OpenSim/Services/HypergridService/UserAgentService.cs
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -30,6 +30,7 @@ using System.Collections.Generic;
30using System.Net; 30using System.Net;
31using System.Reflection; 31using System.Reflection;
32 32
33using OpenSim.Data;
33using OpenSim.Framework; 34using OpenSim.Framework;
34using OpenSim.Services.Connectors.Friends; 35using OpenSim.Services.Connectors.Friends;
35using OpenSim.Services.Connectors.Hypergrid; 36using OpenSim.Services.Connectors.Hypergrid;
@@ -50,14 +51,14 @@ namespace OpenSim.Services.HypergridService
50 /// needs to do it for them. 51 /// needs to do it for them.
51 /// Once we have better clients, this shouldn't be needed. 52 /// Once we have better clients, this shouldn't be needed.
52 /// </summary> 53 /// </summary>
53 public class UserAgentService : IUserAgentService 54 public class UserAgentService : UserAgentServiceBase, IUserAgentService
54 { 55 {
55 private static readonly ILog m_log = 56 private static readonly ILog m_log =
56 LogManager.GetLogger( 57 LogManager.GetLogger(
57 MethodBase.GetCurrentMethod().DeclaringType); 58 MethodBase.GetCurrentMethod().DeclaringType);
58 59
59 // This will need to go into a DB table 60 // This will need to go into a DB table
60 static Dictionary<UUID, TravelingAgentInfo> m_TravelingAgents = new Dictionary<UUID, TravelingAgentInfo>(); 61 //static Dictionary<UUID, TravelingAgentInfo> m_Database = new Dictionary<UUID, TravelingAgentInfo>();
61 62
62 static bool m_Initialized = false; 63 static bool m_Initialized = false;
63 64
@@ -74,6 +75,7 @@ namespace OpenSim.Services.HypergridService
74 protected static string m_GridName; 75 protected static string m_GridName;
75 76
76 protected static int m_LevelOutsideContacts; 77 protected static int m_LevelOutsideContacts;
78 protected static bool m_ShowDetails;
77 79
78 protected static bool m_BypassClientVerification; 80 protected static bool m_BypassClientVerification;
79 81
@@ -86,6 +88,7 @@ namespace OpenSim.Services.HypergridService
86 } 88 }
87 89
88 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector) 90 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
91 : base(config)
89 { 92 {
90 // Let's set this always, because we don't know the sequence 93 // Let's set this always, because we don't know the sequence
91 // of instantiations 94 // of instantiations
@@ -126,20 +129,30 @@ namespace OpenSim.Services.HypergridService
126 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountService, args); 129 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountService, args);
127 130
128 m_LevelOutsideContacts = serverConfig.GetInt("LevelOutsideContacts", 0); 131 m_LevelOutsideContacts = serverConfig.GetInt("LevelOutsideContacts", 0);
132 m_ShowDetails = serverConfig.GetBoolean("ShowUserDetailsInHGProfile", true);
129 133
130 LoadTripPermissionsFromConfig(serverConfig, "ForeignTripsAllowed"); 134 LoadTripPermissionsFromConfig(serverConfig, "ForeignTripsAllowed");
131 LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_TripsAllowedExceptions); 135 LoadDomainExceptionsFromConfig(serverConfig, "AllowExcept", m_TripsAllowedExceptions);
132 LoadDomainExceptionsFromConfig(serverConfig, "DisallowExcept", m_TripsDisallowedExceptions); 136 LoadDomainExceptionsFromConfig(serverConfig, "DisallowExcept", m_TripsDisallowedExceptions);
133 137
134 m_GridName = serverConfig.GetString("ExternalName", string.Empty); 138 m_GridName = Util.GetConfigVarFromSections<string>(config, "GatekeeperURI",
135 if (m_GridName == string.Empty) 139 new string[] { "Startup", "Hypergrid", "UserAgentService" }, String.Empty);
140 if (string.IsNullOrEmpty(m_GridName)) // Legacy. Remove soon.
136 { 141 {
137 serverConfig = config.Configs["GatekeeperService"];
138 m_GridName = serverConfig.GetString("ExternalName", string.Empty); 142 m_GridName = serverConfig.GetString("ExternalName", string.Empty);
143 if (m_GridName == string.Empty)
144 {
145 serverConfig = config.Configs["GatekeeperService"];
146 m_GridName = serverConfig.GetString("ExternalName", string.Empty);
147 }
139 } 148 }
149
140 if (!m_GridName.EndsWith("/")) 150 if (!m_GridName.EndsWith("/"))
141 m_GridName = m_GridName + "/"; 151 m_GridName = m_GridName + "/";
142 152
153 // Finally some cleanup
154 m_Database.DeleteOld();
155
143 } 156 }
144 } 157 }
145 158
@@ -204,10 +217,10 @@ namespace OpenSim.Services.HypergridService
204 return home; 217 return home;
205 } 218 }
206 219
207 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, IPEndPoint clientIP, out string reason) 220 public bool LoginAgentToGrid(GridRegion source, AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, bool fromLogin, out string reason)
208 { 221 {
209 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}", 222 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}",
210 agentCircuit.firstname, agentCircuit.lastname, ((clientIP == null) ? "stored IP" : clientIP.Address.ToString()), gatekeeper.ServerURI); 223 agentCircuit.firstname, agentCircuit.lastname, (fromLogin ? agentCircuit.IPAddress : "stored IP"), gatekeeper.ServerURI);
211 224
212 string gridName = gatekeeper.ServerURI; 225 string gridName = gatekeeper.ServerURI;
213 226
@@ -254,21 +267,21 @@ namespace OpenSim.Services.HypergridService
254 267
255 // Generate a new service session 268 // Generate a new service session
256 agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random(); 269 agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random();
257 TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region); 270 TravelingAgentInfo old = null;
271 TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old);
258 272
259 bool success = false; 273 bool success = false;
260 string myExternalIP = string.Empty; 274 string myExternalIP = string.Empty;
261 275
262 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName); 276 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}, desired region: {2}", m_GridName, gridName, region.RegionID);
263 277
264 if (m_GridName == gridName) 278 if (m_GridName == gridName)
265 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); 279 {
280 success = m_GatekeeperService.LoginAgent(source, agentCircuit, finalDestination, out reason);
281 }
266 else 282 else
267 { 283 {
268 success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason); 284 success = m_GatekeeperConnector.CreateAgent(source, region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason);
269 if (success)
270 // Report them as nowhere
271 m_PresenceService.ReportAgent(agentCircuit.SessionID, UUID.Zero);
272 } 285 }
273 286
274 if (!success) 287 if (!success)
@@ -276,84 +289,64 @@ namespace OpenSim.Services.HypergridService
276 m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}", 289 m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
277 agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); 290 agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason);
278 291
279 // restore the old travel info 292 if (old != null)
280 lock (m_TravelingAgents) 293 StoreTravelInfo(old);
281 { 294 else
282 if (old == null) 295 m_Database.Delete(agentCircuit.SessionID);
283 m_TravelingAgents.Remove(agentCircuit.SessionID);
284 else
285 m_TravelingAgents[agentCircuit.SessionID] = old;
286 }
287 296
288 return false; 297 return false;
289 } 298 }
290 299
300 // Everything is ok
301
302 // Update the perceived IP Address of our grid
291 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP); 303 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
292 // else set the IP addresses associated with this client 304 travel.MyIpAddress = myExternalIP;
293 if (clientIP != null) 305
294 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); 306 StoreTravelInfo(travel);
295 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
296 307
297 return true; 308 return true;
298 } 309 }
299 310
300 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason) 311 public bool LoginAgentToGrid(GridRegion source, AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
301 { 312 {
302 reason = string.Empty; 313 reason = string.Empty;
303 return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, null, out reason); 314 return LoginAgentToGrid(source, agentCircuit, gatekeeper, finalDestination, false, out reason);
304 } 315 }
305 316
306 private void SetClientIP(UUID sessionID, string ip) 317 TravelingAgentInfo CreateTravelInfo(AgentCircuitData agentCircuit, GridRegion region, bool fromLogin, out TravelingAgentInfo existing)
307 { 318 {
308 if (m_TravelingAgents.ContainsKey(sessionID)) 319 HGTravelingData hgt = m_Database.Get(agentCircuit.SessionID);
309 { 320 existing = null;
310 m_log.DebugFormat("[USER AGENT SERVICE]: Setting IP {0} for session {1}", ip, sessionID);
311 m_TravelingAgents[sessionID].ClientIPAddress = ip;
312 }
313 }
314 321
315 TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region) 322 if (hgt != null)
316 {
317 TravelingAgentInfo travel = new TravelingAgentInfo();
318 TravelingAgentInfo old = null;
319 lock (m_TravelingAgents)
320 { 323 {
321 if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID)) 324 // Very important! Override whatever this agent comes with.
322 { 325 // UserAgentService always sets the IP for every new agent
323 // Very important! Override whatever this agent comes with. 326 // with the original IP address.
324 // UserAgentService always sets the IP for every new agent 327 existing = new TravelingAgentInfo(hgt);
325 // with the original IP address. 328 agentCircuit.IPAddress = existing.ClientIPAddress;
326 agentCircuit.IPAddress = m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress;
327
328 old = m_TravelingAgents[agentCircuit.SessionID];
329 }
330
331 m_TravelingAgents[agentCircuit.SessionID] = travel;
332 } 329 }
330
331 TravelingAgentInfo travel = new TravelingAgentInfo(existing);
332 travel.SessionID = agentCircuit.SessionID;
333 travel.UserID = agentCircuit.AgentID; 333 travel.UserID = agentCircuit.AgentID;
334 travel.GridExternalName = region.ServerURI; 334 travel.GridExternalName = region.ServerURI;
335 travel.ServiceToken = agentCircuit.ServiceSessionID; 335 travel.ServiceToken = agentCircuit.ServiceSessionID;
336 if (old != null)
337 travel.ClientIPAddress = old.ClientIPAddress;
338 336
339 return old; 337 if (fromLogin)
338 travel.ClientIPAddress = agentCircuit.IPAddress;
339
340 StoreTravelInfo(travel);
341
342 return travel;
340 } 343 }
341 344
342 public void LogoutAgent(UUID userID, UUID sessionID) 345 public void LogoutAgent(UUID userID, UUID sessionID)
343 { 346 {
344 m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID); 347 m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID);
345 348
346 lock (m_TravelingAgents) 349 m_Database.Delete(sessionID);
347 {
348 List<UUID> travels = new List<UUID>();
349 foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents)
350 if (kvp.Value == null) // do some clean up
351 travels.Add(kvp.Key);
352 else if (kvp.Value.UserID == userID)
353 travels.Add(kvp.Key);
354 foreach (UUID session in travels)
355 m_TravelingAgents.Remove(session);
356 }
357 350
358 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString()); 351 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
359 if (guinfo != null) 352 if (guinfo != null)
@@ -363,10 +356,11 @@ namespace OpenSim.Services.HypergridService
363 // We need to prevent foreign users with the same UUID as a local user 356 // We need to prevent foreign users with the same UUID as a local user
364 public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) 357 public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
365 { 358 {
366 if (!m_TravelingAgents.ContainsKey(sessionID)) 359 HGTravelingData hgt = m_Database.Get(sessionID);
360 if (hgt == null)
367 return false; 361 return false;
368 362
369 TravelingAgentInfo travel = m_TravelingAgents[sessionID]; 363 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
370 364
371 return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower(); 365 return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower();
372 } 366 }
@@ -379,31 +373,32 @@ namespace OpenSim.Services.HypergridService
379 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.", 373 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.",
380 sessionID, reportedIP); 374 sessionID, reportedIP);
381 375
382 if (m_TravelingAgents.ContainsKey(sessionID)) 376 HGTravelingData hgt = m_Database.Get(sessionID);
383 { 377 if (hgt == null)
384 bool result = m_TravelingAgents[sessionID].ClientIPAddress == reportedIP || 378 return false;
385 m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed
386 379
387 m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}", 380 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
388 reportedIP, m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress, result);
389 381
390 return result; 382 bool result = travel.ClientIPAddress == reportedIP || travel.MyIpAddress == reportedIP; // NATed
391 } 383
384 m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}",
385 reportedIP, travel.ClientIPAddress, travel.MyIpAddress, result);
392 386
393 return false; 387 return result;
394 } 388 }
395 389
396 public bool VerifyAgent(UUID sessionID, string token) 390 public bool VerifyAgent(UUID sessionID, string token)
397 { 391 {
398 if (m_TravelingAgents.ContainsKey(sessionID)) 392 HGTravelingData hgt = m_Database.Get(sessionID);
393 if (hgt == null)
399 { 394 {
400 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken); 395 m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
401 return m_TravelingAgents[sessionID].ServiceToken == token; 396 return false;
402 } 397 }
403 398
404 m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID); 399 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
405 400 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, travel.ServiceToken);
406 return false; 401 return travel.ServiceToken == token;
407 } 402 }
408 403
409 [Obsolete] 404 [Obsolete]
@@ -466,17 +461,17 @@ namespace OpenSim.Services.HypergridService
466 } 461 }
467 } 462 }
468 463
469 // Lastly, let's notify the rest who may be online somewhere else 464 //// Lastly, let's notify the rest who may be online somewhere else
470 foreach (string user in usersToBeNotified) 465 //foreach (string user in usersToBeNotified)
471 { 466 //{
472 UUID id = new UUID(user); 467 // UUID id = new UUID(user);
473 if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) 468 // if (m_Database.ContainsKey(id) && m_Database[id].GridExternalName != m_GridName)
474 { 469 // {
475 string url = m_TravelingAgents[id].GridExternalName; 470 // string url = m_Database[id].GridExternalName;
476 // forward 471 // // forward
477 m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); 472 // m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
478 } 473 // }
479 } 474 //}
480 475
481 // and finally, let's send the online friends 476 // and finally, let's send the online friends
482 if (online) 477 if (online)
@@ -578,10 +573,22 @@ namespace OpenSim.Services.HypergridService
578 573
579 if (account != null) 574 if (account != null)
580 { 575 {
581 info.Add("user_flags", (object)account.UserFlags); 576 info.Add("user_firstname", account.FirstName);
582 info.Add("user_created", (object)account.Created); 577 info.Add("user_lastname", account.LastName);
583 info.Add("user_title", (object)account.UserTitle);
584 info.Add("result", "success"); 578 info.Add("result", "success");
579
580 if (m_ShowDetails)
581 {
582 info.Add("user_flags", account.UserFlags);
583 info.Add("user_created", account.Created);
584 info.Add("user_title", account.UserTitle);
585 }
586 else
587 {
588 info.Add("user_flags", 0);
589 info.Add("user_created", 0);
590 info.Add("user_title", string.Empty);
591 }
585 } 592 }
586 593
587 return info; 594 return info;
@@ -603,16 +610,13 @@ namespace OpenSim.Services.HypergridService
603 610
604 public string LocateUser(UUID userID) 611 public string LocateUser(UUID userID)
605 { 612 {
606 foreach (TravelingAgentInfo t in m_TravelingAgents.Values) 613 HGTravelingData[] hgts = m_Database.GetSessions(userID);
607 { 614 if (hgts == null)
608 if (t == null) 615 return string.Empty;
609 { 616
610 m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis"); 617 foreach (HGTravelingData t in hgts)
611 continue; 618 if (t.Data.ContainsKey("GridExternalName") && !m_GridName.Equals(t.Data["GridExternalName"]))
612 } 619 return t.Data["GridExternalName"];
613 if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName))
614 return t.GridExternalName;
615 }
616 620
617 return string.Empty; 621 return string.Empty;
618 } 622 }
@@ -683,17 +687,60 @@ namespace OpenSim.Services.HypergridService
683 return exception; 687 return exception;
684 } 688 }
685 689
690 private void StoreTravelInfo(TravelingAgentInfo travel)
691 {
692 if (travel == null)
693 return;
694
695 HGTravelingData hgt = new HGTravelingData();
696 hgt.SessionID = travel.SessionID;
697 hgt.UserID = travel.UserID;
698 hgt.Data = new Dictionary<string, string>();
699 hgt.Data["GridExternalName"] = travel.GridExternalName;
700 hgt.Data["ServiceToken"] = travel.ServiceToken;
701 hgt.Data["ClientIPAddress"] = travel.ClientIPAddress;
702 hgt.Data["MyIPAddress"] = travel.MyIpAddress;
703
704 m_Database.Store(hgt);
705 }
686 #endregion 706 #endregion
687 707
688 } 708 }
689 709
690 class TravelingAgentInfo 710 class TravelingAgentInfo
691 { 711 {
712 public UUID SessionID;
692 public UUID UserID; 713 public UUID UserID;
693 public string GridExternalName = string.Empty; 714 public string GridExternalName = string.Empty;
694 public string ServiceToken = string.Empty; 715 public string ServiceToken = string.Empty;
695 public string ClientIPAddress = string.Empty; // as seen from this user agent service 716 public string ClientIPAddress = string.Empty; // as seen from this user agent service
696 public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper 717 public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper
718
719 public TravelingAgentInfo(HGTravelingData t)
720 {
721 if (t.Data != null)
722 {
723 SessionID = new UUID(t.SessionID);
724 UserID = new UUID(t.UserID);
725 GridExternalName = t.Data["GridExternalName"];
726 ServiceToken = t.Data["ServiceToken"];
727 ClientIPAddress = t.Data["ClientIPAddress"];
728 MyIpAddress = t.Data["MyIPAddress"];
729 }
730 }
731
732 public TravelingAgentInfo(TravelingAgentInfo old)
733 {
734 if (old != null)
735 {
736 SessionID = old.SessionID;
737 UserID = old.UserID;
738 GridExternalName = old.GridExternalName;
739 ServiceToken = old.ServiceToken;
740 ClientIPAddress = old.ClientIPAddress;
741 MyIpAddress = old.MyIpAddress;
742 }
743 }
697 } 744 }
698 745
699} 746}
diff --git a/OpenSim/Services/HypergridService/UserAgentServiceBase.cs b/OpenSim/Services/HypergridService/UserAgentServiceBase.cs
new file mode 100644
index 0000000..a00e5a6
--- /dev/null
+++ b/OpenSim/Services/HypergridService/UserAgentServiceBase.cs
@@ -0,0 +1,84 @@
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
28using System;
29using System.Reflection;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Data;
33using OpenSim.Services.Interfaces;
34using OpenSim.Services.Base;
35
36namespace OpenSim.Services.HypergridService
37{
38 public class UserAgentServiceBase : ServiceBase
39 {
40 protected IHGTravelingData m_Database = null;
41
42 public UserAgentServiceBase(IConfigSource config)
43 : base(config)
44 {
45 string dllName = String.Empty;
46 string connString = String.Empty;
47 string realm = "hg_traveling_data";
48
49 //
50 // Try reading the [DatabaseService] section, if it exists
51 //
52 IConfig dbConfig = config.Configs["DatabaseService"];
53 if (dbConfig != null)
54 {
55 if (dllName == String.Empty)
56 dllName = dbConfig.GetString("StorageProvider", String.Empty);
57 if (connString == String.Empty)
58 connString = dbConfig.GetString("ConnectionString", String.Empty);
59 }
60
61 //
62 // [UserAgentService] section overrides [DatabaseService], if it exists
63 //
64 IConfig gridConfig = config.Configs["UserAgentService"];
65 if (gridConfig != null)
66 {
67 dllName = gridConfig.GetString("StorageProvider", dllName);
68 connString = gridConfig.GetString("ConnectionString", connString);
69 realm = gridConfig.GetString("Realm", realm);
70 }
71
72 //
73 // We tried, but this doesn't exist. We can't proceed.
74 //
75 if (dllName.Equals(String.Empty))
76 throw new Exception("No StorageProvider configured");
77
78 m_Database = LoadPlugin<IHGTravelingData>(dllName, new Object[] { connString, realm });
79 if (m_Database == null)
80 throw new Exception("Could not find a storage interface in the given module");
81
82 }
83 }
84}