diff --git a/OpenSim/Framework/Communications/IInterRegionCommunications.cs b/OpenSim/Framework/Communications/IInterRegionCommunications.cs index 94e4cf7bf8..c64abb520f 100644 --- a/OpenSim/Framework/Communications/IInterRegionCommunications.cs +++ b/OpenSim/Framework/Communications/IInterRegionCommunications.cs @@ -33,6 +33,7 @@ namespace OpenSim.Framework.Communications { bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData); bool InformRegionOfPrimCrossing(ulong regionHandle, LLUUID primID, string objData); + bool RegionUp(RegionInfo region); bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying); bool ExpectPrimCrossing(ulong regionHandle, LLUUID primID, LLVector3 position, bool isFlying); diff --git a/OpenSim/Framework/IRegionCommsListener.cs b/OpenSim/Framework/IRegionCommsListener.cs index c9fc525df0..53d0059344 100644 --- a/OpenSim/Framework/IRegionCommsListener.cs +++ b/OpenSim/Framework/IRegionCommsListener.cs @@ -46,6 +46,8 @@ namespace OpenSim.Framework public delegate void CloseAgentConnection(ulong regionHandle, LLUUID agentID); + public delegate bool RegionUp(RegionInfo region); + public interface IRegionCommsListener @@ -59,5 +61,7 @@ namespace OpenSim.Framework event AcknowledgePrimCross OnAcknowledgePrimCrossed; event UpdateNeighbours OnNeighboursUpdate; event CloseAgentConnection OnCloseAgentConnection; + event RegionUp OnRegionUp; + } } \ No newline at end of file diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index 0e4d260f81..55075001a3 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -30,7 +30,7 @@ using libsecondlife; namespace OpenSim.Framework { public delegate void restart( RegionInfo thisRegion ); - public delegate void regionup ( RegionInfo thisRegion ); + //public delegate void regionup ( RegionInfo thisRegion ); public enum RegionStatus : int { @@ -43,13 +43,12 @@ namespace OpenSim.Framework public interface IScene { event restart OnRestart; - event regionup OnRegionUp; void AddNewClient(IClientAPI client, bool child); void RemoveClient(LLUUID agentID); void Restart(int seconds); - void OtherRegionUp(RegionInfo thisRegion); + bool OtherRegionUp(RegionInfo thisRegion); RegionInfo RegionInfo { get; } uint NextLocalId { get; } diff --git a/OpenSim/Framework/RegionCommsListener.cs b/OpenSim/Framework/RegionCommsListener.cs index 5dc9b8106e..449c073a99 100644 --- a/OpenSim/Framework/RegionCommsListener.cs +++ b/OpenSim/Framework/RegionCommsListener.cs @@ -42,6 +42,8 @@ namespace OpenSim.Framework public event AcknowledgeAgentCross OnAcknowledgeAgentCrossed; public event AcknowledgePrimCross OnAcknowledgePrimCrossed; public event CloseAgentConnection OnCloseAgentConnection; + public event RegionUp OnRegionUp; + /// /// @@ -68,6 +70,16 @@ namespace OpenSim.Framework return false; } + public virtual bool TriggerRegionUp(RegionInfo region) + { + if (OnRegionUp != null) + { + OnRegionUp(region); + return true; + } + return false; + } + public virtual bool TriggerExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) { diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index 8edfc6fc64..1afa74a1a1 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -454,7 +454,7 @@ namespace OpenSim } UDPServer restartingRegion = CreateRegion(whichRegion); restartingRegion.ServerListener(); - m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle); + //m_sceneManager.SendSimOnlineNotification(restartingRegion.RegionHandle); } diff --git a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs index 4efaa23709..746a19a6ae 100644 --- a/OpenSim/Region/Communications/Local/LocalBackEndServices.cs +++ b/OpenSim/Region/Communications/Local/LocalBackEndServices.cs @@ -155,11 +155,28 @@ namespace OpenSim.Region.Communications.Local return mapBlocks; } - /// + /// /// /// /// /// + /// + public bool RegionUp(RegionInfo region) + { + foreach (RegionCommsListener listener in m_regionListeners.Values) + { + listener.TriggerRegionUp(region); + } + + return true; + } + + public bool TriggerRegionUp(RegionInfo region) + { + + return false; + } + public bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData) //should change from agentCircuitData { diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs index 6b2407a9b2..a0d6bd37fb 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs @@ -380,6 +380,7 @@ namespace OpenSim.Region.Communications.OGS1 InterRegionSingleton.Instance.OnChildAgent += IncomingChildAgent; InterRegionSingleton.Instance.OnPrimGroupArrival += IncomingPrim; InterRegionSingleton.Instance.OnPrimGroupNear += TriggerExpectPrimCrossing; + InterRegionSingleton.Instance.OnRegionUp += TriggerRegionUp; } @@ -465,6 +466,81 @@ namespace OpenSim.Region.Communications.OGS1 } return true; } + + // UGLY! + public bool RegionUp(RegionInfo region) + { + RegionInfo regInfo = null; + try + { + if (m_localBackend.RegionUp(region)) + { + return true; + } + foreach (RegionInfo remoteInfo in m_remoteRegionInfoCache.Values) + { + regInfo = RequestNeighbourInfo(remoteInfo.RegionHandle); + if (regInfo != null) + { + //don't want to be creating a new link to the remote instance every time like we are here + bool retValue = false; + + + OGS1InterRegionRemoting remObject = (OGS1InterRegionRemoting)Activator.GetObject( + typeof(OGS1InterRegionRemoting), + "tcp://" + regInfo.RemotingAddress + + ":" + regInfo.RemotingPort + + "/InterRegions"); + + if (remObject != null) + { + retValue = remObject.RegionUp(region); + } + else + { + Console.WriteLine("remoting object not found"); + } + remObject = null; + + } + + } + + + return true; + } + catch (RemotingException e) + { + MainLog.Instance.Warn("Remoting Error: Unable to connect to adjacent region: " + regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY); + MainLog.Instance.Debug(e.ToString()); + return false; + } + catch (SocketException e) + { + MainLog.Instance.Warn("Socket Error: Unable to connect to adjacent region: " + regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY); + MainLog.Instance.Debug(e.ToString()); + return false; + } + catch (InvalidCredentialException e) + { + MainLog.Instance.Warn("Invalid Credentials: Unable to connect to adjacent region: " + regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY); + MainLog.Instance.Debug(e.ToString()); + return false; + } + catch (AuthenticationException e) + { + MainLog.Instance.Warn("Authentication exception: Unable to connect to adjacent region: " + regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY); + MainLog.Instance.Debug(e.ToString()); + return false; + } + catch (Exception e) + { + MainLog.Instance.Warn("Unknown exception: Unable to connect to adjacent region: " + regInfo.RegionName + " " + regInfo.RegionLocX + "," + regInfo.RegionLocY); + MainLog.Instance.Debug(e.ToString()); + return false; + } + return true; + } /// /// /// @@ -680,6 +756,20 @@ namespace OpenSim.Region.Communications.OGS1 } } + public bool TriggerRegionUp(RegionInfo regionData) + { + try + { + return m_localBackend.TriggerRegionUp(regionData); + } + + catch (RemotingException e) + { + MainLog.Instance.Error("Remoting Error: Unable to connect to adjacent region.\n" + e.ToString()); + return false; + } + } + /// /// /// diff --git a/OpenSim/Region/Communications/OGS1/OGS1InterSimComms.cs b/OpenSim/Region/Communications/OGS1/OGS1InterSimComms.cs index 70018fd5df..aa6f59a058 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1InterSimComms.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1InterSimComms.cs @@ -41,6 +41,8 @@ namespace OpenSim.Region.Communications.OGS1 public delegate bool PrimGroupArrival(ulong regionHandle, LLUUID primID, string objData); + public delegate bool RegionUP (RegionInfo region); + public sealed class InterRegionSingleton { private static readonly InterRegionSingleton instance = new InterRegionSingleton(); @@ -49,6 +51,8 @@ namespace OpenSim.Region.Communications.OGS1 public event ExpectArrival OnArrival; public event InformRegionPrimGroup OnPrimGroupNear; public event PrimGroupArrival OnPrimGroupArrival; + public event RegionUp OnRegionUp; + static InterRegionSingleton() { @@ -72,6 +76,15 @@ namespace OpenSim.Region.Communications.OGS1 return false; } + public bool RegionUp(RegionInfo region) + { + if (OnRegionUp != null) + { + return OnRegionUp(region); + } + return false; + } + public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) { if (OnArrival != null) @@ -116,7 +129,18 @@ namespace OpenSim.Region.Communications.OGS1 return false; } } - + public bool RegionUp(RegionInfo region) + { + try + { + return InterRegionSingleton.Instance.RegionUp(region); + } + catch (RemotingException e) + { + Console.WriteLine("Remoting Error: Unable to connect to remote region.\n" + e.ToString()); + return false; + } + } public bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) { try diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index fd17d56037..a9791eecd0 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -216,7 +216,7 @@ namespace OpenSim.Region.Environment.Scenes m_regionHandle = m_regInfo.RegionHandle; m_regionName = m_regInfo.RegionName; m_datastore = m_regInfo.DataStore; - RegisterRegionWithComms(); + m_physicalPrim = physicalPrim; m_sendTasksToChild = SendTasksToChild; @@ -244,6 +244,7 @@ namespace OpenSim.Region.Environment.Scenes httpListener = httpServer; m_dumpAssetsToFile = dumpAssetsToFile; + RegisterRegionWithComms(); } #endregion @@ -257,21 +258,29 @@ namespace OpenSim.Region.Environment.Scenes m_eventManager.OnPermissionError += SendPermissionAlert; } - public override void OtherRegionUp(RegionInfo otherRegion) + public override bool OtherRegionUp(RegionInfo otherRegion) { // Another region is up. We have to tell all our ScenePresences about it // This fails to get the desired effect and needs further work. - - ForEachScenePresence(delegate(ScenePresence agent) + try { - if (!(agent.IsChildAgent)) - { - InformClientOfNeighbor(agent, otherRegion); - this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); - + + ForEachScenePresence(delegate(ScenePresence agent) + { + if (!(agent.IsChildAgent)) + { + this.CommsManager.InterRegion.InformRegionOfChildAgent(otherRegion.RegionHandle, agent.ControllingClient.RequestClientInfo()); + InformClientOfNeighbor(agent, otherRegion); + } } + + ); } - ); + catch (System.NullReferenceException) + { + // This means that we're not booted up completely yet. + } + return true; } public virtual void Restart(float seconds) { @@ -1068,9 +1077,13 @@ namespace OpenSim.Region.Environment.Scenes m_sceneGridService.OnExpectUser += NewUserConnection; m_sceneGridService.OnAvatarCrossingIntoRegion += AgentCrossing; m_sceneGridService.OnCloseAgentConnection += CloseConnection; + m_sceneGridService.OnRegionUp += OtherRegionUp; + // Tell Other regions that I'm here. + m_sceneGridService.InformNeighborsThatRegionisUp(RegionInfo); } public void UnRegisterReginWithComms() { + m_sceneGridService.OnRegionUp -= OtherRegionUp; m_sceneGridService.OnExpectUser -= NewUserConnection; m_sceneGridService.OnAvatarCrossingIntoRegion -= AgentCrossing; m_sceneGridService.OnCloseAgentConnection -= CloseConnection; @@ -1578,9 +1591,13 @@ namespace OpenSim.Region.Environment.Scenes /// public void ForEachScenePresence(Action action) { - foreach (ScenePresence presence in m_scenePresences.Values) + // We don't want to try to send messages if there are no avatar. + if (!(m_scenePresences.Equals(null))) { - action(presence); + foreach (ScenePresence presence in m_scenePresences.Values) + { + action(presence); + } } } diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index 43593747fc..2db3bdcdcd 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -41,7 +41,6 @@ namespace OpenSim.Region.Environment.Scenes #region Events public event restart OnRestart; - public event regionup OnRegionUp; #endregion @@ -160,7 +159,7 @@ namespace OpenSim.Region.Environment.Scenes } - public abstract void OtherRegionUp(RegionInfo thisRegion); + public abstract bool OtherRegionUp(RegionInfo thisRegion); #endregion diff --git a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs index 9a10c514e7..ae44acbc1c 100644 --- a/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs +++ b/OpenSim/Region/Environment/Scenes/SceneCommunicationService.cs @@ -21,6 +21,7 @@ namespace OpenSim.Region.Environment.Scenes public event ExpectUserDelegate OnExpectUser; public event CloseAgentConnection OnCloseAgentConnection; public event PrimCrossing OnPrimCrossingIntoRegion; + public event RegionUp OnRegionUp; public SceneCommunicationService(CommunicationsManager commsMan) @@ -38,6 +39,7 @@ namespace OpenSim.Region.Environment.Scenes regionCommsHost.OnAvatarCrossingIntoRegion += AgentCrossing; regionCommsHost.OnPrimCrossingIntoRegion += PrimCrossing; regionCommsHost.OnCloseAgentConnection += CloseConnection; + regionCommsHost.OnRegionUp += newRegionUp; } @@ -45,12 +47,16 @@ namespace OpenSim.Region.Environment.Scenes public void Close() { - regionCommsHost.OnExpectUser -= NewUserConnection; - regionCommsHost.OnAvatarCrossingIntoRegion -= AgentCrossing; - regionCommsHost.OnPrimCrossingIntoRegion -= PrimCrossing; - regionCommsHost.OnCloseAgentConnection -= CloseConnection; - m_commsProvider.GridService.DeregisterRegion(m_regionInfo); - regionCommsHost = null; + if (regionCommsHost != null) + { + regionCommsHost.OnRegionUp -= newRegionUp; + regionCommsHost.OnExpectUser -= NewUserConnection; + regionCommsHost.OnAvatarCrossingIntoRegion -= AgentCrossing; + regionCommsHost.OnPrimCrossingIntoRegion -= PrimCrossing; + regionCommsHost.OnCloseAgentConnection -= CloseConnection; + m_commsProvider.GridService.DeregisterRegion(m_regionInfo); + regionCommsHost = null; + } } #region CommsManager Event handlers @@ -59,6 +65,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// + /// protected void NewUserConnection(ulong regionHandle, AgentCircuitData agent) { if (OnExpectUser != null) @@ -67,6 +74,15 @@ namespace OpenSim.Region.Environment.Scenes } } + protected bool newRegionUp(RegionInfo region) + { + if (OnRegionUp != null) + { + OnRegionUp(region); + } + return true; + } + protected void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying) { if (OnAvatarCrossingIntoRegion != null) @@ -249,6 +265,11 @@ namespace OpenSim.Region.Environment.Scenes return m_commsProvider.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position, isFlying); } + public void InformNeighborsThatRegionisUp(RegionInfo region) + { + bool val = m_commsProvider.InterRegion.RegionUp(region); + } + public bool PrimCrossToNeighboringRegion(ulong regionhandle, LLUUID primID, LLVector3 position, bool isPhysical) { return m_commsProvider.InterRegion.ExpectPrimCrossing(regionhandle, primID, position, isPhysical); diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs index 4360d97f46..c28269e2e7 100644 --- a/OpenSim/Region/Environment/Scenes/SceneManager.cs +++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs @@ -121,17 +121,35 @@ namespace OpenSim.Region.Environment.Scenes public void SendSimOnlineNotification(ulong regionHandle) { + RegionInfo Result = null; for (int i = 0; i < m_localScenes.Count; i++) { - if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) + + if (m_localScenes[i].RegionInfo.RegionHandle == regionHandle) { + // Inform other regions to tell their avatar about me - m_localScenes[i].OtherRegionUp(m_localScenes[i].RegionInfo); + Result = m_localScenes[i].RegionInfo; } } + if (!(Result.Equals(null))) + { + for (int i = 0; i < m_localScenes.Count; i++) + { + if (m_localScenes[i].RegionInfo.RegionHandle != regionHandle) + { + // Inform other regions to tell their avatar about me + //m_localScenes[i].OtherRegionUp(Result); + } + } + } + else + { + MainLog.Instance.Error("REGION", "Unable to notify Other regions of this Region coming up"); + } } public void SaveCurrentSceneToXml(string filename) {