diff options
author | Melanie | 2011-06-09 02:05:04 +0100 |
---|---|---|
committer | Melanie | 2011-06-09 02:05:04 +0100 |
commit | 326c46ba70cea70ddfe4aef9a6b73edff63e126a (patch) | |
tree | 5e76347b0d77f58717d8e5e4f3b8787ff01a18d7 /OpenSim/Services/HypergridService/UserAgentService.cs | |
parent | Make the last otem in a list created with llCSV2List findable (diff) | |
parent | Consistency fix on the last commit. (diff) | |
download | opensim-SC-326c46ba70cea70ddfe4aef9a6b73edff63e126a.zip opensim-SC-326c46ba70cea70ddfe4aef9a6b73edff63e126a.tar.gz opensim-SC-326c46ba70cea70ddfe4aef9a6b73edff63e126a.tar.bz2 opensim-SC-326c46ba70cea70ddfe4aef9a6b73edff63e126a.tar.xz |
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Services/HypergridService/UserAgentService.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/UserAgentService.cs | 252 |
1 files changed, 246 insertions, 6 deletions
diff --git a/OpenSim/Services/HypergridService/UserAgentService.cs b/OpenSim/Services/HypergridService/UserAgentService.cs index 09e785f..41d5a88 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) |
@@ -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 | { |
@@ -168,8 +197,11 @@ namespace OpenSim.Services.HypergridService | |||
168 | agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); | 197 | agentCircuit.firstname, agentCircuit.lastname, region.ServerURI, reason); |
169 | 198 | ||
170 | // restore the old travel info | 199 | // restore the old travel info |
171 | lock (m_TravelingAgents) | 200 | if(reason != "Logins Disabled") |
172 | m_TravelingAgents[agentCircuit.SessionID] = old; | 201 | { |
202 | lock (m_TravelingAgents) | ||
203 | m_TravelingAgents[agentCircuit.SessionID] = old; | ||
204 | } | ||
173 | 205 | ||
174 | return false; | 206 | return false; |
175 | } | 207 | } |
@@ -179,6 +211,7 @@ namespace OpenSim.Services.HypergridService | |||
179 | if (clientIP != null) | 211 | if (clientIP != null) |
180 | m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); | 212 | m_TravelingAgents[agentCircuit.SessionID].ClientIPAddress = clientIP.Address.ToString(); |
181 | m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; | 213 | m_TravelingAgents[agentCircuit.SessionID].MyIpAddress = myExternalIP; |
214 | |||
182 | return true; | 215 | return true; |
183 | } | 216 | } |
184 | 217 | ||
@@ -289,6 +322,213 @@ namespace OpenSim.Services.HypergridService | |||
289 | return false; | 322 | return false; |
290 | } | 323 | } |
291 | 324 | ||
325 | public List<UUID> StatusNotification(List<string> friends, UUID foreignUserID, bool online) | ||
326 | { | ||
327 | if (m_FriendsService == null || m_PresenceService == null) | ||
328 | { | ||
329 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to perform status notifications because friends or presence services are missing"); | ||
330 | return new List<UUID>(); | ||
331 | } | ||
332 | |||
333 | List<UUID> localFriendsOnline = new List<UUID>(); | ||
334 | |||
335 | m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends", foreignUserID, friends.Count); | ||
336 | |||
337 | // First, let's double check that the reported friends are, indeed, friends of that user | ||
338 | // And let's check that the secret matches | ||
339 | List<string> usersToBeNotified = new List<string>(); | ||
340 | foreach (string uui in friends) | ||
341 | { | ||
342 | UUID localUserID; | ||
343 | string secret = string.Empty, tmp = string.Empty; | ||
344 | if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret)) | ||
345 | { | ||
346 | FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID); | ||
347 | foreach (FriendInfo finfo in friendInfos) | ||
348 | { | ||
349 | if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret)) | ||
350 | { | ||
351 | // great! | ||
352 | usersToBeNotified.Add(localUserID.ToString()); | ||
353 | } | ||
354 | } | ||
355 | } | ||
356 | } | ||
357 | |||
358 | // Now, let's send the notifications | ||
359 | m_log.DebugFormat("[USER AGENT SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count); | ||
360 | |||
361 | // First, let's send notifications to local users who are online in the home grid | ||
362 | PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray()); | ||
363 | if (friendSessions != null && friendSessions.Length > 0) | ||
364 | { | ||
365 | PresenceInfo friendSession = null; | ||
366 | foreach (PresenceInfo pinfo in friendSessions) | ||
367 | if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents | ||
368 | { | ||
369 | friendSession = pinfo; | ||
370 | break; | ||
371 | } | ||
372 | |||
373 | if (friendSession != null) | ||
374 | { | ||
375 | ForwardStatusNotificationToSim(friendSession.RegionID, foreignUserID, friendSession.UserID, online); | ||
376 | usersToBeNotified.Remove(friendSession.UserID.ToString()); | ||
377 | UUID id; | ||
378 | if (UUID.TryParse(friendSession.UserID, out id)) | ||
379 | localFriendsOnline.Add(id); | ||
380 | |||
381 | } | ||
382 | } | ||
383 | |||
384 | // Lastly, let's notify the rest who may be online somewhere else | ||
385 | foreach (string user in usersToBeNotified) | ||
386 | { | ||
387 | UUID id = new UUID(user); | ||
388 | if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) | ||
389 | { | ||
390 | string url = m_TravelingAgents[id].GridExternalName; | ||
391 | // forward | ||
392 | m_log.WarnFormat("[USER AGENT SERVICE]: User {0} is visiting {1}. HG Status notifications still not implemented.", user, url); | ||
393 | } | ||
394 | } | ||
395 | |||
396 | // and finally, let's send the online friends | ||
397 | if (online) | ||
398 | { | ||
399 | return localFriendsOnline; | ||
400 | } | ||
401 | else | ||
402 | return new List<UUID>(); | ||
403 | } | ||
404 | |||
405 | protected void ForwardStatusNotificationToSim(UUID regionID, UUID foreignUserID, string user, bool online) | ||
406 | { | ||
407 | UUID userID; | ||
408 | if (UUID.TryParse(user, out userID)) | ||
409 | { | ||
410 | if (m_FriendsLocalSimConnector != null) | ||
411 | { | ||
412 | m_log.DebugFormat("[USER AGENT SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline")); | ||
413 | m_FriendsLocalSimConnector.StatusNotify(foreignUserID, userID, online); | ||
414 | } | ||
415 | else | ||
416 | { | ||
417 | GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID); | ||
418 | if (region != null) | ||
419 | { | ||
420 | m_log.DebugFormat("[USER AGENT SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, foreignUserID, (online ? "online" : "offline")); | ||
421 | m_FriendsSimConnector.StatusNotify(region, foreignUserID, userID, online); | ||
422 | } | ||
423 | } | ||
424 | } | ||
425 | } | ||
426 | |||
427 | public List<UUID> GetOnlineFriends(UUID foreignUserID, List<string> friends) | ||
428 | { | ||
429 | List<UUID> online = new List<UUID>(); | ||
430 | |||
431 | if (m_FriendsService == null || m_PresenceService == null) | ||
432 | { | ||
433 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get online friends because friends or presence services are missing"); | ||
434 | return online; | ||
435 | } | ||
436 | |||
437 | m_log.DebugFormat("[USER AGENT SERVICE]: Foreign user {0} wants to know status of {1} local friends", foreignUserID, friends.Count); | ||
438 | |||
439 | // First, let's double check that the reported friends are, indeed, friends of that user | ||
440 | // And let's check that the secret matches and the rights | ||
441 | List<string> usersToBeNotified = new List<string>(); | ||
442 | foreach (string uui in friends) | ||
443 | { | ||
444 | UUID localUserID; | ||
445 | string secret = string.Empty, tmp = string.Empty; | ||
446 | if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret)) | ||
447 | { | ||
448 | FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID); | ||
449 | foreach (FriendInfo finfo in friendInfos) | ||
450 | { | ||
451 | if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret) && | ||
452 | (finfo.TheirFlags & (int)FriendRights.CanSeeOnline) != 0 && (finfo.TheirFlags != -1)) | ||
453 | { | ||
454 | // great! | ||
455 | usersToBeNotified.Add(localUserID.ToString()); | ||
456 | } | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | |||
461 | // Now, let's find out their status | ||
462 | m_log.DebugFormat("[USER AGENT SERVICE]: GetOnlineFriends: user has {0} local friends with status rights", usersToBeNotified.Count); | ||
463 | |||
464 | // First, let's send notifications to local users who are online in the home grid | ||
465 | PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray()); | ||
466 | if (friendSessions != null && friendSessions.Length > 0) | ||
467 | { | ||
468 | foreach (PresenceInfo pi in friendSessions) | ||
469 | { | ||
470 | UUID presenceID; | ||
471 | if (UUID.TryParse(pi.UserID, out presenceID)) | ||
472 | online.Add(presenceID); | ||
473 | } | ||
474 | } | ||
475 | |||
476 | return online; | ||
477 | } | ||
478 | |||
479 | public Dictionary<string, object> GetServerURLs(UUID userID) | ||
480 | { | ||
481 | if (m_UserAccountService == null) | ||
482 | { | ||
483 | m_log.WarnFormat("[USER AGENT SERVICE]: Unable to get server URLs because user account service is missing"); | ||
484 | return new Dictionary<string, object>(); | ||
485 | } | ||
486 | UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero /*!!!*/, userID); | ||
487 | if (account != null) | ||
488 | return account.ServiceURLs; | ||
489 | |||
490 | return new Dictionary<string, object>(); | ||
491 | } | ||
492 | |||
493 | public string LocateUser(UUID userID) | ||
494 | { | ||
495 | foreach (TravelingAgentInfo t in m_TravelingAgents.Values) | ||
496 | { | ||
497 | if (t == null) | ||
498 | { | ||
499 | m_log.ErrorFormat("[USER AGENT SERVICE]: Oops! Null TravelingAgentInfo. Please report this on mantis"); | ||
500 | continue; | ||
501 | } | ||
502 | if (t.UserID == userID && !m_GridName.Equals(t.GridExternalName)) | ||
503 | return t.GridExternalName; | ||
504 | } | ||
505 | |||
506 | return string.Empty; | ||
507 | } | ||
508 | |||
509 | public string GetUUI(UUID userID, UUID targetUserID) | ||
510 | { | ||
511 | // Let's see if it's a local user | ||
512 | UserAccount account = m_UserAccountService.GetUserAccount(UUID.Zero, targetUserID); | ||
513 | if (account != null) | ||
514 | return targetUserID.ToString() + ";" + m_GridName + ";" + account.FirstName + " " + account.LastName ; | ||
515 | |||
516 | // Let's try the list of friends | ||
517 | FriendInfo[] friends = m_FriendsService.GetFriends(userID); | ||
518 | if (friends != null && friends.Length > 0) | ||
519 | { | ||
520 | foreach (FriendInfo f in friends) | ||
521 | if (f.Friend.StartsWith(targetUserID.ToString())) | ||
522 | { | ||
523 | // Let's remove the secret | ||
524 | UUID id; string tmp = string.Empty, secret = string.Empty; | ||
525 | if (Util.ParseUniversalUserIdentifier(f.Friend, out id, out tmp, out tmp, out tmp, out secret)) | ||
526 | return f.Friend.Replace(secret, "0"); | ||
527 | } | ||
528 | } | ||
529 | |||
530 | return string.Empty; | ||
531 | } | ||
292 | } | 532 | } |
293 | 533 | ||
294 | class TravelingAgentInfo | 534 | class TravelingAgentInfo |