From 5e2e05a1c1cf083c52728798c809711f4e2f52ae Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Sun, 16 Nov 2008 22:04:01 +0000 Subject: Megapatch. Completely remove the multiparameter IM methods. Remove the insecure fromAgentSession field. --- .../Modules/Avatar/Friends/FriendsModule.cs | 158 +++++++++++---------- .../Modules/Avatar/Groups/GroupsModule.cs | 17 +-- .../Avatar/InstantMessage/InstantMessageModule.cs | 30 +--- .../Avatar/InstantMessage/MessageTransferModule.cs | 8 +- .../Inventory/Transfer/InventoryTransferModule.cs | 49 +++---- .../Environment/Modules/World/NPC/NPCAvatar.cs | 7 +- OpenSim/Region/Environment/Scenes/Scene.cs | 1 - 7 files changed, 118 insertions(+), 152 deletions(-) (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs index 72c64ad..f07cd4c 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs @@ -263,7 +263,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // to a user to 'add a friend' without causing dialog box spam // Subscribe to instant messages - client.OnInstantMessage += OnInstantMessage; +// client.OnInstantMessage += OnInstantMessage; // Friend list management client.OnApproveFriendRequest += OnApproveFriendRequest; @@ -370,7 +370,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends #region FriendRequestHandling private void OnInstantMessage(IClientAPI client, UUID fromAgentID, - UUID fromAgentSession, UUID toAgentID, + UUID toAgentID, UUID imSessionID, uint timestamp, string fromAgentName, string message, byte dialog, bool fromGroup, byte offline, uint ParentEstateID, Vector3 Position, UUID RegionID, @@ -393,86 +393,65 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends // some properties are misused here: // fromAgentName is the *destination* name (the friend we offer friendship to) - if (fromAgentSession != UUID.Zero) - { - // (1) - // send the friendship-offer to the target - m_log.InfoFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}", - fromAgentID, fromAgentName, toAgentID, imSessionID, message, offline); - - UUID transactionID = UUID.Random(); - - // 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(message)) message = ""; - - GridInstantMessage msg = new GridInstantMessage(); - msg.fromAgentID = fromAgentID.Guid; - msg.fromAgentSession = UUID.Zero.Guid; // server IMs don't have a session - msg.toAgentID = toAgentID.Guid; - msg.imSessionID = transactionID.Guid; // Start new transaction - m_log.DebugFormat("[FRIEND]: new transactionID: {0}", msg.imSessionID); - msg.timestamp = timestamp; - if (client != null) - { - msg.fromAgentName = client.Name; // fromAgentName; - } - else - { - msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it - } - msg.message = message; - msg.dialog = dialog; - msg.fromGroup = fromGroup; - msg.offline = offline; - msg.ParentEstateID = ParentEstateID; - msg.Position = Position; - msg.RegionID = RegionID.Guid; - msg.binaryBucket = binaryBucket; - - m_log.DebugFormat("[FRIEND]: storing transactionID {0} on sender side", transactionID); - lock (m_pendingFriendRequests) - { - m_pendingFriendRequests.Add(transactionID, new Transaction(fromAgentID, fromAgentName)); - outPending(); - } + // (1) + // send the friendship-offer to the target + m_log.InfoFormat("[FRIEND]: Offer(38) - From: {0}, FromName: {1} To: {2}, Session: {3}, Message: {4}, Offline {5}", + fromAgentID, fromAgentName, toAgentID, imSessionID, message, offline); - // we don't want to get that new IM into here if we aren't local, as only on the destination - // should receive it. If we *are* local, *we* are the destination, so we have to receive it. - // As grid-IMs are routed to all modules (in contrast to local IMs), we have to decide here. + UUID transactionID = UUID.Random(); - // We don't really care which local scene we pipe it through. - if (m_TransferModule != null) - { - m_TransferModule.SendInstantMessage(msg, - delegate(bool success) {} - ); - } + // 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(message)) message = ""; + + GridInstantMessage msg = new GridInstantMessage(); + msg.fromAgentID = fromAgentID.Guid; + msg.toAgentID = toAgentID.Guid; + msg.imSessionID = transactionID.Guid; // Start new transaction + m_log.DebugFormat("[FRIEND]: new transactionID: {0}", msg.imSessionID); + msg.timestamp = timestamp; + if (client != null) + { + msg.fromAgentName = client.Name; // fromAgentName; } else { - // (2) - // we are on the receiving end here; just add the transactionID to the stored transactions for later lookup - m_log.DebugFormat("[FRIEND]: storing transactionID {0} on receiver side", imSessionID); - lock (m_pendingFriendRequests) - { - // if both are on the same region-server, the transaction is stored already, but we have to update the name - if (m_pendingFriendRequests.ContainsKey(imSessionID)) - { - m_pendingFriendRequests[imSessionID].agentName = fromAgentName; - m_pendingFriendRequests[imSessionID].count++; - } - else m_pendingFriendRequests.Add(imSessionID, new Transaction(fromAgentID, fromAgentName)); - outPending(); - } + msg.fromAgentName = "(hippos)"; // Added for posterity. This means that we can't figure out who sent it + } + msg.message = message; + msg.dialog = dialog; + msg.fromGroup = fromGroup; + msg.offline = offline; + msg.ParentEstateID = ParentEstateID; + msg.Position = Position; + msg.RegionID = RegionID.Guid; + msg.binaryBucket = binaryBucket; + + m_log.DebugFormat("[FRIEND]: storing transactionID {0} on sender side", transactionID); + lock (m_pendingFriendRequests) + { + m_pendingFriendRequests.Add(transactionID, new Transaction(fromAgentID, fromAgentName)); + outPending(); + } + + // we don't want to get that new IM into here if we aren't local, as only on the destination + // should receive it. If we *are* local, *we* are the destination, so we have to receive it. + // As grid-IMs are routed to all modules (in contrast to local IMs), we have to decide here. + + // We don't really care which local scene we pipe it through. + if (m_TransferModule != null) + { + m_TransferModule.SendInstantMessage(msg, + delegate(bool success) {} + ); } } else if (dialog == (byte)InstantMessageDialog.FriendshipAccepted) // 39 { // accepting the friendship offer causes a type 39 IM being sent to the (possibly remote) initiator // toAgentID is initiator, fromAgentID is new friend (which just approved) - m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agentSession {1}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", - client != null ? client.AgentId.ToString() : "", fromAgentSession, + m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", + client != null ? client.AgentId.ToString() : "", fromAgentID, fromAgentName, imSessionID, toAgentID, message, dialog); lock (m_pendingFriendRequests) { @@ -520,8 +499,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends { // 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}, agentSession {1}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", - client != null ? client.AgentId.ToString() : "", fromAgentSession, + m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", + client != null ? client.AgentId.ToString() : "", fromAgentID, fromAgentName, imSessionID, toAgentID, message, dialog); // not much to do, just clean up the transaction... @@ -542,13 +521,42 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends private void OnGridInstantMessage(GridInstantMessage msg) { + if (msg.dialog == (byte)InstantMessageDialog.FriendshipOffered) + { + // we are on the receiving end here; just add the transactionID + // to the stored transactions for later lookup + // + m_log.DebugFormat("[FRIEND]: storing transactionID {0} on "+ + "receiver side", msg.imSessionID); + + lock (m_pendingFriendRequests) + { + // if both are on the same region-server, the transaction + // is stored already, but we have to update the name + // + if (m_pendingFriendRequests.ContainsKey( + new UUID(msg.imSessionID))) + { + m_pendingFriendRequests[new UUID(msg.imSessionID)].agentName = + msg.fromAgentName; + m_pendingFriendRequests[new UUID(msg.imSessionID)].count++; + } + else m_pendingFriendRequests.Add(new UUID(msg.imSessionID), + new Transaction(new UUID(msg.fromAgentID), + msg.fromAgentName)); + + outPending(); + } + + return; + } + // Just call the IM handler above // This event won't be raised unless we have that agent, // so we can depend on the above not trying to send // via grid again // OnInstantMessage(null, new UUID(msg.fromAgentID), - new UUID(msg.fromAgentSession), new UUID(msg.toAgentID), new UUID(msg.imSessionID), msg.timestamp, msg.fromAgentName, msg.message, msg.dialog, msg.fromGroup, msg.offline, @@ -604,7 +612,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends msg.toAgentID = friendID.Guid; msg.fromAgentID = agentID.Guid; msg.fromAgentName = client.Name; - msg.fromAgentSession = UUID.Zero.Guid; // server IMs don't have a session msg.fromGroup = false; msg.imSessionID = transactionID.Guid; msg.message = agentID.Guid.ToString(); @@ -664,7 +671,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends msg.toAgentID = friendID.Guid; msg.fromAgentID = agentID.Guid; msg.fromAgentName = client.Name; - msg.fromAgentSession = UUID.Zero.Guid; // server IMs don't have a session msg.fromGroup = false; msg.imSessionID = transactionID.Guid; msg.message = agentID.Guid.ToString(); diff --git a/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs index c291c16..eea8e40 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Groups/GroupsModule.cs @@ -178,27 +178,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Groups ActiveGroupTitle); } - private void OnInstantMessage(IClientAPI client, UUID fromAgentID, - UUID fromAgentSession, UUID toAgentID, - UUID imSessionID, uint timestamp, string fromAgentName, - string message, byte dialog, bool fromGroup, byte offline, - uint ParentEstateID, Vector3 Position, UUID RegionID, - byte[] binaryBucket) + private void OnInstantMessage(IClientAPI client, GridInstantMessage im) { } private void OnGridInstantMessage(GridInstantMessage msg) { // Trigger the above event handler - OnInstantMessage(null, new UUID(msg.fromAgentID), - new UUID(msg.fromAgentSession), - new UUID(msg.toAgentID), new UUID(msg.imSessionID), - msg.timestamp, msg.fromAgentName, - msg.message, msg.dialog, msg.fromGroup, msg.offline, - msg.ParentEstateID, - new Vector3(msg.Position.X, msg.Position.Y, msg.Position.Z), - new UUID(msg.RegionID), - msg.binaryBucket); + OnInstantMessage(null, msg); } private void HandleUUIDGroupNameRequest(UUID id,IClientAPI remote_client) diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs index cd8c82c..b106435 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/InstantMessageModule.cs @@ -110,33 +110,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage #endregion - private void OnInstantMessage(IClientAPI client, UUID fromAgentID, - UUID fromAgentSession, UUID toAgentID, - UUID imSessionID, uint timestamp, string fromAgentName, - string message, byte dialog, bool fromGroup, byte offline, - uint ParentEstateID, Vector3 Position, UUID RegionID, - byte[] binaryBucket) - { - // This module handles exclusively private text IM from user - // to user. All others will be caught in other modules - // - if ( dialog != (byte)InstantMessageDialog.MessageFromAgent - && dialog != (byte)InstantMessageDialog.StartTyping - && dialog != (byte)InstantMessageDialog.StopTyping) - { - return; - } - - GridInstantMessage im = new GridInstantMessage(client.Scene, - fromAgentID, fromAgentName, fromAgentSession, toAgentID, - dialog, fromGroup, message, imSessionID, - offline != 0 ? true : false, Position, - binaryBucket); - - ProcessInstantMessage(client, im); - } - - private void ProcessInstantMessage(IClientAPI client, GridInstantMessage im) + public void OnInstantMessage(IClientAPI client, GridInstantMessage im) { byte dialog = im.dialog; @@ -183,7 +157,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage // so we can depend on the above not trying to send // via grid again // - ProcessInstantMessage(null, msg); + OnInstantMessage(null, msg); } } } diff --git a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs index 0dc29a1..67346ae 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/InstantMessage/MessageTransferModule.cs @@ -185,7 +185,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage bool successful = false; // various rational defaults UUID fromAgentID = UUID.Zero; - UUID fromAgentSession = UUID.Zero; UUID toAgentID = UUID.Zero; UUID imSessionID = UUID.Zero; uint timestamp = 0; @@ -207,7 +206,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage Hashtable requestData = (Hashtable)request.Params[0]; // Check if it's got all the data - if (requestData.ContainsKey("from_agent_id") && requestData.ContainsKey("from_agent_session") + if (requestData.ContainsKey("from_agent_id") && requestData.ContainsKey("to_agent_id") && requestData.ContainsKey("im_session_id") && requestData.ContainsKey("timestamp") && requestData.ContainsKey("from_agent_name") && requestData.ContainsKey("message") && requestData.ContainsKey("dialog") @@ -219,7 +218,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage { // Do the easy way of validating the UUIDs UUID.TryParse((string)requestData["from_agent_id"], out fromAgentID); - UUID.TryParse((string)requestData["from_agent_session"], out fromAgentSession); UUID.TryParse((string)requestData["to_agent_id"], out toAgentID); UUID.TryParse((string)requestData["im_session_id"], out imSessionID); UUID.TryParse((string)requestData["region_id"], out RegionID); @@ -337,7 +335,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage GridInstantMessage gim = new GridInstantMessage(); gim.fromAgentID = fromAgentID.Guid; gim.fromAgentName = fromAgentName; - gim.fromAgentSession = fromAgentSession.Guid; gim.fromGroup = fromGroup; gim.imSessionID = imSessionID.Guid; gim.RegionID = RegionID.Guid; @@ -598,7 +595,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.InstantMessage { Hashtable gim = new Hashtable(); gim["from_agent_id"] = msg.fromAgentID.ToString(); - gim["from_agent_session"] = msg.fromAgentSession.ToString(); + // Kept for compatibility + gim["from_agent_session"] = UUID.Zero.ToString(); gim["to_agent_id"] = msg.toAgentID.ToString(); gim["im_session_id"] = msg.imSessionID.ToString(); gim["timestamp"] = msg.timestamp.ToString(); diff --git a/OpenSim/Region/Environment/Modules/Avatar/Inventory/Transfer/InventoryTransferModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Inventory/Transfer/InventoryTransferModule.cs index 71cc726..f4707de 100644 --- a/OpenSim/Region/Environment/Modules/Avatar/Inventory/Transfer/InventoryTransferModule.cs +++ b/OpenSim/Region/Environment/Modules/Avatar/Inventory/Transfer/InventoryTransferModule.cs @@ -117,38 +117,34 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Transfer return null; } - private void OnInstantMessage(IClientAPI client, UUID fromAgentID, - UUID fromAgentSession, UUID toAgentID, - UUID imSessionID, uint timestamp, string fromAgentName, - string message, byte dialog, bool fromGroup, byte offline, - uint ParentEstateID, Vector3 Position, UUID RegionID, - byte[] binaryBucket) + private void OnInstantMessage(IClientAPI client, GridInstantMessage im) { Scene scene = FindClientScene(client.AgentId); if (scene == null) // Something seriously wrong here. return; - if (dialog == (byte) InstantMessageDialog.InventoryOffered) + if (im.dialog == (byte) InstantMessageDialog.InventoryOffered) { ScenePresence user = - scene.GetScenePresence(toAgentID); + scene.GetScenePresence(new UUID(im.toAgentID)); // First byte of the array is probably the item type // Next 16 bytes are the UUID - UUID itemID = new UUID(binaryBucket, 1); + UUID itemID = new UUID(im.binaryBucket, 1); m_log.DebugFormat("[AGENT INVENTORY]: Inserting item {0} "+ "into agent {1}'s inventory", - itemID, toAgentID); + itemID, new UUID(im.toAgentID)); - InventoryItemBase itemCopy = scene.GiveInventoryItem(toAgentID, + InventoryItemBase itemCopy = scene.GiveInventoryItem( + new UUID(im.toAgentID), client.AgentId, itemID); byte[] itemCopyID = itemCopy.ID.GetBytes(); - Array.Copy(itemCopyID, 0, binaryBucket, 1, 16); + Array.Copy(itemCopyID, 0, im.binaryBucket, 1, 16); // Send the IM to the recipient. The item is already // in their inventory, so it will not be lost if @@ -164,9 +160,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Transfer // same ID back on the reply so we know what to act on // user.ControllingClient.SendInstantMessage( - fromAgentID, message, toAgentID, fromAgentName, - dialog, timestamp, itemCopy.ID, false, - binaryBucket); + new UUID(im.fromAgentID), im.message, + new UUID(im.toAgentID), + im.fromAgentName, im.dialog, im.timestamp, + itemCopy.ID, false, im.binaryBucket); return; } @@ -177,15 +174,17 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Transfer // TODO: Implement grid sending } } - else if (dialog == (byte) InstantMessageDialog.InventoryAccepted) + else if (im.dialog == (byte) InstantMessageDialog.InventoryAccepted) { - ScenePresence user = scene.GetScenePresence(toAgentID); + ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); if (user != null) // Local { user.ControllingClient.SendInstantMessage( - fromAgentID, message, toAgentID, fromAgentName, - dialog, timestamp, UUID.Zero, false, binaryBucket); + new UUID(im.fromAgentID), im.message, + new UUID(im.toAgentID), + im.fromAgentName, im.dialog, im.timestamp, + UUID.Zero, false, im.binaryBucket); } else { @@ -194,9 +193,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Transfer // TODO: Implement sending via grid } } - else if (dialog == (byte) InstantMessageDialog.InventoryDeclined) + else if (im.dialog == (byte) InstantMessageDialog.InventoryDeclined) { - UUID itemID = imSessionID; // The item, back from it's trip + UUID itemID = new UUID(im.imSessionID); // The item, back from it's trip // Here, the recipient is local and we can assume that the // inventory is loaded. Courtesy of the above bulk update, @@ -235,13 +234,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Inventory.Transfer } } - ScenePresence user = scene.GetScenePresence(toAgentID); + ScenePresence user = scene.GetScenePresence(new UUID(im.toAgentID)); if (user != null) // Local { user.ControllingClient.SendInstantMessage( - fromAgentID, message, toAgentID, fromAgentName, - dialog, timestamp, UUID.Zero, false, binaryBucket); + new UUID(im.fromAgentID), im.message, + new UUID(im.toAgentID), + im.fromAgentName, im.dialog, im.timestamp, + UUID.Zero, false, im.binaryBucket); } else { diff --git a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs index de0a41a..735a521 100644 --- a/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/Environment/Modules/World/NPC/NPCAvatar.cs @@ -84,9 +84,10 @@ namespace OpenSim.Region.Environment.Modules.World.NPC public void InstantMessage(UUID target, string message) { - OnInstantMessage(this, m_uuid, SessionId, target, UUID.Combine(m_uuid, target), - (uint) Util.UnixTimeSinceEpoch(), Name, message, 0, false, 0, 0, - Position, m_scene.RegionInfo.RegionID, new byte[0]); + OnInstantMessage(this, new GridInstantMessage(m_scene, + m_uuid, m_firstname + " " + m_lastname, + target, 0, false, message, + UUID.Zero, false, Position, new byte[0])); } public void SendAgentOffline(UUID[] agentIDs) diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index e19857c..0416e3a 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -977,7 +977,6 @@ namespace OpenSim.Region.Environment.Scenes GridInstantMessage msg = new GridInstantMessage(); msg.fromAgentID = new Guid(UUID.Zero.ToString()); // From server - msg.fromAgentSession = new Guid(transaction.ToString()); msg.toAgentID = new Guid(ret.Key.ToString()); msg.imSessionID = new Guid(transaction.ToString()); msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); -- cgit v1.1