diff options
author | Diva Canto | 2012-03-21 10:35:06 -0700 |
---|---|---|
committer | Diva Canto | 2012-03-21 10:35:06 -0700 |
commit | 4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee (patch) | |
tree | 6db550ead95b0a8f044f504f33fc2bfc202b1f80 /OpenSim/Services/HypergridService/HGFriendsService.cs | |
parent | HG Friends: pulled sim-bound notification code to HGStatusNotifier, so that w... (diff) | |
download | opensim-SC-4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee.zip opensim-SC-4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee.tar.gz opensim-SC-4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee.tar.bz2 opensim-SC-4a9ca3ca8ff18f4fcf05c3983db5e6b1d49c97ee.tar.xz |
HG Friends: reroute the status notifications to the HGFriends service, so that they can scale better. They were previously being handled by the UAS; that is still there, but it's now obsolete and will be removed in a future release.
Diffstat (limited to 'OpenSim/Services/HypergridService/HGFriendsService.cs')
-rw-r--r-- | OpenSim/Services/HypergridService/HGFriendsService.cs | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/OpenSim/Services/HypergridService/HGFriendsService.cs b/OpenSim/Services/HypergridService/HGFriendsService.cs index 19ee3e2..39524ab 100644 --- a/OpenSim/Services/HypergridService/HGFriendsService.cs +++ b/OpenSim/Services/HypergridService/HGFriendsService.cs | |||
@@ -214,6 +214,91 @@ namespace OpenSim.Services.HypergridService | |||
214 | return false; | 214 | return false; |
215 | } | 215 | } |
216 | 216 | ||
217 | public List<UUID> StatusNotification(List<string> friends, UUID foreignUserID, bool online) | ||
218 | { | ||
219 | if (m_FriendsService == null || m_PresenceService == null) | ||
220 | { | ||
221 | m_log.WarnFormat("[HGFRIENDS SERVICE]: Unable to perform status notifications because friends or presence services are missing"); | ||
222 | return new List<UUID>(); | ||
223 | } | ||
224 | |||
225 | // Let's unblock the caller right now, and take it from here async | ||
226 | |||
227 | List<UUID> localFriendsOnline = new List<UUID>(); | ||
228 | |||
229 | m_log.DebugFormat("[HGFRIENDS SERVICE]: Status notification: foreign user {0} wants to notify {1} local friends of {2} status", | ||
230 | foreignUserID, friends.Count, (online ? "online" : "offline")); | ||
231 | |||
232 | // First, let's double check that the reported friends are, indeed, friends of that user | ||
233 | // And let's check that the secret matches | ||
234 | List<string> usersToBeNotified = new List<string>(); | ||
235 | foreach (string uui in friends) | ||
236 | { | ||
237 | UUID localUserID; | ||
238 | string secret = string.Empty, tmp = string.Empty; | ||
239 | if (Util.ParseUniversalUserIdentifier(uui, out localUserID, out tmp, out tmp, out tmp, out secret)) | ||
240 | { | ||
241 | FriendInfo[] friendInfos = m_FriendsService.GetFriends(localUserID); | ||
242 | foreach (FriendInfo finfo in friendInfos) | ||
243 | { | ||
244 | if (finfo.Friend.StartsWith(foreignUserID.ToString()) && finfo.Friend.EndsWith(secret)) | ||
245 | { | ||
246 | // great! | ||
247 | usersToBeNotified.Add(localUserID.ToString()); | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | // Now, let's send the notifications | ||
254 | //m_log.DebugFormat("[HGFRIENDS SERVICE]: Status notification: user has {0} local friends", usersToBeNotified.Count); | ||
255 | |||
256 | // First, let's send notifications to local users who are online in the home grid | ||
257 | PresenceInfo[] friendSessions = m_PresenceService.GetAgents(usersToBeNotified.ToArray()); | ||
258 | if (friendSessions != null && friendSessions.Length > 0) | ||
259 | { | ||
260 | PresenceInfo friendSession = null; | ||
261 | foreach (PresenceInfo pinfo in friendSessions) | ||
262 | if (pinfo.RegionID != UUID.Zero) // let's guard against traveling agents | ||
263 | { | ||
264 | friendSession = pinfo; | ||
265 | break; | ||
266 | } | ||
267 | |||
268 | if (friendSession != null) | ||
269 | { | ||
270 | ForwardStatusNotificationToSim(friendSession.RegionID, foreignUserID, friendSession.UserID, online); | ||
271 | usersToBeNotified.Remove(friendSession.UserID.ToString()); | ||
272 | UUID id; | ||
273 | if (UUID.TryParse(friendSession.UserID, out id)) | ||
274 | localFriendsOnline.Add(id); | ||
275 | |||
276 | } | ||
277 | } | ||
278 | |||
279 | // Lastly, let's notify the rest who may be online somewhere else | ||
280 | foreach (string user in usersToBeNotified) | ||
281 | { | ||
282 | UUID id = new UUID(user); | ||
283 | //m_UserAgentService.LocateUser(id); | ||
284 | //etc... | ||
285 | //if (m_TravelingAgents.ContainsKey(id) && m_TravelingAgents[id].GridExternalName != m_GridName) | ||
286 | //{ | ||
287 | // string url = m_TravelingAgents[id].GridExternalName; | ||
288 | // // forward | ||
289 | //} | ||
290 | //m_log.WarnFormat("[HGFRIENDS SERVICE]: User {0} is visiting another grid. HG Status notifications still not implemented.", user); | ||
291 | } | ||
292 | |||
293 | // and finally, let's send the online friends | ||
294 | if (online) | ||
295 | { | ||
296 | return localFriendsOnline; | ||
297 | } | ||
298 | else | ||
299 | return new List<UUID>(); | ||
300 | } | ||
301 | |||
217 | #endregion IHGFriendsService | 302 | #endregion IHGFriendsService |
218 | 303 | ||
219 | #region Aux | 304 | #region Aux |
@@ -296,6 +381,28 @@ namespace OpenSim.Services.HypergridService | |||
296 | return false; | 381 | return false; |
297 | } | 382 | } |
298 | 383 | ||
384 | protected void ForwardStatusNotificationToSim(UUID regionID, UUID foreignUserID, string user, bool online) | ||
385 | { | ||
386 | UUID userID; | ||
387 | if (UUID.TryParse(user, out userID)) | ||
388 | { | ||
389 | if (m_FriendsLocalSimConnector != null) | ||
390 | { | ||
391 | m_log.DebugFormat("[HGFRIENDS SERVICE]: Local Notify, user {0} is {1}", foreignUserID, (online ? "online" : "offline")); | ||
392 | m_FriendsLocalSimConnector.StatusNotify(foreignUserID, userID, online); | ||
393 | } | ||
394 | else | ||
395 | { | ||
396 | GridRegion region = m_GridService.GetRegionByUUID(UUID.Zero /* !!! */, regionID); | ||
397 | if (region != null) | ||
398 | { | ||
399 | m_log.DebugFormat("[HGFRIENDS SERVICE]: Remote Notify to region {0}, user {1} is {2}", region.RegionName, foreignUserID, (online ? "online" : "offline")); | ||
400 | m_FriendsSimConnector.StatusNotify(region, foreignUserID, userID, online); | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | |||
299 | #endregion Aux | 406 | #endregion Aux |
300 | } | 407 | } |
301 | } | 408 | } |