diff --git a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs index 906101be7f..5873eb8cb9 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1UserServices.cs @@ -516,7 +516,7 @@ namespace OpenSim.Region.Communications.OGS1 IList parameters = new ArrayList(); parameters.Add(param); XmlRpcRequest req = new XmlRpcRequest("get_user_friend_list", parameters); - XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 3000); + XmlRpcResponse resp = req.Send(m_parent.NetworkServersInfo.UserURL, 8000); Hashtable respData = (Hashtable) resp.Value; if (respData.Contains("avcount")) diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/FriendsModule.cs index 7560c900e2..fc14df7243 100644 --- a/OpenSim/Region/Environment/Modules/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/FriendsModule.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; using libsecondlife; +using libsecondlife.Packets; using Nini.Config; using Nwc.XmlRpc; using OpenSim.Framework; @@ -45,6 +46,8 @@ namespace OpenSim.Region.Environment.Modules Dictionary m_pendingFriendRequests = new Dictionary(); + Dictionary> FriendLists = new Dictionary>(); + public void Initialise(Scene scene, IConfigSource config) { lock (m_scene) @@ -78,11 +81,92 @@ namespace OpenSim.Region.Environment.Modules // Generated by LoginService. The friends are retreived from the database by the UserManager // Subscribe to instant messages + client.OnInstantMessage += OnInstantMessage; client.OnApproveFriendRequest += OnApprovedFriendRequest; client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; + + List fl = new List(); + lock (FriendLists) + { + if (FriendLists.ContainsKey(client.AgentId)) + { + fl = FriendLists[client.AgentId]; + } + else + { + fl = m_scene[0].GetFriendList(client.AgentId); + lock (FriendLists) + { + if (!FriendLists.ContainsKey(client.AgentId)) + FriendLists.Add(client.AgentId, fl); + } + } + } + List UpdateUsers = new List(); + + foreach (FriendListItem f in fl) + { + if (m_rootAgents.ContainsKey(f.Friend)) + { + if (f.onlinestatus == false) + { + UpdateUsers.Add(f.Friend); + f.onlinestatus = true; + } + } + } + foreach (LLUUID user in UpdateUsers) + { + ScenePresence av = GetPresenceFromAgentID(user); + if (av != null) + { + List usrfl = new List(); + + lock (FriendLists) + { + usrfl = FriendLists[user]; + } + + lock (usrfl) + { + foreach (FriendListItem fli in usrfl) + { + if (fli.Friend == client.AgentId) + { + fli.onlinestatus = true; + OnlineNotificationPacket onp = new OnlineNotificationPacket(); + OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[1]; + OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); + onpbl.AgentID = client.AgentId; + onpb[0] = onpbl; + onp.AgentBlock = onpb; + av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); + } + } + } + } + } + + if (UpdateUsers.Count > 0) + { + OnlineNotificationPacket onp = new OnlineNotificationPacket(); + OnlineNotificationPacket.AgentBlockBlock[] onpb = new OnlineNotificationPacket.AgentBlockBlock[UpdateUsers.Count]; + for (int i = 0; i < UpdateUsers.Count; i++) + { + OnlineNotificationPacket.AgentBlockBlock onpbl = new OnlineNotificationPacket.AgentBlockBlock(); + onpbl.AgentID = UpdateUsers[i]; + onpb[i] = onpbl; + } + onp.AgentBlock = onpb; + client.OutPacket(onp, ThrottleOutPacketType.Task); + } + + + + } private void ClientLoggedOut(LLUUID AgentId) @@ -95,6 +179,60 @@ namespace OpenSim.Region.Environment.Modules m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); } } + List lfli = new List(); + lock (FriendLists) + { + if (FriendLists.ContainsKey(AgentId)) + { + lfli = FriendLists[AgentId]; + } + } + List updateUsers = new List(); + foreach (FriendListItem fli in lfli) + { + if (fli.onlinestatus = true) + { + updateUsers.Add(fli.Friend); + } + } + for (int i = 0; i < updateUsers.Count; i++) + { + List flfli = new List(); + lock (FriendLists) + { + if (FriendLists.ContainsKey(updateUsers[i])) + flfli = FriendLists[updateUsers[i]]; + } + for (int j = 0; j < flfli.Count; j++) + { + if (flfli[i].Friend == AgentId) + { + flfli[i].onlinestatus = false; + } + + } + + } + for (int i = 0; i < updateUsers.Count; i++) + { + ScenePresence av = GetPresenceFromAgentID(updateUsers[i]); + if (av != null) + { + + OfflineNotificationPacket onp = new OfflineNotificationPacket(); + OfflineNotificationPacket.AgentBlockBlock[] onpb = new OfflineNotificationPacket.AgentBlockBlock[1]; + OfflineNotificationPacket.AgentBlockBlock onpbl = new OfflineNotificationPacket.AgentBlockBlock(); + onpbl.AgentID = AgentId; + onpb[0] = onpbl; + onp.AgentBlock = onpb; + av.ControllingClient.OutPacket(onp, ThrottleOutPacketType.Task); + } + } + lock (FriendLists) + { + FriendLists.Remove(AgentId); + } + } private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) diff --git a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs index 6f7235e865..6e13b735f1 100644 --- a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs +++ b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs @@ -82,6 +82,7 @@ namespace OpenSim.Region.Environment.Modules // Don't send a Friend Dialog IM with a LLUUID.Zero session. if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero)) { + // Try root avatar only first foreach (Scene scene in m_scenes) { if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) @@ -98,8 +99,27 @@ namespace OpenSim.Region.Environment.Modules } } } + + // try child avatar second + foreach (Scene scene in m_scenes) + { + if (scene.Entities.ContainsKey(toAgentID) && scene.Entities[toAgentID] is ScenePresence) + { + // Local message + ScenePresence user = (ScenePresence)scene.Entities[toAgentID]; + + user.ControllingClient.SendInstantMessage(fromAgentID, fromAgentSession, message, + toAgentID, imSessionID, fromAgentName, dialog, + timestamp); + // Message sent + return; + + } + } + } + // Still here, try send via Grid // TODO } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 6816ad6e2a..20cdb46302 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -2145,8 +2145,15 @@ namespace OpenSim.Region.Environment.Scenes m_statsReporter.SetObjectCapacity(objects); } objectCapacity = objects; + } + public List GetFriendList(LLUUID avatarID) + { + return CommsManager.GetUserFriendList(avatarID); + } + + #endregion #region Other Methods