From e0b7ad767799ba4d9fef1b450f36772134fe1ec9 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 22 Dec 2008 18:39:06 +0000 Subject: * Refactor: Move some code into separate methods in FriendsModule --- .../Modules/Avatar/Friends/FriendsModule.cs | 132 +++++++++++++-------- 1 file changed, 83 insertions(+), 49 deletions(-) (limited to 'OpenSim/Region/Environment/Modules') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 6a8141a..1346508 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -382,67 +382,101 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { // Friend Requests go by Instant Message.. using the dialog param // https://wiki.secondlife.com/wiki/ImprovedInstantMessage - UUID fromAgentID = new UUID(im.fromAgentID); - UUID toAgentID = new UUID(im.toAgentID); if (im.dialog == (byte)InstantMessageDialog.FriendshipOffered) // 38 { - // this is triggered by the initiating agent: - // A local agent offers friendship to some possibly remote friend. - // A IM is triggered, processed here and sent to the friend (possibly in a remote region). - - // some properties are misused here: - // fromAgentName is the *destination* name (the friend we offer friendship to) - - m_log.InfoFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}", - im.fromAgentID, im.fromAgentName, im.toAgentID, im.imSessionID, im.message, im.offline); - - // 1.20 protocol sends an UUID in the message field, instead of the friendship offer text. - // For interoperability, we have to clear that - if (Util.isUUID(im.message)) im.message = ""; - - // be sneeky and use the initiator-UUID as transactionID. This means we can be stateless. - // we have to look up the agent name on friendship-approval, though. - im.imSessionID = im.fromAgentID; - im.fromAgentName = client.Name; - - if (m_TransferModule != null) - { - // Send it to whoever is the destination. - // If new friend is local, it will send an IM to the viewer. - // If new friend is remote, it will cause a OnGridInstantMessage on the remote server - m_TransferModule.SendInstantMessage(im, - delegate(bool success) { - m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); - } - ); - } + FriendshipOffered(client, im); } else if (im.dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39 { - m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", - client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); - + FriendshipAccepted(client, im); } else if (im.dialog == (byte)InstantMessageDialog.FriendshipDeclined) // 40 { - // declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator - // toAgentID is initiator, fromAgentID declined friendship - m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", - client != null ? client.AgentId.ToString() : "", - fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); + FriendshipDeclined(client, im); + } + } + + /// + /// Invoked when a user offers a friendship. + /// + /// May not currently be used - see OnApproveFriendRequest() instead + /// + /// + private void FriendshipOffered(IClientAPI client, GridInstantMessage im) + { + // this is triggered by the initiating agent: + // A local agent offers friendship to some possibly remote friend. + // A IM is triggered, processed here and sent to the friend (possibly in a remote region). + + // some properties are misused here: + // fromAgentName is the *destination* name (the friend we offer friendship to) + + m_log.DebugFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}", + im.fromAgentID, im.fromAgentName, im.toAgentID, im.imSessionID, im.message, im.offline); - // Send the decline to whoever is the destination. - GridInstantMessage msg = new GridInstantMessage(client.Scene, fromAgentID, client.Name, toAgentID, - im.dialog, im.message, im.offline != 0, im.Position); + // 1.20 protocol sends an UUID in the message field, instead of the friendship offer text. + // For interoperability, we have to clear that + if (Util.isUUID(im.message)) im.message = ""; + + // be sneeky and use the initiator-UUID as transactionID. This means we can be stateless. + // we have to look up the agent name on friendship-approval, though. + im.imSessionID = im.fromAgentID; + im.fromAgentName = client.Name; + + if (m_TransferModule != null) + { + // Send it to whoever is the destination. // If new friend is local, it will send an IM to the viewer. // If new friend is remote, it will cause a OnGridInstantMessage on the remote server - m_TransferModule.SendInstantMessage(msg, - delegate(bool success) { + m_TransferModule.SendInstantMessage(im, + delegate(bool success) + { m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); } ); - } + } + } + + /// + /// Invoked when a user accepts a friendship offer. + /// + /// + /// + private void FriendshipAccepted(IClientAPI client, GridInstantMessage im) + { + m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", + client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); + } + + /// + /// Invoked when a user declines a friendship offer. + /// + /// May not currently be used - see OnDenyFriendRequest() instead + /// + /// + private void FriendshipDeclined(IClientAPI client, GridInstantMessage im) + { + UUID fromAgentID = new UUID(im.fromAgentID); + UUID toAgentID = new UUID(im.toAgentID); + + // declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator + // toAgentID is initiator, fromAgentID declined friendship + m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", + client != null ? client.AgentId.ToString() : "", + fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); + + // Send the decline to whoever is the destination. + GridInstantMessage msg = new GridInstantMessage(client.Scene, fromAgentID, client.Name, toAgentID, + im.dialog, im.message, im.offline != 0, im.Position); + + // If new friend is local, it will send an IM to the viewer. + // If new friend is remote, it will cause a OnGridInstantMessage on the remote server + m_TransferModule.SendInstantMessage(msg, + delegate(bool success) { + m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); + } + ); } private void OnGridInstantMessage(GridInstantMessage msg) @@ -467,11 +501,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends if (msg.dialog == (byte)InstantMessageDialog.FriendshipAccepted) { // for accept friendship, we have to do a bit more - approveFriendship(new UUID(msg.fromAgentID), new UUID(msg.toAgentID), msg.fromAgentName); + ApproveFriendship(new UUID(msg.fromAgentID), new UUID(msg.toAgentID), msg.fromAgentName); } } - private void approveFriendship(UUID fromAgentID, UUID toAgentID, string fromName) + private void ApproveFriendship(UUID fromAgentID, UUID toAgentID, string fromName) { m_log.DebugFormat("[FRIEND]: Approve friendship from {0} (ID: {1}) to {2}", fromAgentID, fromName, toAgentID); @@ -537,7 +571,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends friendPresence.ControllingClient.SendInstantMessage(agentID, agentID.ToString(), friendID, client.Name, (byte)InstantMessageDialog.FriendshipAccepted, (uint)Util.UnixTimeSinceEpoch()); - approveFriendship(agentID, friendID, client.Name); + ApproveFriendship(agentID, friendID, client.Name); } else { -- cgit v1.1