aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/HypergridService')
-rw-r--r--OpenSim/Services/HypergridService/GatekeeperService.cs43
-rw-r--r--OpenSim/Services/HypergridService/HGInventoryService.cs2
-rw-r--r--OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs69
-rw-r--r--OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs2
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs216
-rw-r--r--OpenSim/Services/HypergridService/UserAgentServiceBase.cs84
6 files changed, 303 insertions, 113 deletions
diff --git a/OpenSim/Services/HypergridService/GatekeeperService.cs b/OpenSim/Services/HypergridService/GatekeeperService.cs
index 97a0afc..f6136b5 100644
--- a/OpenSim/Services/HypergridService/GatekeeperService.cs
+++ b/OpenSim/Services/HypergridService/GatekeeperService.cs
@@ -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)
@@ -121,6 +123,8 @@ namespace OpenSim.Services.HypergridService
121 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args); 123 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(homeUsersService, args);
122 if (gridUserService != string.Empty) 124 if (gridUserService != string.Empty)
123 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);
124 128
125 if (simService != null) 129 if (simService != null)
126 m_SimulationService = simService; 130 m_SimulationService = simService;
@@ -167,7 +171,7 @@ namespace OpenSim.Services.HypergridService
167 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName); 171 m_log.DebugFormat("[GATEKEEPER SERVICE]: Request to link to {0}", (regionName == string.Empty)? "default region" : regionName);
168 if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty) 172 if (!m_AllowTeleportsToAnyRegion || regionName == string.Empty)
169 { 173 {
170 List<GridRegion> defs = m_GridService.GetDefaultRegions(m_ScopeID); 174 List<GridRegion> defs = m_GridService.GetDefaultHypergridRegions(m_ScopeID);
171 if (defs != null && defs.Count > 0) 175 if (defs != null && defs.Count > 0)
172 { 176 {
173 region = defs[0]; 177 region = defs[0];
@@ -223,7 +227,7 @@ namespace OpenSim.Services.HypergridService
223 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}", 227 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}",
224 aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName, 228 aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionName,
225 aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, aCircuit.teleportFlags.ToString()); 229 aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, aCircuit.teleportFlags.ToString());
226 230
227 // 231 //
228 // Check client 232 // Check client
229 // 233 //
@@ -287,17 +291,16 @@ namespace OpenSim.Services.HypergridService
287 } 291 }
288 } 292 }
289 } 293 }
290 m_log.DebugFormat("[GATEKEEPER SERVICE]: User is ok");
291 294
292 // 295 //
293 // Foreign agents allowed? Exceptions? 296 // Foreign agents allowed? Exceptions?
294 // 297 //
295 if (account == null) 298 if (account == null)
296 { 299 {
297 bool allowed = m_ForeignAgentsAllowed; 300 bool allowed = m_ForeignAgentsAllowed;
298 301
299 if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions)) 302 if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions))
300 allowed = false; 303 allowed = false;
301 304
302 if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions)) 305 if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions))
303 allowed = true; 306 allowed = true;
@@ -311,6 +314,20 @@ namespace OpenSim.Services.HypergridService
311 } 314 }
312 } 315 }
313 316
317 //
318 // Is the user banned?
319 // This uses a Ban service that's more powerful than the configs
320 //
321 string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit));
322 if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL))
323 {
324 reason = "You are banned from this world";
325 m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui);
326 return false;
327 }
328
329 m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name);
330
314 bool isFirstLogin = false; 331 bool isFirstLogin = false;
315 // 332 //
316 // Login the presence, if it's not there yet (by the login service) 333 // Login the presence, if it's not there yet (by the login service)
@@ -328,7 +345,8 @@ namespace OpenSim.Services.HypergridService
328 aCircuit.firstname, aCircuit.lastname); 345 aCircuit.firstname, aCircuit.lastname);
329 return false; 346 return false;
330 } 347 }
331 m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence ok"); 348
349 m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name);
332 350
333 // Also login foreigners with GridUser service 351 // Also login foreigners with GridUser service
334 if (m_GridUserService != null && account == null) 352 if (m_GridUserService != null && account == null)
@@ -359,7 +377,9 @@ namespace OpenSim.Services.HypergridService
359 reason = "Destination region not found"; 377 reason = "Destination region not found";
360 return false; 378 return false;
361 } 379 }
362 m_log.DebugFormat("[GATEKEEPER SERVICE]: destination ok: {0}", destination.RegionName); 380
381 m_log.DebugFormat(
382 "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name);
363 383
364 // 384 //
365 // Adjust the visible name 385 // Adjust the visible name
@@ -393,7 +413,8 @@ namespace OpenSim.Services.HypergridService
393 // Preserve our TeleportFlags we have gathered so-far 413 // Preserve our TeleportFlags we have gathered so-far
394 loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags; 414 loginFlag |= (Constants.TeleportFlags) aCircuit.teleportFlags;
395 415
396 m_log.DebugFormat("[GATEKEEPER SERVICE]: launching agent {0}", loginFlag); 416 m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0} {1}", aCircuit.Name, loginFlag);
417
397 return m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, out reason); 418 return m_SimulationService.CreateAgent(destination, aCircuit, (uint)loginFlag, out reason);
398 } 419 }
399 420
@@ -402,6 +423,12 @@ namespace OpenSim.Services.HypergridService
402 if (!CheckAddress(aCircuit.ServiceSessionID)) 423 if (!CheckAddress(aCircuit.ServiceSessionID))
403 return false; 424 return false;
404 425
426 if (string.IsNullOrEmpty(aCircuit.IPAddress))
427 {
428 m_log.DebugFormat("[GATEKEEPER SERVICE]: Agent did not provide a client IP address.");
429 return false;
430 }
431
405 string userURL = string.Empty; 432 string userURL = string.Empty;
406 if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) 433 if (aCircuit.ServiceURLs.ContainsKey("HomeURI"))
407 userURL = aCircuit.ServiceURLs["HomeURI"].ToString(); 434 userURL = aCircuit.ServiceURLs["HomeURI"].ToString();
diff --git a/OpenSim/Services/HypergridService/HGInventoryService.cs b/OpenSim/Services/HypergridService/HGInventoryService.cs
index 326e68d..3233caf 100644
--- a/OpenSim/Services/HypergridService/HGInventoryService.cs
+++ b/OpenSim/Services/HypergridService/HGInventoryService.cs
@@ -298,7 +298,7 @@ namespace OpenSim.Services.HypergridService
298 UserAccount user = m_Cache.GetUser(it.CreatorId); 298 UserAccount user = m_Cache.GetUser(it.CreatorId);
299 299
300 // Adjust the creator data 300 // Adjust the creator data
301 if (user != null && it != null && (it.CreatorData == null || it.CreatorData == string.Empty)) 301 if (user != null && it != null && string.IsNullOrEmpty(it.CreatorData))
302 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName; 302 it.CreatorData = m_HomeURL + ";" + user.FirstName + " " + user.LastName;
303 } 303 }
304 return it; 304 return it;
diff --git a/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs b/OpenSim/Services/HypergridService/HGSuitcaseInventoryService.cs
index eecf757..835cde3 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 m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI", 99// m_HomeURL = Util.GetConfigVarFromSections<string>(config, "HomeURI",
100 new string[] { "Startup", "Hypergrid", m_ConfigName }, String.Empty); 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,6 +115,12 @@ 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 == null || (tree != null && tree.Count == 0))
120 return null; 126 return null;
@@ -134,6 +140,7 @@ namespace OpenSim.Services.HypergridService
134 public override InventoryCollection GetUserInventory(UUID userID) 140 public override InventoryCollection GetUserInventory(UUID userID)
135 { 141 {
136 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID); 142 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: Get Suitcase inventory for user {0}", userID);
143
137 InventoryCollection userInventory = new InventoryCollection(); 144 InventoryCollection userInventory = new InventoryCollection();
138 userInventory.UserID = userID; 145 userInventory.UserID = userID;
139 userInventory.Folders = new List<InventoryFolderBase>(); 146 userInventory.Folders = new List<InventoryFolderBase>();
@@ -141,6 +148,12 @@ namespace OpenSim.Services.HypergridService
141 148
142 XInventoryFolder suitcase = GetSuitcaseXFolder(userID); 149 XInventoryFolder suitcase = GetSuitcaseXFolder(userID);
143 150
151 if (suitcase == null)
152 {
153 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for user inventory", userID);
154 return null;
155 }
156
144 List<XInventoryFolder> tree = GetFolderTree(userID, suitcase.folderID); 157 List<XInventoryFolder> tree = GetFolderTree(userID, suitcase.folderID);
145 if (tree == null || (tree != null && tree.Count == 0)) 158 if (tree == null || (tree != null && tree.Count == 0))
146 { 159 {
@@ -182,7 +195,8 @@ namespace OpenSim.Services.HypergridService
182 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID); 195 m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: GetRootFolder for {0}", principalID);
183 196
184 // Let's find out the local root folder 197 // Let's find out the local root folder
185 XInventoryFolder root = GetRootXFolder(principalID); ; 198 XInventoryFolder root = GetRootXFolder(principalID);
199
186 if (root == null) 200 if (root == null)
187 { 201 {
188 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID); 202 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to retrieve local root folder for user {0}", principalID);
@@ -199,16 +213,23 @@ namespace OpenSim.Services.HypergridService
199 // In the DB we tag it as type 100, but we use -1 (Unknown) outside 213 // In the DB we tag it as type 100, but we use -1 (Unknown) outside
200 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase"); 214 suitcase = CreateFolder(principalID, root.folderID, 100, "My Suitcase");
201 if (suitcase == null) 215 if (suitcase == null)
216 {
202 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder"); 217 m_log.ErrorFormat("[HG SUITCASE INVENTORY SERVICE]: Unable to create suitcase folder");
203 m_Database.StoreFolder(suitcase); 218 }
219 else
220 {
221 m_Database.StoreFolder(suitcase);
204 222
205 // Create System folders 223 // Create System folders
206 CreateSystemFolders(principalID, suitcase.folderID); 224 CreateSystemFolders(principalID, suitcase.folderID);
207 }
208 225
209 SetAsNormalFolder(suitcase); 226 SetAsNormalFolder(suitcase);
210 227
211 return ConvertToOpenSim(suitcase); 228 return ConvertToOpenSim(suitcase);
229 }
230 }
231
232 return null;
212 } 233 }
213 234
214 protected void CreateSystemFolders(UUID principalID, UUID rootID) 235 protected void CreateSystemFolders(UUID principalID, UUID rootID)
@@ -255,6 +276,13 @@ namespace OpenSim.Services.HypergridService
255 { 276 {
256 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type); 277 //m_log.DebugFormat("[HG INVENTORY SERVICE]: GetFolderForType for {0} {0}", principalID, type);
257 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 278 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
279
280 if (suitcase == null)
281 {
282 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: Found no suitcase folder for user {0} when looking for child type folder {1}", principalID, type);
283 return null;
284 }
285
258 XInventoryFolder[] folders = m_Database.GetFolders( 286 XInventoryFolder[] folders = m_Database.GetFolders(
259 new string[] { "agentID", "type", "parentFolderID" }, 287 new string[] { "agentID", "type", "parentFolderID" },
260 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() }); 288 new string[] { principalID.ToString(), ((int)type).ToString(), suitcase.folderID.ToString() });
@@ -472,6 +500,22 @@ namespace OpenSim.Services.HypergridService
472 return null; 500 return null;
473 } 501 }
474 502
503 private XInventoryFolder GetCurrentOutfitXFolder(UUID userID)
504 {
505 XInventoryFolder root = GetRootXFolder(userID);
506 if (root == null)
507 return null;
508
509 XInventoryFolder[] folders = m_Database.GetFolders(
510 new string[] { "agentID", "type", "parentFolderID" },
511 new string[] { userID.ToString(), ((int)AssetType.CurrentOutfitFolder).ToString(), root.folderID.ToString() });
512
513 if (folders.Length == 0)
514 return null;
515
516 return folders[0];
517 }
518
475 private XInventoryFolder GetSuitcaseXFolder(UUID principalID) 519 private XInventoryFolder GetSuitcaseXFolder(UUID principalID)
476 { 520 {
477 // Warp! Root folder for travelers 521 // Warp! Root folder for travelers
@@ -510,6 +554,7 @@ namespace OpenSim.Services.HypergridService
510 if (m_SuitcaseTrees.TryGetValue(principalID, out t)) 554 if (m_SuitcaseTrees.TryGetValue(principalID, out t))
511 return t; 555 return t;
512 556
557 // Get the tree of the suitcase folder
513 t = GetFolderTreeRecursive(folder); 558 t = GetFolderTreeRecursive(folder);
514 m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes 559 m_SuitcaseTrees.AddOrUpdate(principalID, t, 5*60); // 5minutes
515 return t; 560 return t;
@@ -546,6 +591,7 @@ namespace OpenSim.Services.HypergridService
546 private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID) 591 private bool IsWithinSuitcaseTree(UUID principalID, UUID folderID)
547 { 592 {
548 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID); 593 XInventoryFolder suitcase = GetSuitcaseXFolder(principalID);
594
549 if (suitcase == null) 595 if (suitcase == null)
550 { 596 {
551 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID); 597 m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: User {0} does not have a Suitcase folder", principalID);
@@ -555,6 +601,9 @@ namespace OpenSim.Services.HypergridService
555 List<XInventoryFolder> tree = new List<XInventoryFolder>(); 601 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 602 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)); 603 tree.AddRange(GetFolderTree(principalID, suitcase.folderID));
604 // Also add the Current Outfit folder to the list of available folders
605 tree.Add(GetCurrentOutfitXFolder(principalID));
606
558 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl) 607 XInventoryFolder f = tree.Find(delegate(XInventoryFolder fl)
559 { 608 {
560 if (fl.folderID == folderID) return true; 609 if (fl.folderID == folderID) return true;
diff --git a/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs b/OpenSim/Services/HypergridService/Properties/AssemblyInfo.cs
index 8d66f1b..0fb60f6 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.6.*")] 32[assembly: AssemblyVersion("0.8.0.*")]
33 33
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index ec76508..b414aca 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
@@ -86,6 +87,7 @@ namespace OpenSim.Services.HypergridService
86 } 87 }
87 88
88 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector) 89 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
90 : base(config)
89 { 91 {
90 // Let's set this always, because we don't know the sequence 92 // Let's set this always, because we don't know the sequence
91 // of instantiations 93 // of instantiations
@@ -146,6 +148,9 @@ namespace OpenSim.Services.HypergridService
146 if (!m_GridName.EndsWith("/")) 148 if (!m_GridName.EndsWith("/"))
147 m_GridName = m_GridName + "/"; 149 m_GridName = m_GridName + "/";
148 150
151 // Finally some cleanup
152 m_Database.DeleteOld();
153
149 } 154 }
150 } 155 }
151 156
@@ -210,10 +215,10 @@ namespace OpenSim.Services.HypergridService
210 return home; 215 return home;
211 } 216 }
212 217
213 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, IPEndPoint clientIP, out string reason) 218 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, bool fromLogin, out string reason)
214 { 219 {
215 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}", 220 m_log.DebugFormat("[USER AGENT SERVICE]: Request to login user {0} {1} (@{2}) to grid {3}",
216 agentCircuit.firstname, agentCircuit.lastname, ((clientIP == null) ? "stored IP" : clientIP.Address.ToString()), gatekeeper.ServerURI); 221 agentCircuit.firstname, agentCircuit.lastname, (fromLogin ? agentCircuit.IPAddress : "stored IP"), gatekeeper.ServerURI);
217 222
218 string gridName = gatekeeper.ServerURI; 223 string gridName = gatekeeper.ServerURI;
219 224
@@ -260,12 +265,13 @@ namespace OpenSim.Services.HypergridService
260 265
261 // Generate a new service session 266 // Generate a new service session
262 agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random(); 267 agentCircuit.ServiceSessionID = region.ServerURI + ";" + UUID.Random();
263 TravelingAgentInfo old = UpdateTravelInfo(agentCircuit, region); 268 TravelingAgentInfo old = null;
269 TravelingAgentInfo travel = CreateTravelInfo(agentCircuit, region, fromLogin, out old);
264 270
265 bool success = false; 271 bool success = false;
266 string myExternalIP = string.Empty; 272 string myExternalIP = string.Empty;
267 273
268 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName); 274 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}, desired region: {2}", m_GridName, gridName, region.RegionID);
269 275
270 if (m_GridName == gridName) 276 if (m_GridName == gridName)
271 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); 277 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason);
@@ -282,23 +288,21 @@ namespace OpenSim.Services.HypergridService
282 m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}", 288 m_log.DebugFormat("[USER AGENT SERVICE]: Unable to login user {0} {1} to grid {2}, reason: {3}",
283 agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); 289 agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason);
284 290
285 // restore the old travel info 291 if (old != null)
286 lock (m_TravelingAgents) 292 StoreTravelInfo(old);
287 { 293 else
288 if (old == null) 294 m_Database.Delete(agentCircuit.SessionID);
289 m_TravelingAgents.Remove(agentCircuit.SessionID);
290 else
291 m_TravelingAgents[agentCircuit.SessionID] = old;
292 }
293 295
294 return false; 296 return false;
295 } 297 }
296 298
299 // Everything is ok
300
301 // Update the perceived IP Address of our grid
297 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP); 302 m_log.DebugFormat("[USER AGENT SERVICE]: Gatekeeper sees me as {0}", myExternalIP);
298 // else set the IP addresses associated with this client 303 travel.MyIpAddress = myExternalIP;
299 if (clientIP != null) 304
300 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); 305 StoreTravelInfo(travel);
301 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
302 306
303 return true; 307 return true;
304 } 308 }
@@ -306,60 +310,42 @@ namespace OpenSim.Services.HypergridService
306 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason) 310 public bool LoginAgentToGrid(AgentCircuitData agentCircuit, GridRegion gatekeeper, GridRegion finalDestination, out string reason)
307 { 311 {
308 reason = string.Empty; 312 reason = string.Empty;
309 return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, null, out reason); 313 return LoginAgentToGrid(agentCircuit, gatekeeper, finalDestination, false, out reason);
310 } 314 }
311 315
312 private void SetClientIP(UUID sessionID, string ip) 316 TravelingAgentInfo CreateTravelInfo(AgentCircuitData agentCircuit, GridRegion region, bool fromLogin, out TravelingAgentInfo existing)
313 { 317 {
314 if (m_TravelingAgents.ContainsKey(sessionID)) 318 HGTravelingData hgt = m_Database.Get(agentCircuit.SessionID);
315 { 319 existing = null;
316 m_log.DebugFormat("[USER AGENT SERVICE]: Setting IP {0} for session {1}", ip, sessionID);
317 m_TravelingAgents[sessionID].ClientIPAddress = ip;
318 }
319 }
320 320
321 TravelingAgentInfo UpdateTravelInfo(AgentCircuitData agentCircuit, GridRegion region) 321 if (hgt != null)
322 {
323 TravelingAgentInfo travel = new TravelingAgentInfo();
324 TravelingAgentInfo old = null;
325 lock (m_TravelingAgents)
326 { 322 {
327 if (m_TravelingAgents.ContainsKey(agentCircuit.SessionID)) 323 // Very important! Override whatever this agent comes with.
328 { 324 // UserAgentService always sets the IP for every new agent
329 // Very important! Override whatever this agent comes with. 325 // with the original IP address.
330 // UserAgentService always sets the IP for every new agent 326 existing = new TravelingAgentInfo(hgt);
331 // with the original IP address. 327 agentCircuit.IPAddress = existing.ClientIPAddress;
332 agentCircuit.IPAddress = m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress;
333
334 old = m_TravelingAgents[agentCircuit.SessionID];
335 }
336
337 m_TravelingAgents[agentCircuit.SessionID] = travel;
338 } 328 }
329
330 TravelingAgentInfo travel = new TravelingAgentInfo(existing);
331 travel.SessionID = agentCircuit.SessionID;
339 travel.UserID = agentCircuit.AgentID; 332 travel.UserID = agentCircuit.AgentID;
340 travel.GridExternalName = region.ServerURI; 333 travel.GridExternalName = region.ServerURI;
341 travel.ServiceToken = agentCircuit.ServiceSessionID; 334 travel.ServiceToken = agentCircuit.ServiceSessionID;
342 if (old != null)
343 travel.ClientIPAddress = old.ClientIPAddress;
344 335
345 return old; 336 if (fromLogin)
337 travel.ClientIPAddress = agentCircuit.IPAddress;
338
339 StoreTravelInfo(travel);
340
341 return travel;
346 } 342 }
347 343
348 public void LogoutAgent(UUID userID, UUID sessionID) 344 public void LogoutAgent(UUID userID, UUID sessionID)
349 { 345 {
350 m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID); 346 m_log.DebugFormat("[USER AGENT SERVICE]: User {0} logged out", userID);
351 347
352 lock (m_TravelingAgents) 348 m_Database.Delete(sessionID);
353 {
354 List<UUID> travels = new List<UUID>();
355 foreach (KeyValuePair<UUID, TravelingAgentInfo> kvp in m_TravelingAgents)
356 if (kvp.Value == null) // do some clean up
357 travels.Add(kvp.Key);
358 else if (kvp.Value.UserID == userID)
359 travels.Add(kvp.Key);
360 foreach (UUID session in travels)
361 m_TravelingAgents.Remove(session);
362 }
363 349
364 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString()); 350 GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(userID.ToString());
365 if (guinfo != null) 351 if (guinfo != null)
@@ -369,10 +355,11 @@ namespace OpenSim.Services.HypergridService
369 // We need to prevent foreign users with the same UUID as a local user 355 // We need to prevent foreign users with the same UUID as a local user
370 public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName) 356 public bool IsAgentComingHome(UUID sessionID, string thisGridExternalName)
371 { 357 {
372 if (!m_TravelingAgents.ContainsKey(sessionID)) 358 HGTravelingData hgt = m_Database.Get(sessionID);
359 if (hgt == null)
373 return false; 360 return false;
374 361
375 TravelingAgentInfo travel = m_TravelingAgents[sessionID]; 362 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
376 363
377 return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower(); 364 return travel.GridExternalName.ToLower() == thisGridExternalName.ToLower();
378 } 365 }
@@ -385,29 +372,32 @@ namespace OpenSim.Services.HypergridService
385 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.", 372 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying Client session {0} with reported IP {1}.",
386 sessionID, reportedIP); 373 sessionID, reportedIP);
387 374
388 if (m_TravelingAgents.ContainsKey(sessionID)) 375 HGTravelingData hgt = m_Database.Get(sessionID);
389 { 376 if (hgt == null)
390 m_log.DebugFormat("[USER AGENT SERVICE]: Comparing with login IP {0} and MyIP {1}", 377 return false;
391 m_TravelingAgents[sessionID].ClientIPAddress, m_TravelingAgents[sessionID].MyIpAddress);
392 378
393 return m_TravelingAgents[sessionID].ClientIPAddress == reportedIP || 379 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
394 m_TravelingAgents[sessionID].MyIpAddress == reportedIP; // NATed 380
395 } 381 bool result = travel.ClientIPAddress == reportedIP || travel.MyIpAddress == reportedIP; // NATed
396 382
397 return false; 383 m_log.DebugFormat("[USER AGENT SERVICE]: Comparing {0} with login IP {1} and MyIP {1}; result is {3}",
384 reportedIP, travel.ClientIPAddress, travel.MyIpAddress, result);
385
386 return result;
398 } 387 }
399 388
400 public bool VerifyAgent(UUID sessionID, string token) 389 public bool VerifyAgent(UUID sessionID, string token)
401 { 390 {
402 if (m_TravelingAgents.ContainsKey(sessionID)) 391 HGTravelingData hgt = m_Database.Get(sessionID);
392 if (hgt == null)
403 { 393 {
404 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, m_TravelingAgents[sessionID].ServiceToken); 394 m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID);
405 return m_TravelingAgents[sessionID].ServiceToken == token; 395 return false;
406 } 396 }
407 397
408 m_log.DebugFormat("[USER AGENT SERVICE]: Token verification for session {0}: no such session", sessionID); 398 TravelingAgentInfo travel = new TravelingAgentInfo(hgt);
409 399 m_log.DebugFormat("[USER AGENT SERVICE]: Verifying agent token {0} against {1}", token, travel.ServiceToken);
410 return false; 400 return travel.ServiceToken == token;
411 } 401 }
412 402
413 [Obsolete] 403 [Obsolete]
@@ -470,17 +460,17 @@ namespace OpenSim.Services.HypergridService
470 } 460 }
471 } 461 }
472 462
473 // Lastly, let's notify the rest who may be online somewhere else 463 //// Lastly, let's notify the rest who may be online somewhere else
474 foreach (string user in usersToBeNotified) 464 //foreach (string user in usersToBeNotified)
475 { 465 //{
476 UUID id = new UUID(user); 466 // UUID id = new UUID(user);
477 if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) 467 // if (m_Database.ContainsKey(id) && m_Database[id].GridExternalName != m_GridName)
478 { 468 // {
479 string url = m_TravelingAgents[id].GridExternalName; 469 // string url = m_Database[id].GridExternalName;
480 // forward 470 // // forward
481 m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); 471 // m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
482 } 472 // }
483 } 473 //}
484 474
485 // and finally, let's send the online friends 475 // and finally, let's send the online friends
486 if (online) 476 if (online)
@@ -607,16 +597,13 @@ namespace OpenSim.Services.HypergridService
607 597
608 public string LocateUser(UUID userID) 598 public string LocateUser(UUID userID)
609 { 599 {
610 foreach (TravelingAgentInfo t in m_TravelingAgents.Values) 600 HGTravelingData[] hgts = m_Database.GetSessions(userID);
611 { 601 if (hgts == null)
612 if (t == null) 602 return string.Empty;
613 { 603
614 m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis"); 604 foreach (HGTravelingData t in hgts)
615 continue; 605 if (t.Data.ContainsKey("GridExternalName") && !m_GridName.Equals(t.Data["GridExternalName"]))
616 } 606 return t.Data["GridExternalName"];
617 if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName))
618 return t.GridExternalName;
619 }
620 607
621 return string.Empty; 608 return string.Empty;
622 } 609 }
@@ -687,17 +674,60 @@ namespace OpenSim.Services.HypergridService
687 return exception; 674 return exception;
688 } 675 }
689 676
677 private void StoreTravelInfo(TravelingAgentInfo travel)
678 {
679 if (travel == null)
680 return;
681
682 HGTravelingData hgt = new HGTravelingData();
683 hgt.SessionID = travel.SessionID;
684 hgt.UserID = travel.UserID;
685 hgt.Data = new Dictionary<string, string>();
686 hgt.Data["GridExternalName"] = travel.GridExternalName;
687 hgt.Data["ServiceToken"] = travel.ServiceToken;
688 hgt.Data["ClientIPAddress"] = travel.ClientIPAddress;
689 hgt.Data["MyIPAddress"] = travel.MyIpAddress;
690
691 m_Database.Store(hgt);
692 }
690 #endregion 693 #endregion
691 694
692 } 695 }
693 696
694 class TravelingAgentInfo 697 class TravelingAgentInfo
695 { 698 {
699 public UUID SessionID;
696 public UUID UserID; 700 public UUID UserID;
697 public string GridExternalName = string.Empty; 701 public string GridExternalName = string.Empty;
698 public string ServiceToken = string.Empty; 702 public string ServiceToken = string.Empty;
699 public string ClientIPAddress = string.Empty; // as seen from this user agent service 703 public string ClientIPAddress = string.Empty; // as seen from this user agent service
700 public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper 704 public string MyIpAddress = string.Empty; // the user agent service's external IP, as seen from the next gatekeeper
705
706 public TravelingAgentInfo(HGTravelingData t)
707 {
708 if (t.Data != null)
709 {
710 SessionID = new UUID(t.SessionID);
711 UserID = new UUID(t.UserID);
712 GridExternalName = t.Data["GridExternalName"];
713 ServiceToken = t.Data["ServiceToken"];
714 ClientIPAddress = t.Data["ClientIPAddress"];
715 MyIpAddress = t.Data["MyIPAddress"];
716 }
717 }
718
719 public TravelingAgentInfo(TravelingAgentInfo old)
720 {
721 if (old != null)
722 {
723 SessionID = old.SessionID;
724 UserID = old.UserID;
725 GridExternalName = old.GridExternalName;
726 ServiceToken = old.ServiceToken;
727 ClientIPAddress = old.ClientIPAddress;
728 MyIpAddress = old.MyIpAddress;
729 }
730 }
701 } 731 }
702 732
703} 733}
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}