diff --git a/OpenSim/Framework/IRegionCommsListener.cs b/OpenSim/Framework/IRegionCommsListener.cs index 1a24469fed..24c6499244 100644 --- a/OpenSim/Framework/IRegionCommsListener.cs +++ b/OpenSim/Framework/IRegionCommsListener.cs @@ -38,6 +38,8 @@ namespace OpenSim.Framework public delegate void AcknowledgeAgentCross(ulong regionHandle, LLUUID agentID); + public delegate void CloseAgentConnection(ulong regionHandle, LLUUID agentID); + public interface IRegionCommsListener { event ExpectUserDelegate OnExpectUser; @@ -45,5 +47,6 @@ namespace OpenSim.Framework event AgentCrossing OnAvatarCrossingIntoRegion; event AcknowledgeAgentCross OnAcknowledgeAgentCrossed; event UpdateNeighbours OnNeighboursUpdate; + event CloseAgentConnection OnCloseAgentConnection; } } \ No newline at end of file diff --git a/OpenSim/Framework/RegionCommsListener.cs b/OpenSim/Framework/RegionCommsListener.cs index ee0d5036e4..84d1b02b7f 100644 --- a/OpenSim/Framework/RegionCommsListener.cs +++ b/OpenSim/Framework/RegionCommsListener.cs @@ -38,6 +38,7 @@ namespace OpenSim.Framework public event AgentCrossing OnAvatarCrossingIntoRegion; public event UpdateNeighbours OnNeighboursUpdate; public event AcknowledgeAgentCross OnAcknowledgeAgentCrossed; + public event CloseAgentConnection OnCloseAgentConnection; /// /// @@ -76,6 +77,14 @@ namespace OpenSim.Framework return false; } + public virtual void TriggerCloseAgentConnection(ulong regionHandle, LLUUID agentID) + { + if (OnCloseAgentConnection != null) + { + OnCloseAgentConnection(regionHandle, agentID); + } + } + /// /// /// diff --git a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs index 852dc8e91f..1e7681305c 100644 --- a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs +++ b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs @@ -182,7 +182,7 @@ namespace OpenSim.Region.Communications.Local { if (m_regionListeners.ContainsKey(regionHandle)) { - // m_regionListeners[regionHandle].TriggerExpectAvatarCrossing(regionHandle, agentID, position, isFlying); + m_regionListeners[regionHandle].TriggerCloseAgentConnection(regionHandle, agentID); } } diff --git a/OpenSim/Region/Environment/Modules/ChatModule.cs b/OpenSim/Region/Environment/Modules/ChatModule.cs index 9d4187a41c..52491edefa 100644 --- a/OpenSim/Region/Environment/Modules/ChatModule.cs +++ b/OpenSim/Region/Environment/Modules/ChatModule.cs @@ -181,60 +181,63 @@ namespace OpenSim.Region.Environment.Modules { m_scene.ForEachScenePresence(delegate(ScenePresence presence) { - int dis = -100000; - - LLVector3 avatarRegionPos = presence.AbsolutePosition + - new LLVector3( - scene.RegionInfo.RegionLocX*256, - scene.RegionInfo.RegionLocY*256, - 0); - dis = - Math.Abs((int) avatarRegionPos.GetDistanceTo(fromRegionPos)); - - switch (e.Type) + if (!presence.IsChildAgent) { - case ChatTypeEnum.Whisper: - if (dis < m_whisperdistance) - { - //should change so the message is sent through the avatar rather than direct to the ClientView - presence.ControllingClient.SendChatMessage(message, - type, - fromPos, - fromName, - fromAgentID); - } - break; - case ChatTypeEnum.Say: - if (dis < m_saydistance) - { - //Console.WriteLine("sending chat"); - presence.ControllingClient.SendChatMessage(message, - type, - fromPos, - fromName, - fromAgentID); - } - break; - case ChatTypeEnum.Shout: - if (dis < m_shoutdistance) - { - presence.ControllingClient.SendChatMessage(message, - type, - fromPos, - fromName, - fromAgentID); - } - break; + int dis = -100000; - case ChatTypeEnum.Broadcast: - presence.ControllingClient.SendChatMessage(message, - type, - fromPos, - fromName, - fromAgentID); - break; - default: - break; + LLVector3 avatarRegionPos = presence.AbsolutePosition + + new LLVector3( + scene.RegionInfo.RegionLocX * 256, + scene.RegionInfo.RegionLocY * 256, + 0); + dis = + Math.Abs((int)avatarRegionPos.GetDistanceTo(fromRegionPos)); + + switch (e.Type) + { + case ChatTypeEnum.Whisper: + if (dis < m_whisperdistance) + { + //should change so the message is sent through the avatar rather than direct to the ClientView + presence.ControllingClient.SendChatMessage(message, + type, + fromPos, + fromName, + fromAgentID); + } + break; + case ChatTypeEnum.Say: + if (dis < m_saydistance) + { + //Console.WriteLine("sending chat"); + presence.ControllingClient.SendChatMessage(message, + type, + fromPos, + fromName, + fromAgentID); + } + break; + case ChatTypeEnum.Shout: + if (dis < m_shoutdistance) + { + presence.ControllingClient.SendChatMessage(message, + type, + fromPos, + fromName, + fromAgentID); + } + break; + + case ChatTypeEnum.Broadcast: + presence.ControllingClient.SendChatMessage(message, + type, + fromPos, + fromName, + fromAgentID); + break; + default: + break; + } } }); } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 8262478aa3..d436bb350a 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -816,6 +816,7 @@ namespace OpenSim.Region.Environment.Scenes m_sceneGridService.RegisterRegion(m_regInfo); m_sceneGridService.OnExpectUser += NewUserConnection; m_sceneGridService.OnAvatarCrossingIntoRegion += AgentCrossing; + m_sceneGridService.OnCloseAgentConnection += CloseConnection; } /// @@ -864,13 +865,26 @@ namespace OpenSim.Region.Environment.Scenes } } + public void CloseConnection(ulong regionHandle, LLUUID agentID) + { + if (regionHandle == m_regionHandle) + { + ScenePresence presence = m_innerScene.GetScenePresence(agentID); + if(presence != null) + { + libsecondlife.Packets.DisableSimulatorPacket disable = new libsecondlife.Packets.DisableSimulatorPacket(); + presence.ControllingClient.OutPacket(disable); + } + } + } + /// /// /// public void InformClientOfNeighbours(ScenePresence presence) { - m_sceneGridService.InformClientOfNeighbours(presence); + m_sceneGridService.EnableNeighbourChildAgents(presence); } /// @@ -908,7 +922,7 @@ namespace OpenSim.Region.Environment.Scenes { if (m_scenePresences.ContainsKey(remoteClient.AgentId)) { - m_sceneGridService.RequestTeleportLocation(m_scenePresences[remoteClient.AgentId], regionHandle, position, lookAt, flags); + m_sceneGridService.RequestTeleportToLocation(m_scenePresences[remoteClient.AgentId], regionHandle, position, lookAt, flags); } } @@ -920,7 +934,7 @@ namespace OpenSim.Region.Environment.Scenes /// public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying) { - return m_sceneGridService.InformNeighbourOfCrossing(regionhandle, agentID, position, isFlying); + return m_sceneGridService.CrossToNeighbouringRegion(regionhandle, agentID, position, isFlying); } #endregion diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs index 27b0cbad3e..9bd55e1811 100644 --- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs @@ -19,7 +19,7 @@ namespace OpenSim.Region.Environment.Scenes public event AgentCrossing OnAvatarCrossingIntoRegion; public event ExpectUserDelegate OnExpectUser; - + public event CloseAgentConnection OnCloseAgentConnection; public SceneCommunicationService(CommunicationsManager commsMan) { @@ -34,6 +34,7 @@ namespace OpenSim.Region.Environment.Scenes { regionCommsHost.OnExpectUser += NewUserConnection; regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing; + regionCommsHost.OnCloseAgentConnection += CloseConnection; } } @@ -41,6 +42,7 @@ namespace OpenSim.Region.Environment.Scenes { regionCommsHost.OnExpectUser -= NewUserConnection; regionCommsHost.OnAvatarCrossingIntoRegion -= AgentCrossing; + regionCommsHost.OnCloseAgentConnection -= CloseConnection; //regionCommsHost.RemoveRegion(m_regionInfo); //TODO add to method to commsManager regionCommsHost = null; } @@ -51,7 +53,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - public void NewUserConnection(ulong regionHandle, AgentCircuitData agent) + protected void NewUserConnection(ulong regionHandle, AgentCircuitData agent) { if (OnExpectUser != null) { @@ -59,13 +61,21 @@ namespace OpenSim.Region.Environment.Scenes } } - public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) + protected void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) { if (OnAvatarCrossingIntoRegion != null) { OnAvatarCrossingIntoRegion(regionHandle, agentID, position, isFlying); } } + + protected void CloseConnection(ulong regionHandle, LLUUID agentID) + { + if (OnCloseAgentConnection != null) + { + OnCloseAgentConnection(regionHandle, agentID); + } + } #endregion #region Inform Client of Neighbours @@ -105,7 +115,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - public void InformClientOfNeighbours(ScenePresence avatar) + public void EnableNeighbourChildAgents(ScenePresence avatar) { List neighbours = m_commsProvider.GridService.RequestNeighbours(m_regionInfo.RegionLocX, m_regionInfo.RegionLocY); @@ -160,7 +170,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - public virtual void RequestTeleportLocation(ScenePresence avatar, ulong regionHandle, LLVector3 position, + public virtual void RequestTeleportToLocation(ScenePresence avatar, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags) { if (regionHandle == m_regionInfo.RegionHandle) @@ -189,6 +199,14 @@ namespace OpenSim.Region.Environment.Scenes string capsPath = Util.GetCapsURL(avatar.ControllingClient.AgentId); avatar.ControllingClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4), capsPath); avatar.MakeChildAgent(); + uint newRegionX = (uint)(regionHandle >> 40); + uint newRegionY = (((uint)(regionHandle)) >> 8); + uint oldRegionX = (uint)(m_regionInfo.RegionHandle >> 40); + uint oldRegionY = (((uint)(m_regionInfo.RegionHandle)) >> 8); + if (Util.fast_distance2d((int)(newRegionX - oldRegionX), (int)(newRegionY - oldRegionY)) > 3) + { + CloseChildAgentConnections(avatar); + } } } } @@ -199,14 +217,19 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying) + public bool CrossToNeighbouringRegion(ulong regionhandle, LLUUID agentID, LLVector3 position, bool isFlying) { return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); } public void CloseChildAgentConnections(ScenePresence presence) { - + foreach (ulong regionHandle in presence.KnownChildRegions) + { + + m_commsProvider.InterRegion.TellRegionToCloseChildConnection(regionHandle, presence.ControllingClient.AgentId); + presence.RemoveNeighbourRegion(regionHandle); + } } } } diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 628921ce4c..49e3c395a2 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -232,6 +232,10 @@ namespace OpenSim.Region.Environment.Scenes set { m_parentID = value; } } + public List KnownChildRegions + { + get { return m_KnownChildRegions; } + } #endregion #region Constructor(s) @@ -411,6 +415,13 @@ namespace OpenSim.Region.Environment.Scenes } } + public void RemoveNeighbourRegion(ulong regionHandle) + { + if (!m_KnownChildRegions.Contains(regionHandle)) + { + m_KnownChildRegions.Remove(regionHandle); + } + } #endregion #region Event Handlers @@ -1090,9 +1101,8 @@ namespace OpenSim.Region.Environment.Scenes public void SetWearable(int wearableId, AvatarWearable wearable) { m_wearables[wearableId] = wearable; - m_controllingClient.SendWearables(m_wearables, m_wearablesSerial++); - SendOurAppearance( m_controllingClient ); - + m_controllingClient.SendWearables(m_wearables, ++m_wearablesSerial); + //m_controllingClient.SendWearables(m_wearables, m_wearablesSerial++); } } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs index 1176e13219..e0ddec5fac 100644 --- a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs +++ b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs @@ -10,7 +10,7 @@ using OpenSim.Region.Physics.Manager; namespace OpenSim.Region.Environment.Scenes { - public class SceneXmlLoader //Most likely can move to a module + public class SceneXmlLoader // can move to a module? { protected InnerScene m_innerScene; protected RegionInfo m_regInfo;