From 3991908db5b50e764112d30e5750447db67795b5 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Mon, 2 Jun 2008 16:16:07 +0000 Subject: * This update enables grid wide presence updates. * You'll need to start-up the MessageingServer and set it up. It sets up like any of the other grid servers. * All user presence data is kept in memory for speed, while the agent is online. That means if you shutdown the messaging server or the messaging server crashes, it forgets who's online/offline. * Occasionally the region-cache will get stale if regions move around a lot. if it gets stale, run clear-cache on the messaging server console to clear the region cache. --- .../Modules/Avatar/Friends/FriendsModule.cs | 132 +++++++++++++++++++-- 1 file changed, 122 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/Avatar/Friends') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index c82f88d..92c808b 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; +using System.Collections; using System.Collections.Generic; using System.Reflection; using libsecondlife; @@ -45,6 +46,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends private Dictionary> FriendLists = new Dictionary>(); private Dictionary m_pendingFriendRequests = new Dictionary(); private Dictionary m_rootAgents = new Dictionary(); + private Dictionary> StoredFriendListUpdates = new Dictionary>(); + private List m_scene = new List(); #region IRegionModule Members @@ -91,6 +94,73 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) { m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); + Hashtable requestData = (Hashtable)req.Params[0]; + if (requestData.ContainsKey("agent_id") && requestData.ContainsKey("notify_id") && requestData.ContainsKey("status")) + { + LLUUID notifyAgentId = LLUUID.Zero; + LLUUID notifyAboutAgentId = LLUUID.Zero; + bool notifyOnlineStatus = false; + + if ((string)requestData["status"] == "TRUE") + notifyOnlineStatus = true; + + Helpers.TryParse((string)requestData["notify_id"], out notifyAgentId); + + Helpers.TryParse((string)requestData["agent_id"], out notifyAboutAgentId); + + ScenePresence avatar = GetPresenceFromAgentID(notifyAgentId); + if (avatar != null) + { + if (avatar.IsChildAgent) + { + StoredFriendListUpdate sob = new StoredFriendListUpdate(); + sob.OnlineYN = notifyOnlineStatus; + sob.storedAbout = notifyAboutAgentId; + sob.storedFor = notifyAgentId; + lock (StoredFriendListUpdates) + { + if (StoredFriendListUpdates.ContainsKey(notifyAgentId)) + { + StoredFriendListUpdates[notifyAgentId].Add(sob); + } + else + { + List newitem = new List(); + newitem.Add(sob); + StoredFriendListUpdates.Add(notifyAgentId, newitem); + } + } + } + else + { + if (notifyOnlineStatus) + doFriendListUpdateOnline(notifyAboutAgentId); + else + ClientLoggedOut(notifyAboutAgentId); + } + } + else + { + StoredFriendListUpdate sob = new StoredFriendListUpdate(); + sob.OnlineYN = notifyOnlineStatus; + sob.storedAbout = notifyAboutAgentId; + sob.storedFor = notifyAgentId; + lock (StoredFriendListUpdates) + { + if (StoredFriendListUpdates.ContainsKey(notifyAgentId)) + { + StoredFriendListUpdates[notifyAgentId].Add(sob); + } + else + { + List newitem = new List(); + newitem.Add(sob); + StoredFriendListUpdates.Add(notifyAgentId, newitem); + } + } + } + + } return new XmlRpcResponse(); } @@ -110,24 +180,30 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends client.OnDenyFriendRequest += OnDenyFriendRequest; client.OnTerminateFriendship += OnTerminateFriendship; + doFriendListUpdateOnline(client.AgentId); + + } + + private void doFriendListUpdateOnline(LLUUID AgentId) + { List fl = new List(); //bool addFLback = false; lock (FriendLists) { - if (FriendLists.ContainsKey(client.AgentId)) + if (FriendLists.ContainsKey(AgentId)) { - fl = FriendLists[client.AgentId]; + fl = FriendLists[AgentId]; } else { - fl = m_scene[0].GetFriendList(client.AgentId); + fl = m_scene[0].GetFriendList(AgentId); //lock (FriendLists) //{ - if (!FriendLists.ContainsKey(client.AgentId)) - FriendLists.Add(client.AgentId, fl); + if (!FriendLists.ContainsKey(AgentId)) + FriendLists.Add(AgentId, fl); //} } } @@ -161,11 +237,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { foreach (FriendListItem fli in usrfl) { - if (fli.Friend == client.AgentId) + if (fli.Friend == AgentId) { fli.onlinestatus = true; LLUUID[] Agents = new LLUUID[1]; - Agents[0] = client.AgentId; + Agents[0] = AgentId; av.ControllingClient.SendAgentOnline(Agents); } @@ -176,8 +252,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends if (UpdateUsers.Count > 0) { - - client.SendAgentOnline(UpdateUsers.ToArray()); + ScenePresence avatar = GetPresenceFromAgentID(AgentId); + if (avatar != null) + { + avatar.ControllingClient.SendAgentOnline(UpdateUsers.ToArray()); + } } } @@ -302,6 +381,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { m_rootAgents.Add(avatar.UUID, avatar.RegionHandle); m_log.Info("[FRIEND]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + "."); + + List updateme = new List(); + lock (StoredFriendListUpdates) + { + if (StoredFriendListUpdates.ContainsKey(avatar.UUID)) + { + updateme = StoredFriendListUpdates[avatar.UUID]; + StoredFriendListUpdates.Remove(avatar.UUID); + } + } + + if (updateme.Count > 0) + { + foreach (StoredFriendListUpdate u in updateme) + { + if (u.OnlineYN) + doFriendListUpdateOnline(u.storedAbout); + else + ClientLoggedOut(u.storedAbout); + } + } } } //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); @@ -441,8 +541,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1); - m_pendingFriendRequests.Remove(transactionID); + + + //LLUUID[] Agents = new LLUUID[1]; + //Agents[0] = msg.toAgentID; + //av.ControllingClient.SendAgentOnline(Agents); + m_pendingFriendRequests.Remove(transactionID); // TODO: Inform agent that the friend is online } } @@ -498,4 +603,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends #endregion } + + public struct StoredFriendListUpdate + { + public LLUUID storedFor; + public LLUUID storedAbout; + public bool OnlineYN; + } } -- cgit v1.1