From 272bf712796ad8e98e79aee50311a84deaf23d79 Mon Sep 17 00:00:00 2001 From: Dan Lake Date: Thu, 27 Oct 2011 02:26:37 -0700 Subject: Removed use of 'is' operator and casting to find the root ScenePresence in MessageTransfer modules and Groups module. --- .../InstantMessage/HGMessageTransferModule.cs | 57 +++++++++------------- .../Avatar/InstantMessage/MessageTransferModule.cs | 52 ++++++++------------ .../Avatar/XmlRpcGroups/GroupsMessagingModule.cs | 15 +++--- .../Avatar/XmlRpcGroups/GroupsModule.cs | 11 ++--- 4 files changed, 53 insertions(+), 82 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs index 72b448b..321a705 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/HGMessageTransferModule.cs @@ -143,24 +143,19 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage // Try root avatar only first foreach (Scene scene in m_Scenes) { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) - { -// m_log.DebugFormat( -// "[HG INSTANT MESSAGE]: Looking for root agent {0} in {1}", -// toAgentID.ToString(), scene.RegionInfo.RegionName); - - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - if (!user.IsChildAgent) - { - // Local message -// m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", user.Name, toAgentID); - user.ControllingClient.SendInstantMessage(im); +// m_log.DebugFormat( +// "[HG INSTANT MESSAGE]: Looking for root agent {0} in {1}", +// toAgentID.ToString(), scene.RegionInfo.RegionName); + ScenePresence sp = scene.GetScenePresence(toAgentID); + if (sp != null && !sp.IsChildAgent) + { + // Local message +// m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", user.Name, toAgentID); + sp.ControllingClient.SendInstantMessage(im); - // Message sent - result(true); - return; - } + // Message sent + result(true); + return; } } @@ -168,16 +163,14 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage foreach (Scene scene in m_Scenes) { // m_log.DebugFormat( -// "[HG INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); - - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) - { +// "[HG INSTANT MESSAGE]: Looking for child of {0} in {1}", +// toAgentID, scene.RegionInfo.RegionName); + ScenePresence sp = scene.GetScenePresence(toAgentID); + if (sp != null) + { // Local message - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - // m_log.DebugFormat("[HG INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", user.Name, toAgentID); - user.ControllingClient.SendInstantMessage(im); + sp.ControllingClient.SendInstantMessage(im); // Message sent result(true); @@ -231,17 +224,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage bool successful = false; foreach (Scene scene in m_Scenes) { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) + ScenePresence sp = scene.GetScenePresence(toAgentID); + if(!sp.IsChildAgent) { - ScenePresence user = - (ScenePresence)scene.Entities[toAgentID]; - - if (!user.IsChildAgent) - { - scene.EventManager.TriggerIncomingInstantMessage(gim); - successful = true; - } + scene.EventManager.TriggerIncomingInstantMessage(gim); + successful = true; } } if (!successful) diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs index 45b84f4..0dad3c4 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/MessageTransferModule.cs @@ -136,24 +136,19 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage // Try root avatar only first foreach (Scene scene in m_Scenes) { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) +// m_log.DebugFormat( +// "[INSTANT MESSAGE]: Looking for root agent {0} in {1}", +// toAgentID.ToString(), scene.RegionInfo.RegionName); + ScenePresence sp = scene.GetScenePresence(toAgentID); + if (sp != null && !sp.IsChildAgent) { -// m_log.DebugFormat( -// "[INSTANT MESSAGE]: Looking for root agent {0} in {1}", -// toAgentID.ToString(), scene.RegionInfo.RegionName); - - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - if (!user.IsChildAgent) - { - // Local message -// m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", user.Name, toAgentID); - user.ControllingClient.SendInstantMessage(im); - - // Message sent - result(true); - return; - } + // Local message +// m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to root agent {0} {1}", user.Name, toAgentID); + sp.ControllingClient.SendInstantMessage(im); + + // Message sent + result(true); + return; } } @@ -162,15 +157,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage { // m_log.DebugFormat( // "[INSTANT MESSAGE]: Looking for child of {0} in {1}", toAgentID, scene.RegionInfo.RegionName); - - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) + ScenePresence sp = scene.GetScenePresence(toAgentID); + if (sp != null) { // Local message - ScenePresence user = (ScenePresence) scene.Entities[toAgentID]; - // m_log.DebugFormat("[INSTANT MESSAGE]: Delivering IM to child agent {0} {1}", user.Name, toAgentID); - user.ControllingClient.SendInstantMessage(im); + sp.ControllingClient.SendInstantMessage(im); // Message sent result(true); @@ -389,17 +381,11 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage // Trigger the Instant message in the scene. foreach (Scene scene in m_Scenes) { - if (scene.Entities.ContainsKey(toAgentID) && - scene.Entities[toAgentID] is ScenePresence) + ScenePresence sp = scene.GetScenePresence(toAgentID); + if (sp != null && !sp.IsChildAgent) { - ScenePresence user = - (ScenePresence)scene.Entities[toAgentID]; - - if (!user.IsChildAgent) - { - scene.EventManager.TriggerIncomingInstantMessage(gim); - successful = true; - } + scene.EventManager.TriggerIncomingInstantMessage(gim); + successful = true; } } if (!successful) diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs index a12e6ea..10b83e6 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsMessagingModule.cs @@ -504,19 +504,18 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups // Try root avatar first foreach (Scene scene in m_sceneList) { - if (scene.Entities.ContainsKey(agentID) && - scene.Entities[agentID] is ScenePresence) + ScenePresence sp = scene.GetScenePresence(agentID); + if (sp != null) { - ScenePresence user = (ScenePresence)scene.Entities[agentID]; - if (!user.IsChildAgent) + if (!sp.IsChildAgent) { - if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", user.ControllingClient.Name); - return user.ControllingClient; + if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found root agent for client : {0}", sp.ControllingClient.Name); + return sp.ControllingClient; } else { - if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", user.ControllingClient.Name); - child = user.ControllingClient; + if (m_debugEnabled) m_log.WarnFormat("[GROUPS-MESSAGING]: Found child agent for client : {0}", sp.ControllingClient.Name); + child = sp.ControllingClient; } } } diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index 630fcab..b2c0f48 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -1076,17 +1076,16 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups // Try root avatar first foreach (Scene scene in m_sceneList) { - if (scene.Entities.ContainsKey(agentID) && - scene.Entities[agentID] is ScenePresence) + ScenePresence sp = scene.GetScenePresence(agentID); + if (sp != null) { - ScenePresence user = (ScenePresence)scene.Entities[agentID]; - if (!user.IsChildAgent) + if (!sp.IsChildAgent) { - return user.ControllingClient; + return sp.ControllingClient; } else { - child = user.ControllingClient; + child = sp.ControllingClient; } } } -- cgit v1.1