diff options
Diffstat (limited to 'OpenSim/Services/HypergridService/UserAgentService.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/UserAgentService.cs | 224 |
1 files changed, 221 insertions, 3 deletions
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index 445d45e..387547e 100644 --- a/OpenSim/Services/HypergridService/UserAgentService.cs +++ b/OpenSim/Services/HypergridService/UserAgentService.cs | |||
@@ -31,10 +31,12 @@ using System.Net; | |||
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | 32 | ||
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Services.Connectors.Friends; | ||
34 | using OpenSim.Services.Connectors.Hypergrid; | 35 | using OpenSim.Services.Connectors.Hypergrid; |
35 | using OpenSim.Services.Interfaces; | 36 | using OpenSim.Services.Interfaces; |
36 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | 37 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; |
37 | using OpenSim.Server.Base; | 38 | using OpenSim.Server.Base; |
39 | using FriendInfo = OpenSim.Services.Interfaces.FriendInfo; | ||
38 | 40 | ||
39 | using OpenMetaverse; | 41 | using OpenMetaverse; |
40 | using log4net; | 42 | using 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) |
@@ -156,11 +180,16 @@ namespace OpenSim.Services.HypergridService | |||
156 | string gridName = gatekeeper.ServerURI; | 180 | string gridName = gatekeeper.ServerURI; |
157 | 181 | ||
158 | m_log.DebugFormat("[USER AGENT SERVICE]: this grid: {0}, desired grid: {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 | { |
@@ -179,6 +208,7 @@ namespace OpenSim.Services.HypergridService | |||
179 | if (clientIP != null) | 208 | if (clientIP != null) |
180 | m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); | 209 | m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); |
181 | m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; | 210 | m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; |
211 | |||
182 | return true; | 212 | return true; |
183 | } | 213 | } |
184 | 214 | ||
@@ -291,6 +321,194 @@ namespace OpenSim.Services.HypergridService | |||
291 | return false; | 321 | return false; |
292 | } | 322 | } |
293 | 323 | ||
324 | public void StatusNotification(List<string> friends, UUID foreignUserID, bool online) | ||
325 | { | ||
326 | if (m_FriendsService == null || m_PresenceService == null) | ||
327 | { | ||
328 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing"); | ||
329 | return; | ||
330 | } | ||
331 | |||
332 | m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count); | ||
333 | |||
334 | // First, let's double check that the reported friends are, indeed, friends of that user | ||
335 | // And let's check that the secret matches | ||
336 | List<string> usersToBeNotified = new List<string>(); | ||
337 | foreach (string uui in friends) | ||
338 | { | ||
339 | UUID localUserID; | ||
340 | string secret = string.Empty, tmp = string.Empty; | ||
341 | if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret)) | ||
342 | { | ||
343 | FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID); | ||
344 | foreach (FriendInfo finfo in friendInfos) | ||
345 | { | ||
346 | if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret)) | ||
347 | { | ||
348 | // great! | ||
349 | usersToBeNotified.Add(localUserID.ToString()); | ||
350 | } | ||
351 | } | ||
352 | } | ||
353 | } | ||
354 | |||
355 | // Now, let's send the notifications | ||
356 | m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count); | ||
357 | |||
358 | // First, let's send notifications to local users who are online in the home grid | ||
359 | PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray()); | ||
360 | if (friendSessions != null && friendSessions.Length > 0) | ||
361 | { | ||
362 | PresenceInfo friendSession = null; | ||
363 | foreach (PresenceInfo pinfo in friendSessions) | ||
364 | if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents | ||
365 | { | ||
366 | friendSession = pinfo; | ||
367 | break; | ||
368 | } | ||
369 | |||
370 | if (friendSession != null) | ||
371 | { | ||
372 | ForwardStatusNotificationToSim(friendSession.RegionID, friendSession.UserID, foreignUserID, online); | ||
373 | usersToBeNotified.Remove(friendSession.UserID.ToString()); | ||
374 | } | ||
375 | } | ||
376 | |||
377 | // Lastly, let's notify the rest who may be online somewhere else | ||
378 | foreach (string user in usersToBeNotified) | ||
379 | { | ||
380 | UUID id = new UUID(user); | ||
381 | if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) | ||
382 | { | ||
383 | string url = m_TravelingAgents[id].GridExternalName; | ||
384 | // forward | ||
385 | m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); | ||
386 | } | ||
387 | } | ||
388 | } | ||
389 | |||
390 | protected void ForwardStatusNotificationToSim(UUID regionID, string user, UUID foreignUserID, bool online) | ||
391 | { | ||
392 | UUID userID; | ||
393 | if (UUID.TryParse(user, out userID)) | ||
394 | { | ||
395 | if (m_FriendsLocalSimConnector != null) | ||
396 | { | ||
397 | m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline")); | ||
398 | m_FriendsLocalSimConnector.StatusNotify(userID, foreignUserID, online); | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID); | ||
403 | if (region != null) | ||
404 | { | ||
405 | m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, user, foreignUserID, (online ? "online" : "offline")); | ||
406 | m_FriendsSimConnector.StatusNotify(region, userID, foreignUserID, online); | ||
407 | } | ||
408 | } | ||
409 | } | ||
410 | } | ||
411 | |||
412 | public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends) | ||
413 | { | ||
414 | List<UUID> online = new List<UUID>(); | ||
415 | |||
416 | if (m_FriendsService == null || m_PresenceService == null) | ||
417 | { | ||
418 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing"); | ||
419 | return online; | ||
420 | } | ||
421 | |||
422 | m_log.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count); | ||
423 | |||
424 | // First, let's double check that the reported friends are, indeed, friends of that user | ||
425 | // And let's check that the secret matches and the rights | ||
426 | List<string> usersToBeNotified = new List<string>(); | ||
427 | foreach (string uui in friends) | ||
428 | { | ||
429 | UUID localUserID; | ||
430 | string secret = string.Empty, tmp = string.Empty; | ||
431 | if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret)) | ||
432 | { | ||
433 | FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID); | ||
434 | foreach (FriendInfo finfo in friendInfos) | ||
435 | { | ||
436 | if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) && | ||
437 | (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1)) | ||
438 | { | ||
439 | // great! | ||
440 | usersToBeNotified.Add(localUserID.ToString()); | ||
441 | } | ||
442 | } | ||
443 | } | ||
444 | } | ||
445 | |||
446 | // Now, let's find out their status | ||
447 | m_log.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count); | ||
448 | |||
449 | // First, let's send notifications to local users who are online in the home grid | ||
450 | PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray()); | ||
451 | if (friendSessions != null && friendSessions.Length > 0) | ||
452 | { | ||
453 | foreach (PresenceInfo pi in friendSessions) | ||
454 | { | ||
455 | UUID presenceID; | ||
456 | if (UUID.TryParse(pi.UserID, out presenceID)) | ||
457 | online.Add(presenceID); | ||
458 | } | ||
459 | } | ||
460 | |||
461 | return online; | ||
462 | } | ||
463 | |||
464 | public Dictionary<string, object> GetServerURLs(UUID userID) | ||
465 | { | ||
466 | if (m_UserAccountService == null) | ||
467 | { | ||
468 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get server URLs because user account service is missing"); | ||
469 | return new Dictionary<string, object>(); | ||
470 | } | ||
471 | UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID); | ||
472 | if (account != null) | ||
473 | return account.ServiceURLs; | ||
474 | |||
475 | return new Dictionary<string, object>(); | ||
476 | } | ||
477 | |||
478 | public string LocateUser(UUID userID) | ||
479 | { | ||
480 | foreach (TravelingAgentInfo t in m_TravelingAgents.Values) | ||
481 | { | ||
482 | if (t.UserID == userID) | ||
483 | return t.GridExternalName; | ||
484 | } | ||
485 | |||
486 | return string.Empty; | ||
487 | } | ||
488 | |||
489 | public string GetUUI(UUID userID, UUID targetUserID) | ||
490 | { | ||
491 | // Let's see if it's a local user | ||
492 | UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, targetUserID); | ||
493 | if (account != null) | ||
494 | return targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName ; | ||
495 | |||
496 | // Let's try the list of friends | ||
497 | FriendInfo[] friends = m_FriendsService.GetFriends(userID); | ||
498 | if (friends != null && friends.Length > 0) | ||
499 | { | ||
500 | foreach (FriendInfo f in friends) | ||
501 | if (f.Friend.StartsWith(targetUserID.ToString())) | ||
502 | { | ||
503 | // Let's remove the secret | ||
504 | UUID id; string tmp = string.Empty, secret = string.Empty; | ||
505 | if (Util.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret)) | ||
506 | return f.Friend.Replace(secret, "0"); | ||
507 | } | ||
508 | } | ||
509 | |||
510 | return string.Empty; | ||
511 | } | ||
294 | } | 512 | } |
295 | 513 | ||
296 | class TravelingAgentInfo | 514 | class TravelingAgentInfo |