diff options
author | Diva Canto | 2010-02-27 18:16:31 -0800 |
---|---|---|
committer | Diva Canto | 2010-02-27 18:16:31 -0800 |
commit | 1daabc3473aa7696a8ff5d63eb31736ce2158642 (patch) | |
tree | fc7f07d856de79dfdfed03114374f993de400f1a /OpenSim/Region/CoreModules | |
parent | Update the local cache upon friendship acceptance. Logout notifications working. (diff) | |
download | opensim-SC-1daabc3473aa7696a8ff5d63eb31736ce2158642.zip opensim-SC-1daabc3473aa7696a8ff5d63eb31736ce2158642.tar.gz opensim-SC-1daabc3473aa7696a8ff5d63eb31736ce2158642.tar.bz2 opensim-SC-1daabc3473aa7696a8ff5d63eb31736ce2158642.tar.xz |
Status notification (online/offline) working for same sim.
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 84 |
1 files changed, 66 insertions, 18 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index a750c92..7e7d9e9 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -226,7 +226,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
226 | 226 | ||
227 | m_Friends.Add(client.AgentId, newFriends); | 227 | m_Friends.Add(client.AgentId, newFriends); |
228 | 228 | ||
229 | StatusChange(client.AgentId, true); | 229 | //StatusChange(client.AgentId, true); |
230 | } | 230 | } |
231 | 231 | ||
232 | private void OnClientClosed(UUID agentID, Scene scene) | 232 | private void OnClientClosed(UUID agentID, Scene scene) |
@@ -242,9 +242,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
242 | 242 | ||
243 | private void OnLogout(IClientAPI client) | 243 | private void OnLogout(IClientAPI client) |
244 | { | 244 | { |
245 | m_Friends.Remove(client.AgentId); | ||
246 | |||
247 | StatusChange(client.AgentId, false); | 245 | StatusChange(client.AgentId, false); |
246 | m_Friends.Remove(client.AgentId); | ||
248 | } | 247 | } |
249 | 248 | ||
250 | private void OnMakeRootAgent(ScenePresence sp) | 249 | private void OnMakeRootAgent(ScenePresence sp) |
@@ -253,7 +252,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
253 | 252 | ||
254 | if (m_Friends.ContainsKey(agentID)) | 253 | if (m_Friends.ContainsKey(agentID)) |
255 | { | 254 | { |
256 | if (m_Friends[agentID].RegionID == UUID.Zero) | 255 | if (m_Friends[agentID].RegionID == UUID.Zero && m_Friends[agentID].Friends == null) |
257 | { | 256 | { |
258 | m_Friends[agentID].Friends = | 257 | m_Friends[agentID].Friends = |
259 | m_FriendsService.GetFriends(agentID); | 258 | m_FriendsService.GetFriends(agentID); |
@@ -290,9 +289,20 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
290 | return; | 289 | return; |
291 | } | 290 | } |
292 | 291 | ||
292 | List<UUID> online = GetOnlineFriends(agentID); | ||
293 | |||
294 | m_log.DebugFormat("[FRIENDS]: User {0} has {1} friends online", agentID, online.Count); | ||
295 | client.SendAgentOnline(online.ToArray()); | ||
296 | |||
297 | // Now inform the friends that this user is online | ||
298 | StatusChange(agentID, true); | ||
299 | } | ||
300 | |||
301 | List<UUID> GetOnlineFriends(UUID userID) | ||
302 | { | ||
293 | List<string> friendList = new List<string>(); | 303 | List<string> friendList = new List<string>(); |
294 | 304 | ||
295 | foreach (FriendInfo fi in m_Friends[agentID].Friends) | 305 | foreach (FriendInfo fi in m_Friends[userID].Friends) |
296 | { | 306 | { |
297 | if ((fi.TheirFlags & 1) != 0) | 307 | if ((fi.TheirFlags & 1) != 0) |
298 | friendList.Add(fi.Friend); | 308 | friendList.Add(fi.Friend); |
@@ -308,7 +318,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
308 | online.Add(new UUID(pi.UserID)); | 318 | online.Add(new UUID(pi.UserID)); |
309 | } | 319 | } |
310 | 320 | ||
311 | client.SendAgentOnline(online.ToArray()); | 321 | return online; |
312 | } | 322 | } |
313 | 323 | ||
314 | // | 324 | // |
@@ -347,25 +357,58 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
347 | return null; | 357 | return null; |
348 | } | 358 | } |
349 | 359 | ||
360 | /// <summary> | ||
361 | /// Caller beware! Call this only for root agents. | ||
362 | /// </summary> | ||
363 | /// <param name="agentID"></param> | ||
364 | /// <param name="online"></param> | ||
350 | private void StatusChange(UUID agentID, bool online) | 365 | private void StatusChange(UUID agentID, bool online) |
351 | { | 366 | { |
352 | foreach (UserFriendData fd in m_Friends.Values) | 367 | if (m_Friends.ContainsKey(agentID)) |
353 | { | 368 | { |
354 | // Is this a root agent? If not, they will get updates | 369 | List<FriendInfo> friendList = new List<FriendInfo>(); |
355 | // through the root and this next check is redundant | 370 | foreach (FriendInfo fi in m_Friends[agentID].Friends) |
356 | // | 371 | { |
357 | if (fd.RegionID == UUID.Zero) | 372 | if ((fi.MyFlags & 1) != 0) |
358 | continue; | 373 | friendList.Add(fi); |
374 | } | ||
375 | foreach (FriendInfo fi in friendList) | ||
376 | { | ||
377 | // Notify about this user status | ||
378 | StatusNotify(fi, agentID, online); | ||
379 | } | ||
380 | } | ||
381 | } | ||
359 | 382 | ||
360 | if (fd.IsFriend(agentID.ToString())) | 383 | private void StatusNotify(FriendInfo friend, UUID userID, bool online) |
384 | { | ||
385 | UUID friendID = UUID.Zero; | ||
386 | |||
387 | if (UUID.TryParse(friend.Friend, out friendID)) | ||
388 | { | ||
389 | IClientAPI friendClient = LocateClientObject(friendID); | ||
390 | if (friendClient != null) | ||
361 | { | 391 | { |
362 | UUID[] changed = new UUID[] { agentID }; | 392 | //m_log.DebugFormat("[FRIENDS]: Notify {0} that user {1} is {2}", friend.Friend, userID, online); |
363 | IClientAPI client = LocateClientObject(fd.PrincipalID); | 393 | // the friend in this sim as root agent |
364 | if (online) | 394 | if (online) |
365 | client.SendAgentOnline(changed); | 395 | friendClient.SendAgentOnline(new UUID[] { userID }); |
366 | else | 396 | else |
367 | client.SendAgentOffline(changed); | 397 | friendClient.SendAgentOffline(new UUID[] { userID }); |
398 | // we're done | ||
399 | return; | ||
368 | } | 400 | } |
401 | |||
402 | // The friend is not here [as root]. Let's forward. | ||
403 | PresenceInfo[] friendSessions = PresenceService.GetAgents(new string[] { friendID.ToString() }); | ||
404 | PresenceInfo friendSession = PresenceInfo.GetOnlinePresence(friendSessions); | ||
405 | if (friendSession != null) | ||
406 | { | ||
407 | GridRegion region = GridService.GetRegionByUUID(m_Scenes[0].RegionInfo.ScopeID, friendSession.RegionID); | ||
408 | m_FriendsSimConnector.StatusNotify(region, userID, friendID, online); | ||
409 | } | ||
410 | |||
411 | // Friend is not online. Ignore. | ||
369 | } | 412 | } |
370 | } | 413 | } |
371 | 414 | ||
@@ -490,6 +533,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
490 | FriendsService.Delete(agentID, exfriendID.ToString()); | 533 | FriendsService.Delete(agentID, exfriendID.ToString()); |
491 | FriendsService.Delete(exfriendID, agentID.ToString()); | 534 | FriendsService.Delete(exfriendID, agentID.ToString()); |
492 | 535 | ||
536 | // Update local cache | ||
537 | m_Friends[agentID].Friends = FriendsService.GetFriends(agentID); | ||
538 | |||
493 | client.SendTerminateFriend(exfriendID); | 539 | client.SendTerminateFriend(exfriendID); |
494 | 540 | ||
495 | // | 541 | // |
@@ -499,8 +545,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
499 | IClientAPI friendClient = LocateClientObject(exfriendID); | 545 | IClientAPI friendClient = LocateClientObject(exfriendID); |
500 | if (friendClient != null) | 546 | if (friendClient != null) |
501 | { | 547 | { |
502 | // the prospective friend in this sim as root agent | 548 | // the friend in this sim as root agent |
503 | friendClient.SendTerminateFriend(exfriendID); | 549 | friendClient.SendTerminateFriend(exfriendID); |
550 | // update local cache | ||
551 | m_Friends[exfriendID].Friends = FriendsService.GetFriends(exfriendID); | ||
504 | // we're done | 552 | // we're done |
505 | return; | 553 | return; |
506 | } | 554 | } |