aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService/UserAgentService.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs252
1 files changed, 247 insertions, 5 deletions
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index 09e785f..ac53583 100644
--- a/OpenSim/Services/HypergridService/UserAgentService.cs
+++ b/OpenSim/Services/HypergridService/UserAgentService.cs
@@ -31,10 +31,12 @@ using System.Net;
31using System.Reflection; 31using System.Reflection;
32 32
33using OpenSim.Framework; 33using OpenSim.Framework;
34using OpenSim.Services.Connectors.Friends;
34using OpenSim.Services.Connectors.Hypergrid; 35using OpenSim.Services.Connectors.Hypergrid;
35using OpenSim.Services.Interfaces; 36using OpenSim.Services.Interfaces;
36using GridRegion = OpenSim.Services.Interfaces.GridRegion; 37using GridRegion = OpenSim.Services.Interfaces.GridRegion;
37using OpenSim.Server.Base; 38using OpenSim.Server.Base;
39using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
38 40
39using OpenMetaverse; 41using OpenMetaverse;
40using log4net; 42using log4net;
@@ -63,19 +65,35 @@ namespace OpenSim.Services.HypergridService
63 protected static IGridService m_GridService; 65 protected static IGridService m_GridService;
64 protected static GatekeeperServiceConnector m_GatekeeperConnector; 66 protected static GatekeeperServiceConnector m_GatekeeperConnector;
65 protected static IGatekeeperService m_GatekeeperService; 67 protected static IGatekeeperService m_GatekeeperService;
68 protected static IFriendsService m_FriendsService;
69 protected static IPresenceService m_PresenceService;
70 protected static IUserAccountService m_UserAccountService;
71 protected static IFriendsSimConnector m_FriendsLocalSimConnector; // standalone, points to HGFriendsModule
72 protected static FriendsSimConnector m_FriendsSimConnector; // grid
66 73
67 protected static string m_GridName; 74 protected static string m_GridName;
68 75
69 protected static bool m_BypassClientVerification; 76 protected static bool m_BypassClientVerification;
70 77
71 public UserAgentService(IConfigSource config) 78 public UserAgentService(IConfigSource config) : this(config, null)
72 { 79 {
80 }
81
82 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
83 {
84 // Let's set this always, because we don't know the sequence
85 // of instantiations
86 if (friendsConnector != null)
87 m_FriendsLocalSimConnector = friendsConnector;
88
73 if (!m_Initialized) 89 if (!m_Initialized)
74 { 90 {
75 m_Initialized = true; 91 m_Initialized = true;
76 92
77 m_log.DebugFormat("[HOME USERS SECURITY]: Starting..."); 93 m_log.DebugFormat("[HOME USERS SECURITY]: Starting...");
78 94
95 m_FriendsSimConnector = new FriendsSimConnector();
96
79 IConfig serverConfig = config.Configs["UserAgentService"]; 97 IConfig serverConfig = config.Configs["UserAgentService"];
80 if (serverConfig == null) 98 if (serverConfig == null)
81 throw new Exception(String.Format("No section UserAgentService in config file")); 99 throw new Exception(String.Format("No section UserAgentService in config file"));
@@ -83,6 +101,9 @@ namespace OpenSim.Services.HypergridService
83 string gridService = serverConfig.GetString("GridService", String.Empty); 101 string gridService = serverConfig.GetString("GridService", String.Empty);
84 string gridUserService = serverConfig.GetString("GridUserService", String.Empty); 102 string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
85 string gatekeeperService = serverConfig.GetString("GatekeeperService", String.Empty); 103 string gatekeeperService = serverConfig.GetString("GatekeeperService", String.Empty);
104 string friendsService = serverConfig.GetString("FriendsService", String.Empty);
105 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
106 string userAccountService = serverConfig.GetString("UserAccountService", String.Empty);
86 107
87 m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false); 108 m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false);
88 109
@@ -94,6 +115,9 @@ namespace OpenSim.Services.HypergridService
94 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args); 115 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
95 m_GatekeeperConnector = new GatekeeperServiceConnector(); 116 m_GatekeeperConnector = new GatekeeperServiceConnector();
96 m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(gatekeeperService, args); 117 m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(gatekeeperService, args);
118 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args);
119 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
120 m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(userAccountService, args);
97 121
98 m_GridName = serverConfig.GetString("ExternalName", string.Empty); 122 m_GridName = serverConfig.GetString("ExternalName", string.Empty);
99 if (m_GridName == string.Empty) 123 if (m_GridName == string.Empty)
@@ -155,12 +179,17 @@ namespace OpenSim.Services.HypergridService
155 string myExternalIP = string.Empty; 179 string myExternalIP = string.Empty;
156 string gridName = gatekeeper.ServerURI; 180 string gridName = gatekeeper.ServerURI;
157 181
158 m_log.DebugFormat("[USER AGENT SERVICE]: m_grid - {0}, gn - {1}", m_GridName, gridName); 182 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName);
159 183
160 if (m_GridName == gridName) 184 if (m_GridName == gridName)
161 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); 185 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason);
162 else 186 else
187 {
163 success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason); 188 success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason);
189 if (success)
190 // Report them as nowhere
191 m_PresenceService.ReportAgent(agentCircuit.SessionID, UUID.Zero);
192 }
164 193
165 if (!success) 194 if (!success)
166 { 195 {
@@ -169,7 +198,12 @@ namespace OpenSim.Services.HypergridService
169 198
170 // restore the old travel info 199 // restore the old travel info
171 lock (m_TravelingAgents) 200 lock (m_TravelingAgents)
172 m_TravelingAgents[agentCircuit.SessionID] = old; 201 {
202 if (old == null)
203 m_TravelingAgents.Remove(agentCircuit.SessionID);
204 else
205 m_TravelingAgents[agentCircuit.SessionID] = old;
206 }
173 207
174 return false; 208 return false;
175 } 209 }
@@ -179,6 +213,7 @@ namespace OpenSim.Services.HypergridService
179 if (clientIP != null) 213 if (clientIP != null)
180 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); 214 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString();
181 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; 215 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
216
182 return true; 217 return true;
183 } 218 }
184 219
@@ -289,6 +324,213 @@ namespace OpenSim.Services.HypergridService
289 return false; 324 return false;
290 } 325 }
291 326
327 public List<UUID> StatusNotification(List<string> friends, UUID foreignUserID, bool online)
328 {
329 if (m_FriendsService == null || m_PresenceService == null)
330 {
331 m_log.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing");
332 return new List<UUID>();
333 }
334
335 List<UUID> localFriendsOnline = new List<UUID>();
336
337 m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count);
338
339 // First, let's double check that the reported friends are, indeed, friends of that user
340 // And let's check that the secret matches
341 List<string> usersToBeNotified = new List<string>();
342 foreach (string uui in friends)
343 {
344 UUID localUserID;
345 string secret = string.Empty, tmp = string.Empty;
346 if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
347 {
348 FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
349 foreach (FriendInfo finfo in friendInfos)
350 {
351 if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret))
352 {
353 // great!
354 usersToBeNotified.Add(localUserID.ToString());
355 }
356 }
357 }
358 }
359
360 // Now, let's send the notifications
361 m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count);
362
363 // First, let's send notifications to local users who are online in the home grid
364 PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
365 if (friendSessions != null && friendSessions.Length > 0)
366 {
367 PresenceInfo friendSession = null;
368 foreach (PresenceInfo pinfo in friendSessions)
369 if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents
370 {
371 friendSession = pinfo;
372 break;
373 }
374
375 if (friendSession != null)
376 {
377 ForwardStatusNotificationToSim(friendSession.RegionID, foreignUserID, friendSession.UserID, online);
378 usersToBeNotified.Remove(friendSession.UserID.ToString());
379 UUID id;
380 if (UUID.TryParse(friendSession.UserID, out id))
381 localFriendsOnline.Add(id);
382
383 }
384 }
385
386 // Lastly, let's notify the rest who may be online somewhere else
387 foreach (string user in usersToBeNotified)
388 {
389 UUID id = new UUID(user);
390 if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName)
391 {
392 string url = m_TravelingAgents[id].GridExternalName;
393 // forward
394 m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
395 }
396 }
397
398 // and finally, let's send the online friends
399 if (online)
400 {
401 return localFriendsOnline;
402 }
403 else
404 return new List<UUID>();
405 }
406
407 protected void ForwardStatusNotificationToSim(UUID regionID, UUID foreignUserID, string user, bool online)
408 {
409 UUID userID;
410 if (UUID.TryParse(user, out userID))
411 {
412 if (m_FriendsLocalSimConnector != null)
413 {
414 m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline"));
415 m_FriendsLocalSimConnector.StatusNotify(foreignUserID, userID, online);
416 }
417 else
418 {
419 GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID);
420 if (region != null)
421 {
422 m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, foreignUserID, (online ? "online" : "offline"));
423 m_FriendsSimConnector.StatusNotify(region, foreignUserID, userID, online);
424 }
425 }
426 }
427 }
428
429 public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends)
430 {
431 List<UUID> online = new List<UUID>();
432
433 if (m_FriendsService == null || m_PresenceService == null)
434 {
435 m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
436 return online;
437 }
438
439 m_log.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count);
440
441 // First, let's double check that the reported friends are, indeed, friends of that user
442 // And let's check that the secret matches and the rights
443 List<string> usersToBeNotified = new List<string>();
444 foreach (string uui in friends)
445 {
446 UUID localUserID;
447 string secret = string.Empty, tmp = string.Empty;
448 if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
449 {
450 FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
451 foreach (FriendInfo finfo in friendInfos)
452 {
453 if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) &&
454 (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1))
455 {
456 // great!
457 usersToBeNotified.Add(localUserID.ToString());
458 }
459 }
460 }
461 }
462
463 // Now, let's find out their status
464 m_log.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count);
465
466 // First, let's send notifications to local users who are online in the home grid
467 PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
468 if (friendSessions != null && friendSessions.Length > 0)
469 {
470 foreach (PresenceInfo pi in friendSessions)
471 {
472 UUID presenceID;
473 if (UUID.TryParse(pi.UserID, out presenceID))
474 online.Add(presenceID);
475 }
476 }
477
478 return online;
479 }
480
481 public Dictionary<string, object> GetServerURLs(UUID userID)
482 {
483 if (m_UserAccountService == null)
484 {
485 m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get server URLs because user account service is missing");
486 return new Dictionary<string, object>();
487 }
488 UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID);
489 if (account != null)
490 return account.ServiceURLs;
491
492 return new Dictionary<string, object>();
493 }
494
495 public string LocateUser(UUID userID)
496 {
497 foreach (TravelingAgentInfo t in m_TravelingAgents.Values)
498 {
499 if (t == null)
500 {
501 m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis");
502 continue;
503 }
504 if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName))
505 return t.GridExternalName;
506 }
507
508 return string.Empty;
509 }
510
511 public string GetUUI(UUID userID, UUID targetUserID)
512 {
513 // Let's see if it's a local user
514 UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, targetUserID);
515 if (account != null)
516 return targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName ;
517
518 // Let's try the list of friends
519 FriendInfo[] friends = m_FriendsService.GetFriends(userID);
520 if (friends != null && friends.Length > 0)
521 {
522 foreach (FriendInfo f in friends)
523 if (f.Friend.StartsWith(targetUserID.ToString()))
524 {
525 // Let's remove the secret
526 UUID id; string tmp = string.Empty, secret = string.Empty;
527 if (Util.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret))
528 return f.Friend.Replace(secret, "0");
529 }
530 }
531
532 return string.Empty;
533 }
292 } 534 }
293 535
294 class TravelingAgentInfo 536 class TravelingAgentInfo