aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/HypergridService
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/HypergridService')
-rw-r--r--OpenSim/Services/HypergridService/HGInstantMessageService.cs317
-rw-r--r--OpenSim/Services/HypergridService/UserAgentService.cs224
2 files changed, 538 insertions, 3 deletions
diff --git a/OpenSim/Services/HypergridService/HGInstantMessageService.cs b/OpenSim/Services/HypergridService/HGInstantMessageService.cs
new file mode 100644
index 0000000..ca0fd7f
--- /dev/null
+++ b/OpenSim/Services/HypergridService/HGInstantMessageService.cs
@@ -0,0 +1,317 @@
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 System.Collections.Generic;
30using System.Net;
31using System.Reflection;
32
33using OpenSim.Framework;
34using OpenSim.Services.Connectors.Friends;
35using OpenSim.Services.Connectors.Hypergrid;
36using OpenSim.Services.Interfaces;
37using OpenSim.Services.Connectors.InstantMessage;
38using GridRegion = OpenSim.Services.Interfaces.GridRegion;
39using OpenSim.Server.Base;
40using FriendInfo = OpenSim.Services.Interfaces.FriendInfo;
41
42using OpenMetaverse;
43using log4net;
44using Nini.Config;
45
46namespace OpenSim.Services.HypergridService
47{
48 /// <summary>
49 /// Inter-grid IM
50 /// </summary>
51 public class HGInstantMessageService : IInstantMessage
52 {
53 private static readonly ILog m_log =
54 LogManager.GetLogger(
55 MethodBase.GetCurrentMethod().DeclaringType);
56
57 private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours
58
59 static bool m_Initialized = false;
60
61 protected static IGridService m_GridService;
62 protected static IPresenceService m_PresenceService;
63 protected static IUserAgentService m_UserAgentService;
64
65 protected static IInstantMessageSimConnector m_IMSimConnector;
66
67 protected static Dictionary<UUID, object> m_UserLocationMap = new Dictionary<UUID, object>();
68 private static ExpiringCache<UUID, GridRegion> m_RegionCache;
69
70 public HGInstantMessageService(IConfigSource config)
71 : this(config, null)
72 {
73 }
74
75 public HGInstantMessageService(IConfigSource config, IInstantMessageSimConnector imConnector)
76 {
77 if (imConnector != null)
78 m_IMSimConnector = imConnector;
79
80 if (!m_Initialized)
81 {
82 m_Initialized = true;
83
84 m_log.DebugFormat("[HG IM SERVICE]: Starting...");
85
86 IConfig serverConfig = config.Configs["HGInstantMessageService"];
87 if (serverConfig == null)
88 throw new Exception(String.Format("No section HGInstantMessageService in config file"));
89
90 string gridService = serverConfig.GetString("GridService", String.Empty);
91 string presenceService = serverConfig.GetString("PresenceService", String.Empty);
92 string userAgentService = serverConfig.GetString("UserAgentService", String.Empty);
93
94 if (gridService == string.Empty || presenceService == string.Empty)
95 throw new Exception(String.Format("Incomplete specifications, InstantMessage Service cannot function."));
96
97 Object[] args = new Object[] { config };
98 m_GridService = ServerUtils.LoadPlugin<IGridService>(gridService, args);
99 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(presenceService, args);
100 m_UserAgentService = ServerUtils.LoadPlugin<IUserAgentService>(userAgentService, args);
101
102 m_RegionCache = new ExpiringCache<UUID, GridRegion>();
103
104 }
105 }
106
107 public bool IncomingInstantMessage(GridInstantMessage im)
108 {
109 m_log.DebugFormat("[HG IM SERVICE]: Received message {0} from {1} to {2}", im.message, im.fromAgentID, im.toAgentID);
110 UUID toAgentID = new UUID(im.toAgentID);
111
112 if (m_IMSimConnector != null)
113 {
114 m_log.DebugFormat("[XXX] SendIMToRegion local im connector");
115 return m_IMSimConnector.SendInstantMessage(im);
116 }
117 else
118 return TrySendInstantMessage(im, "", true);
119 }
120
121 public bool OutgoingInstantMessage(GridInstantMessage im, string url)
122 {
123 m_log.DebugFormat("[HG IM SERVICE]: Sending message {0} from {1} to {2}@{3}", im.message, im.fromAgentID, im.toAgentID, url);
124 if (url != string.Empty)
125 return TrySendInstantMessage(im, url, true);
126 else
127 {
128 PresenceInfo upd = new PresenceInfo();
129 upd.RegionID = UUID.Zero;
130 return TrySendInstantMessage(im, upd, true);
131 }
132 }
133
134 protected bool TrySendInstantMessage(GridInstantMessage im, object previousLocation, bool firstTime)
135 {
136 UUID toAgentID = new UUID(im.toAgentID);
137
138 PresenceInfo upd = null;
139 string url = string.Empty;
140
141 bool lookupAgent = false;
142
143 lock (m_UserLocationMap)
144 {
145 if (m_UserLocationMap.ContainsKey(toAgentID))
146 {
147 object o = m_UserLocationMap[toAgentID];
148 if (o is PresenceInfo)
149 upd = (PresenceInfo)o;
150 else if (o is string)
151 url = (string)o;
152
153 // We need to compare the current location with the previous
154 // or the recursive loop will never end because it will never try to lookup the agent again
155 if (!firstTime)
156 {
157 lookupAgent = true;
158 upd = null;
159 url = string.Empty;
160 }
161 }
162 else
163 {
164 lookupAgent = true;
165 }
166 }
167
168 m_log.DebugFormat("[XXX] Neeed lookup ? {0}", (lookupAgent ? "yes" : "no"));
169
170 // Are we needing to look-up an agent?
171 if (lookupAgent)
172 {
173 // Non-cached user agent lookup.
174 PresenceInfo[] presences = m_PresenceService.GetAgents(new string[] { toAgentID.ToString() });
175 if (presences != null && presences.Length > 0)
176 {
177 foreach (PresenceInfo p in presences)
178 {
179 if (p.RegionID != UUID.Zero)
180 {
181 m_log.DebugFormat("[XXX]: Found presence in {0}", p.RegionID);
182 upd = p;
183 break;
184 }
185 }
186 }
187
188 if (upd == null)
189 {
190 // Let's check with the UAS if the user is elsewhere
191 m_log.DebugFormat("[HG IM SERVICE]: User is not present. Checking location with User Agent service");
192 url = m_UserAgentService.LocateUser(toAgentID);
193 }
194
195 if (upd != null || url != string.Empty)
196 {
197 // check if we've tried this before..
198 // This is one way to end the recursive loop
199 //
200 if (!firstTime && ((previousLocation is PresenceInfo && upd != null && upd.RegionID == ((PresenceInfo)previousLocation).RegionID) ||
201 (previousLocation is string && upd == null && previousLocation.Equals(url))))
202 {
203 // m_log.Error("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
204 m_log.DebugFormat("[HG IM SERVICE]: Fail 2 {0} {1}", previousLocation, url);
205
206 return false;
207 }
208 }
209 }
210
211 if (upd != null)
212 {
213 // ok, the user is around somewhere. Let's send back the reply with "success"
214 // even though the IM may still fail. Just don't keep the caller waiting for
215 // the entire time we're trying to deliver the IM
216 return SendIMToRegion(upd, im, toAgentID);
217 }
218 else if (url != string.Empty)
219 {
220 // ok, the user is around somewhere. Let's send back the reply with "success"
221 // even though the IM may still fail. Just don't keep the caller waiting for
222 // the entire time we're trying to deliver the IM
223 return ForwardIMToGrid(url, im, toAgentID);
224 }
225 else if (firstTime && previousLocation is string && (string)previousLocation != string.Empty)
226 {
227 return ForwardIMToGrid((string)previousLocation, im, toAgentID);
228 }
229 else
230 m_log.DebugFormat("[HG IM SERVICE]: Unable to locate user {0}", toAgentID);
231 return false;
232 }
233
234 bool SendIMToRegion(PresenceInfo upd, GridInstantMessage im, UUID toAgentID)
235 {
236 bool imresult = false;
237 GridRegion reginfo = null;
238 if (!m_RegionCache.TryGetValue(upd.RegionID, out reginfo))
239 {
240 reginfo = m_GridService.GetRegionByUUID(UUID.Zero /*!!!*/, upd.RegionID);
241 if (reginfo != null)
242 m_RegionCache.AddOrUpdate(upd.RegionID, reginfo, CACHE_EXPIRATION_SECONDS);
243 }
244
245 if (reginfo != null)
246 {
247 imresult = InstantMessageServiceConnector.SendInstantMessage(reginfo.ServerURI, im);
248 }
249 else
250 {
251 m_log.DebugFormat("[HG IM SERVICE]: Failed to deliver message to {0}", reginfo.ServerURI);
252 return false;
253 }
254
255 if (imresult)
256 {
257 // IM delivery successful, so store the Agent's location in our local cache.
258 lock (m_UserLocationMap)
259 {
260 if (m_UserLocationMap.ContainsKey(toAgentID))
261 {
262 m_UserLocationMap[toAgentID] = upd;
263 }
264 else
265 {
266 m_UserLocationMap.Add(toAgentID, upd);
267 }
268 }
269 return true;
270 }
271 else
272 {
273 // try again, but lookup user this time.
274 // Warning, this must call the Async version
275 // of this method or we'll be making thousands of threads
276 // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
277 // The version that spawns the thread is SendGridInstantMessageViaXMLRPC
278
279 // This is recursive!!!!!
280 return TrySendInstantMessage(im, upd, false);
281 }
282 }
283
284 bool ForwardIMToGrid(string url, GridInstantMessage im, UUID toAgentID)
285 {
286 if (InstantMessageServiceConnector.SendInstantMessage(url, im))
287 {
288 // IM delivery successful, so store the Agent's location in our local cache.
289 lock (m_UserLocationMap)
290 {
291 if (m_UserLocationMap.ContainsKey(toAgentID))
292 {
293 m_UserLocationMap[toAgentID] = url;
294 }
295 else
296 {
297 m_UserLocationMap.Add(toAgentID, url);
298 }
299 }
300
301 return true;
302 }
303 else
304 {
305 // try again, but lookup user this time.
306 // Warning, this must call the Async version
307 // of this method or we'll be making thousands of threads
308 // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
309 // The version that spawns the thread is SendGridInstantMessageViaXMLRPC
310
311 // This is recursive!!!!!
312 return TrySendInstantMessage(im, url, false);
313 }
314
315 }
316 }
317}
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;
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)
@@ -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