aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services')
-rw-r--r--OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs91
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs172
-rw-r--r--OpenSim/Services/Interfaces/IGatekeeperService.cs3
-rw-r--r--OpenSim/Services/Interfaces/ISimulatorSocialService.cs40
4 files changed, 303 insertions, 3 deletions
diff --git a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
index c40a347..46d30df 100644
--- a/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
+++ b/OpenSim/Services/Connectors/Hypergrid/UserAgentServiceConnector.cs
@@ -404,6 +404,97 @@ namespace OpenSim.Services.Connectors.Hypergrid
404 GetBoolResponse(request, out reason); 404 GetBoolResponse(request, out reason);
405 } 405 }
406 406
407 public void StatusNotification(List<string> friends, UUID userID, bool online)
408 {
409 Hashtable hash = new Hashtable();
410 hash["userID"] = userID.ToString();
411 hash["online"] = online.ToString();
412 int i = 0;
413 foreach (string s in friends)
414 {
415 hash["friend_" + i.ToString()] = s;
416 i++;
417 }
418
419 IList paramList = new ArrayList();
420 paramList.Add(hash);
421
422 XmlRpcRequest request = new XmlRpcRequest("status_notification", paramList);
423 string reason = string.Empty;
424 GetBoolResponse(request, out reason);
425
426 }
427
428 public List<UUID> GetOnlineFriends(UUID userID, List<string> friends)
429 {
430 Hashtable hash = new Hashtable();
431 hash["userID"] = userID.ToString();
432 int i = 0;
433 foreach (string s in friends)
434 {
435 hash["friend_" + i.ToString()] = s;
436 i++;
437 }
438
439 IList paramList = new ArrayList();
440 paramList.Add(hash);
441
442 XmlRpcRequest request = new XmlRpcRequest("get_online_friends", paramList);
443 string reason = string.Empty;
444
445 // Send and get reply
446 List<UUID> online = new List<UUID>();
447 XmlRpcResponse response = null;
448 try
449 {
450 response = request.Send(m_ServerURL, 10000);
451 }
452 catch (Exception e)
453 {
454 m_log.DebugFormat("[USER AGENT CONNECTOR]: Unable to contact remote server {0}", m_ServerURL);
455 reason = "Exception: " + e.Message;
456 return online;
457 }
458
459 if (response.IsFault)
460 {
461 m_log.ErrorFormat("[USER AGENT CONNECTOR]: remote call to {0} returned an error: {1}", m_ServerURL, response.FaultString);
462 reason = "XMLRPC Fault";
463 return online;
464 }
465
466 hash = (Hashtable)response.Value;
467 //foreach (Object o in hash)
468 // m_log.Debug(">> " + ((DictionaryEntry)o).Key + ":" + ((DictionaryEntry)o).Value);
469 try
470 {
471 if (hash == null)
472 {
473 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got null response from {0}! THIS IS BAAAAD", m_ServerURL);
474 reason = "Internal error 1";
475 return online;
476 }
477
478 // Here is the actual response
479 foreach (object key in hash.Keys)
480 {
481 if (key is string && ((string)key).StartsWith("friend_") && hash[key] != null)
482 {
483 UUID uuid;
484 if (UUID.TryParse(hash[key].ToString(), out uuid))
485 online.Add(uuid);
486 }
487 }
488
489 }
490 catch (Exception e)
491 {
492 m_log.ErrorFormat("[USER AGENT CONNECTOR]: Got exception on GetOnlineFriends response.");
493 reason = "Exception: " + e.Message;
494 }
495
496 return online;
497 }
407 498
408 private bool GetBoolResponse(XmlRpcRequest request, out string reason) 499 private bool GetBoolResponse(XmlRpcRequest request, out string reason)
409 { 500 {
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
diff --git a/OpenSim/Services/Interfaces/IGatekeeperService.cs b/OpenSim/Services/Interfaces/IGatekeeperService.cs
index aac8293..fa1ab1c 100644
--- a/OpenSim/Services/Interfaces/IGatekeeperService.cs
+++ b/OpenSim/Services/Interfaces/IGatekeeperService.cs
@@ -55,6 +55,9 @@ namespace OpenSim.Services.Interfaces
55 void LogoutAgent(UUID userID, UUID sessionID); 55 void LogoutAgent(UUID userID, UUID sessionID);
56 GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt); 56 GridRegion GetHomeRegion(UUID userID, out Vector3 position, out Vector3 lookAt);
57 57
58 void StatusNotification(List<string> friends, UUID userID, bool online);
59 List<UUID> GetOnlineFriends(UUID userID, List<string> friends);
60
58 bool AgentIsComingHome(UUID sessionID, string thisGridExternalName); 61 bool AgentIsComingHome(UUID sessionID, string thisGridExternalName);
59 bool VerifyAgent(UUID sessionID, string token); 62 bool VerifyAgent(UUID sessionID, string token);
60 bool VerifyClient(UUID sessionID, string reportedIP); 63 bool VerifyClient(UUID sessionID, string reportedIP);
diff --git a/OpenSim/Services/Interfaces/ISimulatorSocialService.cs b/OpenSim/Services/Interfaces/ISimulatorSocialService.cs
new file mode 100644
index 0000000..0b7aefc
--- /dev/null
+++ b/OpenSim/Services/Interfaces/ISimulatorSocialService.cs
@@ -0,0 +1,40 @@
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 OpenSim.Framework;
30using OpenMetaverse;
31
32using GridRegion = OpenSim.Services.Interfaces.GridRegion;
33
34namespace OpenSim.Services.Interfaces
35{
36 public interface IFriendsSimConnector
37 {
38 bool StatusNotify(UUID userID, UUID friendID, bool online);
39 }
40}