aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService/UserAgentService.cs
diff options
context:
space:
mode:
authorDiva Canto2011-05-23 19:45:39 -0700
committerDiva Canto2011-05-23 19:45:39 -0700
commit24f28d353427d1905ae1a46408841265379e29c3 (patch)
tree07234a5837632bbe0d1198bf282d023c9cd1fb43 /OpenSim/Services/HypergridService/UserAgentService.cs
parentMore on HG Friends. Added Delete(string, string) across the board. Added secu... (diff)
downloadopensim-SC-24f28d353427d1905ae1a46408841265379e29c3.zip
opensim-SC-24f28d353427d1905ae1a46408841265379e29c3.tar.gz
opensim-SC-24f28d353427d1905ae1a46408841265379e29c3.tar.bz2
opensim-SC-24f28d353427d1905ae1a46408841265379e29c3.tar.xz
HG friends: Status notifications working. Also initial logins get the online friends in other grids.
Diffstat (limited to '')
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs172
1 files changed, 169 insertions, 3 deletions
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs
index 445d45e..0181533 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,34 @@ 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 IFriendsSimConnector m_FriendsLocalSimConnector; // standalone, points to HGFriendsModule
71 protected static FriendsSimConnector m_FriendsSimConnector; // grid
66 72
67 protected static string m_GridName; 73 protected static string m_GridName;
68 74
69 protected static bool m_BypassClientVerification; 75 protected static bool m_BypassClientVerification;
70 76
71 public UserAgentService(IConfigSource config) 77 public UserAgentService(IConfigSource config) : this(config, null)
72 { 78 {
79 }
80
81 public UserAgentService(IConfigSource config, IFriendsSimConnector friendsConnector)
82 {
83 // Let's set this always, because we don't know the sequence
84 // of instantiations
85 if (friendsConnector != null)
86 m_FriendsLocalSimConnector = friendsConnector;
87
73 if (!m_Initialized) 88 if (!m_Initialized)
74 { 89 {
75 m_Initialized = true; 90 m_Initialized = true;
76 91
77 m_log.DebugFormat("[HOME USERS SECURITY]: Starting..."); 92 m_log.DebugFormat("[HOME USERS SECURITY]: Starting...");
78 93
94 m_FriendsSimConnector = new FriendsSimConnector();
95
79 IConfig serverConfig = config.Configs["UserAgentService"]; 96 IConfig serverConfig = config.Configs["UserAgentService"];
80 if (serverConfig == null) 97 if (serverConfig == null)
81 throw new Exception(String.Format("No section UserAgentService in config file")); 98 throw new Exception(String.Format("No section UserAgentService in config file"));
@@ -83,6 +100,8 @@ namespace OpenSim.Services.HypergridService
83 string gridService = serverConfig.GetString("GridService", String.Empty); 100 string gridService = serverConfig.GetString("GridService", String.Empty);
84 string gridUserService = serverConfig.GetString("GridUserService", String.Empty); 101 string gridUserService = serverConfig.GetString("GridUserService", String.Empty);
85 string gatekeeperService = serverConfig.GetString("GatekeeperService", String.Empty); 102 string gatekeeperService = serverConfig.GetString("GatekeeperService", String.Empty);
103 string friendsService = serverConfig.GetString("FriendsService", String.Empty);
104 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
86 105
87 m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false); 106 m_BypassClientVerification = serverConfig.GetBoolean("BypassClientVerification", false);
88 107
@@ -94,6 +113,8 @@ namespace OpenSim.Services.HypergridService
94 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args); 113 m_GridUserService = ServerUtils.LoadPlugin<IGridUserService>(gridUserService, args);
95 m_GatekeeperConnector = new GatekeeperServiceConnector(); 114 m_GatekeeperConnector = new GatekeeperServiceConnector();
96 m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(gatekeeperService, args); 115 m_GatekeeperService = ServerUtils.LoadPlugin<IGatekeeperService>(gatekeeperService, args);
116 m_FriendsService = ServerUtils.LoadPlugin<IFriendsService>(friendsService, args);
117 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
97 118
98 m_GridName = serverConfig.GetString("ExternalName", string.Empty); 119 m_GridName = serverConfig.GetString("ExternalName", string.Empty);
99 if (m_GridName == string.Empty) 120 if (m_GridName == string.Empty)
@@ -156,11 +177,16 @@ namespace OpenSim.Services.HypergridService
156 string gridName = gatekeeper.ServerURI; 177 string gridName = gatekeeper.ServerURI;
157 178
158 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName); 179 m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {1}", m_GridName, gridName);
159 180
160 if (m_GridName == gridName) 181 if (m_GridName == gridName)
161 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason); 182 success = m_GatekeeperService.LoginAgent(agentCircuit, finalDestination, out reason);
162 else 183 else
184 {
163 success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason); 185 success = m_GatekeeperConnector.CreateAgent(region, agentCircuit, (uint)Constants.TeleportFlags.ViaLogin, out myExternalIP, out reason);
186 if (success)
187 // Report them as nowhere
188 m_PresenceService.ReportAgent(agentCircuit.SessionID, UUID.Zero);
189 }
164 190
165 if (!success) 191 if (!success)
166 { 192 {
@@ -179,6 +205,7 @@ namespace OpenSim.Services.HypergridService
179 if (clientIP != null) 205 if (clientIP != null)
180 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); 206 m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString();
181 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; 207 m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP;
208
182 return true; 209 return true;
183 } 210 }
184 211
@@ -291,6 +318,145 @@ namespace OpenSim.Services.HypergridService
291 return false; 318 return false;
292 } 319 }
293 320
321 public void StatusNotification(List<string> friends, UUID foreignUserID, bool online)
322 {
323 if (m_FriendsService == null || m_PresenceService == null)
324 {
325 m_log.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing");
326 return;
327 }
328
329 m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count);
330
331 // First, let's double check that the reported friends are, indeed, friends of that user
332 // And let's check that the secret matches
333 List<string> usersToBeNotified = new List<string>();
334 foreach (string uui in friends)
335 {
336 UUID localUserID;
337 string secret = string.Empty, tmp = string.Empty;
338 if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
339 {
340 FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
341 foreach (FriendInfo finfo in friendInfos)
342 {
343 if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret))
344 {
345 // great!
346 usersToBeNotified.Add(localUserID.ToString());
347 }
348 }
349 }
350 }
351
352 // Now, let's send the notifications
353 m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count);
354
355 // First, let's send notifications to local users who are online in the home grid
356 PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
357 if (friendSessions != null && friendSessions.Length > 0)
358 {
359 PresenceInfo friendSession = null;
360 foreach (PresenceInfo pinfo in friendSessions)
361 if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents
362 {
363 friendSession = pinfo;
364 break;
365 }
366
367 if (friendSession != null)
368 {
369 ForwardStatusNotificationToSim(friendSession.RegionID, friendSession.UserID, foreignUserID, online);
370 usersToBeNotified.Remove(friendSession.UserID.ToString());
371 }
372 }
373
374 // Lastly, let's notify the rest who may be online somewhere else
375 foreach (string user in usersToBeNotified)
376 {
377 UUID id = new UUID(user);
378 if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName)
379 {
380 string url = m_TravelingAgents[id].GridExternalName;
381 // forward
382 m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url);
383 }
384 }
385 }
386
387 protected void ForwardStatusNotificationToSim(UUID regionID, string user, UUID foreignUserID, bool online)
388 {
389 UUID userID;
390 if (UUID.TryParse(user, out userID))
391 {
392 if (m_FriendsLocalSimConnector != null)
393 {
394 m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline"));
395 m_FriendsLocalSimConnector.StatusNotify(userID, foreignUserID, online);
396 }
397 else
398 {
399 GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID);
400 if (region != null)
401 {
402 m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, user, foreignUserID, (online ? "online" : "offline"));
403 m_FriendsSimConnector.StatusNotify(region, userID, foreignUserID, online);
404 }
405 }
406 }
407 }
408
409 public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends)
410 {
411 List<UUID> online = new List<UUID>();
412
413 if (m_FriendsService == null || m_PresenceService == null)
414 {
415 m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing");
416 return online;
417 }
418
419 m_log.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count);
420
421 // First, let's double check that the reported friends are, indeed, friends of that user
422 // And let's check that the secret matches and the rights
423 List<string> usersToBeNotified = new List<string>();
424 foreach (string uui in friends)
425 {
426 UUID localUserID;
427 string secret = string.Empty, tmp = string.Empty;
428 if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret))
429 {
430 FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID);
431 foreach (FriendInfo finfo in friendInfos)
432 {
433 if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) &&
434 (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1))
435 {
436 // great!
437 usersToBeNotified.Add(localUserID.ToString());
438 }
439 }
440 }
441 }
442
443 // Now, let's find out their status
444 m_log.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count);
445
446 // First, let's send notifications to local users who are online in the home grid
447 PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray());
448 if (friendSessions != null && friendSessions.Length > 0)
449 {
450 foreach (PresenceInfo pi in friendSessions)
451 {
452 UUID presenceID;
453 if (UUID.TryParse(pi.UserID, out presenceID))
454 online.Add(presenceID);
455 }
456 }
457
458 return online;
459 }
294 } 460 }
295 461
296 class TravelingAgentInfo 462 class TravelingAgentInfo