From be20f41637b6c06ce3ab16bc25851b6e43468e12 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Wed, 30 Apr 2008 21:43:47 +0000 Subject: * Cruft removal step #1. Cleaning Modules directory. --- .../Modules/Avatar/Friends/FriendsModule.cs | 165 ++++++++++----------- 1 file changed, 81 insertions(+), 84 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 3b0cc4c..db38d87 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -42,13 +42,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private Dictionary> FriendLists = new Dictionary>(); + private Dictionary m_pendingFriendRequests = new Dictionary(); + private Dictionary m_rootAgents = new Dictionary(); private List m_scene = new List(); - Dictionary m_rootAgents = new Dictionary(); - - Dictionary m_pendingFriendRequests = new Dictionary(); - - Dictionary> FriendLists = new Dictionary>(); + #region IRegionModule Members public void Initialise(Scene scene, IConfigSource config) { @@ -68,11 +67,33 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends scene.EventManager.OnMakeChildAgent += MakeChildAgent; scene.EventManager.OnClientClosed += ClientLoggedOut; } + + public void PostInitialise() + { + } + + public void Close() + { + } + + public string Name + { + get { return "FriendsModule"; } + } + + public bool IsSharedModule + { + get { return true; } + } + + #endregion + public XmlRpcResponse processPresenceUpdate(XmlRpcRequest req) { m_log.Info("[FRIENDS]: Got Notification about a user! OMG"); return new XmlRpcResponse(); } + private void OnNewClient(IClientAPI client) { // All friends establishment protocol goes over instant message @@ -83,7 +104,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // 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; @@ -99,10 +120,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { fl = FriendLists[client.AgentId]; } - else + else { fl = m_scene[0].GetFriendList(client.AgentId); - + //lock (FriendLists) //{ if (!FriendLists.ContainsKey(client.AgentId)) @@ -110,11 +131,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends //} } } - + List UpdateUsers = new List(); foreach (FriendListItem f in fl) - { + { if (m_rootAgents.ContainsKey(f.Friend)) { if (f.onlinestatus == false) @@ -169,10 +190,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends onp.AgentBlock = onpb; client.OutPacket(onp, ThrottleOutPacketType.Task); } - - - - } private void ClientLoggedOut(LLUUID AgentId) @@ -182,7 +199,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends if (m_rootAgents.ContainsKey(AgentId)) { m_rootAgents.Remove(AgentId); - m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); + m_log.Info("[FRIEND]: Removing " + AgentId + ". Agent logged out."); } } List lfli = new List(); @@ -208,7 +225,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends List flfli = new List(); try { - lock (FriendLists) { if (FriendLists.ContainsKey(updateUsers[i])) @@ -231,9 +247,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { flfli[i].onlinestatus = false; } - } - + catch (IndexOutOfRangeException) { // Ignore the index out of range exception. @@ -242,15 +257,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends m_log.Info("[FRIEND]: Unable to enumerate last friendlist user. User logged off"); } } - } - + 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(); @@ -265,7 +278,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { FriendLists.Remove(AgentId); } - } private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID) @@ -282,7 +294,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { JId avatarID = new JId(avatar.JID); // REST Post XMPP Stanzas! - } // Claim User! my user! Mine mine mine! } @@ -295,9 +306,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends } //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); } + private void MakeChildAgent(ScenePresence avatar) { - lock (m_rootAgents) { if (m_rootAgents.ContainsKey(avatar.UUID)) @@ -307,30 +318,53 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends m_rootAgents.Remove(avatar.UUID); m_log.Info("[FRIEND]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent"); } - } } + } + private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) + { + ScenePresence returnAgent = null; + lock (m_scene) + { + ScenePresence queryagent = null; + for (int i = 0; i < m_scene.Count; i++) + { + queryagent = m_scene[i].GetScenePresence(AgentID); + if (queryagent != null) + { + if (!queryagent.IsChildAgent) + { + returnAgent = queryagent; + break; + } + } + } + } + return returnAgent; } + #region FriendRequestHandling - private void OnInstantMessage(IClientAPI client,LLUUID fromAgentID, + + private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID, LLUUID fromAgentSession, LLUUID toAgentID, LLUUID imSessionID, uint timestamp, string fromAgentName, - string message, byte dialog, bool fromGroup, byte offline, - uint ParentEstateID, LLVector3 Position, LLUUID RegionID, + string message, byte dialog, bool fromGroup, byte offline, + uint ParentEstateID, LLVector3 Position, LLUUID RegionID, byte[] binaryBucket) { // Friend Requests go by Instant Message.. using the dialog param // https://wiki.secondlife.com/wiki/ImprovedInstantMessage // 38 == Offer friendship - if (dialog == (byte)38) + if (dialog == (byte) 38) { LLUUID friendTransactionID = LLUUID.Random(); m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); - m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); + m_log.Info("[FRIEND]: 38 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + + message); GridInstantMessage msg = new GridInstantMessage(); msg.fromAgentID = fromAgentID.UUID; msg.fromAgentSession = fromAgentSession.UUID; @@ -340,11 +374,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends msg.timestamp = timestamp; if (client != null) { - msg.fromAgentName = client.FirstName + " " + client.LastName;// fromAgentName; + msg.fromAgentName = client.FirstName + " " + client.LastName; // fromAgentName; } else { - msg.fromAgentName = "(hippos)";// Added for posterity. This means that we can't figure out who sent it + msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it } msg.message = message; msg.dialog = dialog; @@ -359,15 +393,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends } // 39 == Accept Friendship - if (dialog == (byte)39) + if (dialog == (byte) 39) { - m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); + m_log.Info("[FRIEND]: 39 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + + message); } // 40 == Decline Friendship - if (dialog == (byte)40) + if (dialog == (byte) 40) { - m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + message); + m_log.Info("[FRIEND]: 40 - From:" + fromAgentID.ToString() + " To: " + toAgentID.ToString() + " Session:" + imSessionID.ToString() + " Message:" + + message); } } @@ -395,16 +431,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends msg.imSessionID = transactionID.UUID; msg.message = agentID.UUID.ToString(); msg.ParentEstateID = 0; - msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); + msg.timestamp = (uint) Util.UnixTimeSinceEpoch(); msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; - msg.dialog = (byte)39;// Approved friend request + msg.dialog = (byte) 39; // Approved friend request msg.Position = new sLLVector3(); - msg.offline = (byte)0; + msg.offline = (byte) 0; msg.binaryBucket = new byte[0]; // We don't really care which scene we pipe it through, it goes to the shared IM Module and/or the database SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); - SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint)1); + SceneAgentIn.StoreAddFriendship(m_pendingFriendRequests[transactionID], agentID, (uint) 1); m_pendingFriendRequests.Remove(transactionID); // TODO: Inform agent that the friend is online @@ -433,11 +469,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends msg.imSessionID = transactionID.UUID; msg.message = agentID.UUID.ToString(); msg.ParentEstateID = 0; - msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); + msg.timestamp = (uint) Util.UnixTimeSinceEpoch(); msg.RegionID = SceneAgentIn.RegionInfo.RegionID.UUID; - msg.dialog = (byte)40;// Deny friend request + msg.dialog = (byte) 40; // Deny friend request msg.Position = new sLLVector3(); - msg.offline = (byte)0; + msg.offline = (byte) 0; msg.binaryBucket = new byte[0]; SceneAgentIn.TriggerGridInstantMessage(msg, InstantMessageReceiver.IMModule); m_pendingFriendRequests.Remove(transactionID); @@ -453,52 +489,13 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends private void OnGridInstantMessage(GridInstantMessage msg) { // Trigger the above event handler - OnInstantMessage(null,new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), + OnInstantMessage(null, new LLUUID(msg.fromAgentID), new LLUUID(msg.fromAgentSession), new LLUUID(msg.toAgentID), new LLUUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, msg.message, msg.dialog, msg.fromGroup, msg.offline, msg.ParentEstateID, new LLVector3(msg.Position.x, msg.Position.y, msg.Position.z), new LLUUID(msg.RegionID), msg.binaryBucket); } - #endregion - private ScenePresence GetPresenceFromAgentID(LLUUID AgentID) - { - ScenePresence returnAgent = null; - lock (m_scene) - { - ScenePresence queryagent = null; - for (int i = 0; i < m_scene.Count; i++) - { - queryagent = m_scene[i].GetScenePresence(AgentID); - if (queryagent != null) - { - if (!queryagent.IsChildAgent) - { - returnAgent = queryagent; - break; - } - } - } - } - return returnAgent; - - } - - public void PostInitialise() - { - } - - public void Close() - { - } - public string Name - { - get { return "FriendsModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } + #endregion } } \ No newline at end of file -- cgit v1.1