From 39c9b656c871bf0eaba104f197a902123d7d9428 Mon Sep 17 00:00:00 2001 From: BlueWall Date: Mon, 23 Jan 2012 09:42:15 -0500 Subject: [PATCH 1/5] Cleanup unused parts, add some error handling --- .../World/Estate/TelehubManager.cs | 121 +++++++++--------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs index ee77ae1d28..68b4ba5a63 100644 --- a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs +++ b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs @@ -35,82 +35,65 @@ namespace OpenSim.Region.CoreModules.World.Estate { public class TelehubManager { - - private UUID ObjectID; - private string ObjectName; - private Vector3 ObjectPosition; - Quaternion ObjectRotation; - List SpawnPoint = new List(); - UUID EstateID; - bool m_HasTelehub = false; Scene m_Scene; - // This will get an option... - Vector3 InitialSpawnPoint = new Vector3(0.0f,0.0f,0.0f); - - public bool HasTelehub - { - get { return m_HasTelehub; } - } public TelehubManager(Scene scene) { m_Scene = scene; } - // Fill our Telehub struct with values -// public Telehub TelehubVals() -// { -// // Telehub telehub = new Telehub(); -// EstateSettings telehub = m_EstateSettings; -// -// telehub.TelehubObject = ObjectID; -// telehub.TelehubName = ObjectName; -// telehub.TelehubPos = ObjectPosition; -// telehub.TelehubRot = ObjectRotation; -// telehub. = SpawnPoint; -// return telehub; -// } - // Connect the Telehub public bool Connect(SceneObjectPart part) - { - m_Scene.RegionInfo.RegionSettings.ClearSpawnPoints(); - - m_Scene.RegionInfo.RegionSettings.TelehubObject = part.UUID; - m_Scene.RegionInfo.RegionSettings.TelehubName = part.Name; - m_Scene.RegionInfo.RegionSettings.TelehubPos = part.AbsolutePosition; - m_Scene.RegionInfo.RegionSettings.TelehubRot = part.GetWorldRotation(); - - // Clear this for now - m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(InitialSpawnPoint); - m_Scene.RegionInfo.RegionSettings.HasTelehub = true; - m_Scene.RegionInfo.RegionSettings.Save(); - return true; - } - - // Disconnect the Telehub: Clear it out for now, look at just disableing - public bool DisConnect(SceneObjectPart part) { bool result = false; - try{ - m_Scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero; - m_Scene.RegionInfo.RegionSettings.TelehubName = String.Empty; - m_Scene.RegionInfo.RegionSettings.TelehubPos = Vector3.Zero; - // This is probably wrong! But, HasTelehub will block access - m_Scene.RegionInfo.RegionSettings.TelehubRot = Quaternion.Identity; + if (m_Scene.RegionInfo.RegionSettings.HasTelehub) + return result; + + try + { m_Scene.RegionInfo.RegionSettings.ClearSpawnPoints(); - m_Scene.RegionInfo.RegionSettings.HasTelehub = false; + + m_Scene.RegionInfo.RegionSettings.TelehubObject = part.UUID; + m_Scene.RegionInfo.RegionSettings.TelehubName = part.Name; + m_Scene.RegionInfo.RegionSettings.TelehubPos = part.AbsolutePosition; + m_Scene.RegionInfo.RegionSettings.TelehubRot = part.GetWorldRotation(); + m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(new Vector3(0.0f,0.0f,0.0f)); + m_Scene.RegionInfo.RegionSettings.HasTelehub = true; m_Scene.RegionInfo.RegionSettings.Save(); + result = true; } catch (Exception ex) { result = false; } - finally - { + return result; + } + + // Disconnect the Telehub: + public bool DisConnect(SceneObjectPart part) + { + bool result = false; + + if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) + return result; + + try + { + m_Scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero; + m_Scene.RegionInfo.RegionSettings.TelehubName = String.Empty; + m_Scene.RegionInfo.RegionSettings.TelehubPos = Vector3.Zero; + m_Scene.RegionInfo.RegionSettings.ClearSpawnPoints(); + m_Scene.RegionInfo.RegionSettings.HasTelehub = false; + m_Scene.RegionInfo.RegionSettings.Save(); + + result = true; + } + catch (Exception ex) + { + result = false; } return result; @@ -119,19 +102,35 @@ namespace OpenSim.Region.CoreModules.World.Estate // Add a SpawnPoint to the Telehub public bool AddSpawnPoint(Vector3 point) { + bool result = false; - float dist = (float) Util.GetDistanceTo(m_Scene.RegionInfo.RegionSettings.TelehubPos, point); - Vector3 nvec = Util.GetNormalizedVector(point - m_Scene.RegionInfo.RegionSettings.TelehubPos); - Vector3 spoint = nvec * dist; + if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) + return result; - m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(spoint); - m_Scene.RegionInfo.RegionSettings.Save(); - return true; + try + { + float dist = (float) Util.GetDistanceTo(m_Scene.RegionInfo.RegionSettings.TelehubPos, point); + Vector3 nvec = Util.GetNormalizedVector(point - m_Scene.RegionInfo.RegionSettings.TelehubPos); + Vector3 spoint = nvec * dist; + + m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(spoint); + m_Scene.RegionInfo.RegionSettings.Save(); + result = true; + } + catch (Exception ex) + { + result = false; + } + + return result; } // Remove a SpawnPoint from the Telehub public bool RemoveSpawnPoint(int spawnpoint) { + if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) + return false; + m_Scene.RegionInfo.RegionSettings.RemoveSpawnPoint(spawnpoint); m_Scene.RegionInfo.RegionSettings.Save(); From 9cfc43005d8d906083b176a2961aa3892193dcb4 Mon Sep 17 00:00:00 2001 From: BlueWall Date: Mon, 23 Jan 2012 10:28:18 -0500 Subject: [PATCH 2/5] Cleanup --- .../Region/CoreModules/World/Estate/TelehubManager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs index 68b4ba5a63..9b92df94fe 100644 --- a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs +++ b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs @@ -109,10 +109,13 @@ namespace OpenSim.Region.CoreModules.World.Estate try { - float dist = (float) Util.GetDistanceTo(m_Scene.RegionInfo.RegionSettings.TelehubPos, point); - Vector3 nvec = Util.GetNormalizedVector(point - m_Scene.RegionInfo.RegionSettings.TelehubPos); + Vector3 thPos = m_Scene.RegionInfo.RegionSettings.TelehubPos; + Quaternion thRot = m_Scene.RegionInfo.RegionSettings.TelehubRot; + + float dist = (float) Util.GetDistanceTo(thPos, point); + Vector3 nvec = Util.GetNormalizedVector(point - thPos); Vector3 spoint = nvec * dist; - + m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(spoint); m_Scene.RegionInfo.RegionSettings.Save(); result = true; From 6a85abbd14f36f9d1f1035820730f3e8cd395987 Mon Sep 17 00:00:00 2001 From: BlueWall Date: Mon, 23 Jan 2012 14:53:25 -0500 Subject: [PATCH 3/5] Add update to Telehub position and rotation before adding SpawnPoints --- .../CoreModules/World/Estate/TelehubManager.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs index 9b92df94fe..2d7d0eef90 100644 --- a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs +++ b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs @@ -109,11 +109,18 @@ namespace OpenSim.Region.CoreModules.World.Estate try { - Vector3 thPos = m_Scene.RegionInfo.RegionSettings.TelehubPos; - Quaternion thRot = m_Scene.RegionInfo.RegionSettings.TelehubRot; + // Need to update the position in case the Telehubn has been moved + UUID TelehubID = m_Scene.RegionInfo.RegionSettings.TelehubObject; + SceneObjectPart part = m_Scene.GetSceneObjectPart(TelehubID); - float dist = (float) Util.GetDistanceTo(thPos, point); - Vector3 nvec = Util.GetNormalizedVector(point - thPos); + Vector3 TelehubPos = part.AbsolutePosition; + Quaternion TelehubRot = part.GetWorldRotation(); + + m_Scene.RegionInfo.RegionSettings.TelehubPos = TelehubPos; + m_Scene.RegionInfo.RegionSettings.TelehubRot = TelehubRot; + + float dist = (float) Util.GetDistanceTo(TelehubPos, point); + Vector3 nvec = Util.GetNormalizedVector(point - TelehubPos); Vector3 spoint = nvec * dist; m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(spoint); From 48379e644206bf59e5e2059902f1d7dfd1be5e94 Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 23 Jan 2012 21:23:55 +0000 Subject: [PATCH 4/5] IMPORTANT!!!!! Please READ. DO NOT Use this version or any before it since the Telehub commits! They will eat your babies and corrupt your database while they munch. DO NOT use anything from the first Telehub commit to this one. FIRST GOOD COMMIT is the one FOLLOWING this one. You have been warned. --- .../Data/MySQL/Resources/RegionStore.migrations | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/OpenSim/Data/MySQL/Resources/RegionStore.migrations b/OpenSim/Data/MySQL/Resources/RegionStore.migrations index 31321484a1..720e200310 100644 --- a/OpenSim/Data/MySQL/Resources/RegionStore.migrations +++ b/OpenSim/Data/MySQL/Resources/RegionStore.migrations @@ -848,21 +848,12 @@ COMMIT; BEGIN; CREATE TABLE IF NOT EXISTS `spawn_points` ( `RegionID` varchar(36) COLLATE utf8_unicode_ci NOT NULL, - `PointX` float NOT NULL, - `PointY` float NOT NULL, - `PointZ` float NOT NULL, + `Yaw` float NOT NULL, + `Pitch` float NOT NULL, + `Distance` float NOT NULL, KEY `RegionID` (`RegionID`) ) ENGINE=Innodb; ALTER TABLE `regionsettings` ADD COLUMN `TelehubObject` varchar(36) NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubName` varchar(255) NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubEnabled` tinyint(4) NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubPosX` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubPosY` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubPosZ` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubRotX` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubRotY` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubRotZ` float NOT NULL; -ALTER TABLE `regionsettings` ADD COLUMN `TelehubRotW` float NOT NULL; COMMIT; From 87799c1f3ddfbc4b0994cac4e54498520899e4d4 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 24 Jan 2012 00:32:10 +0000 Subject: [PATCH 5/5] Change Telehubs to store only the data that is really needed and not additional redundant information. --- OpenSim/Data/MySQL/MySQLSimulationData.cs | 53 ++------ OpenSim/Framework/RegionSettings.cs | 116 +++++++----------- .../World/Estate/EstateManagementModule.cs | 78 +++++++----- .../World/Estate/TelehubManager.cs | 70 +++-------- 4 files changed, 123 insertions(+), 194 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index b94f6ac701..ebb41a526d 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -997,9 +997,7 @@ namespace OpenSim.Data.MySQL "covenant, Sandbox, sunvectorx, sunvectory, " + "sunvectorz, loaded_creation_datetime, " + "loaded_creation_id, map_tile_ID, " + - "TelehubEnabled, TelehubObject, TelehubName, " + - "TelehubPosX, TelehubPosY, TelehubPosZ, " + - "TelehubRotX, TelehubRotY, TelehubRotZ, TelehubRotW) " + + "TelehubObject) " + "values (?RegionUUID, ?BlockTerraform, " + "?BlockFly, ?AllowDamage, ?RestrictPushing, " + "?AllowLandResell, ?AllowLandJoinDivide, " + @@ -1015,10 +1013,7 @@ namespace OpenSim.Data.MySQL "?SunPosition, ?Covenant, ?Sandbox, " + "?SunVectorX, ?SunVectorY, ?SunVectorZ, " + "?LoadedCreationDateTime, ?LoadedCreationID, " + - "?TerrainImageID, " + - "?TelehubEnabled, ?TelehubObject, ?TelehubName, " + - "?TelehubPosX, ?TelehubPosY, ?TelehubPosZ, " + - "?TelehubRotX, ?TelehubRotY, ?TelehubRotZ, ?TelehubRotW )"; + "?TerrainImageID) "; FillRegionSettingsCommand(cmd, rs); @@ -1306,20 +1301,7 @@ namespace OpenSim.Data.MySQL newSettings.LoadedCreationID = (String) row["loaded_creation_id"]; newSettings.TerrainImageID = DBGuid.FromDB(row["map_tile_ID"]); - newSettings.HasTelehub = Convert.ToBoolean(row["TelehubEnabled"]); newSettings.TelehubObject = DBGuid.FromDB(row["TelehubObject"]); - newSettings.TelehubName = (string) row["TelehubName"]; - newSettings.TelehubPos = new Vector3 ( - Convert.ToSingle(row["TelehubPosX"]), - Convert.ToSingle(row["TelehubPosY"]), - Convert.ToSingle(row["TelehubPosZ"]) - ); - newSettings.TelehubRot = new Quaternion ( - Convert.ToSingle(row["TelehubRotX"]), - Convert.ToSingle(row["TelehubRotY"]), - Convert.ToSingle(row["TelehubRotZ"]), - Convert.ToSingle(row["TelehubRotW"]) - ); return newSettings; } @@ -1650,16 +1632,7 @@ namespace OpenSim.Data.MySQL cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime); cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID); cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID); - cmd.Parameters.AddWithValue("TelehubEnabled", settings.HasTelehub); cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject); - cmd.Parameters.AddWithValue("TelehubName", settings.TelehubName); - cmd.Parameters.AddWithValue("TelehubPosX", settings.TelehubPos.X); - cmd.Parameters.AddWithValue("TelehubPosY", settings.TelehubPos.Y); - cmd.Parameters.AddWithValue("TelehubPosZ", settings.TelehubPos.Z); - cmd.Parameters.AddWithValue("TelehubRotX", settings.TelehubRot.X); - cmd.Parameters.AddWithValue("TelehubRotY", settings.TelehubRot.Y); - cmd.Parameters.AddWithValue("TelehubRotZ", settings.TelehubRot.Z); - cmd.Parameters.AddWithValue("TelehubRotW", settings.TelehubRot.W); } /// @@ -1874,20 +1847,20 @@ namespace OpenSim.Data.MySQL using (MySqlCommand cmd = dbcon.CreateCommand()) { - cmd.CommandText = "select PointX, PointY, PointZ from spawn_points where RegionID = ?RegionID"; + cmd.CommandText = "select Yaw, Pitch, Distance from spawn_points where RegionID = ?RegionID"; cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString()); using (IDataReader r = cmd.ExecuteReader()) { while (r.Read()) { - Vector3 point = new Vector3(); + SpawnPoint sp = new SpawnPoint(); - point.X = (float)r["PointX"]; - point.Y = (float)r["PointY"]; - point.Z = (float)r["PointZ"]; + sp.Yaw = (float)r["Yaw"]; + sp.Pitch = (float)r["Pitch"]; + sp.Distance = (float)r["Distance"]; - rs.AddSpawnPoint(point); + rs.AddSpawnPoint(sp); } } } @@ -1912,14 +1885,14 @@ namespace OpenSim.Data.MySQL cmd.Parameters.Clear(); - cmd.CommandText = "insert into spawn_points (RegionID, PointX, PointY, PointZ) values ( ?RegionID, ?PointX, ?PointY,?PointZ)"; + cmd.CommandText = "insert into spawn_points (RegionID, Yaw, Pitch, Distance) values ( ?RegionID, ?Yaw, ?Pitch, ?Distance)"; - foreach (Vector3 p in rs.SpawnPoints()) + foreach (SpawnPoint p in rs.SpawnPoints()) { cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString()); - cmd.Parameters.AddWithValue("?PointX", p.X); - cmd.Parameters.AddWithValue("?PointY", p.Y); - cmd.Parameters.AddWithValue("?PointZ", p.Z); + cmd.Parameters.AddWithValue("?Yaw", p.Yaw); + cmd.Parameters.AddWithValue("?Pitch", p.Pitch); + cmd.Parameters.AddWithValue("?Distance", p.Distance); cmd.ExecuteNonQuery(); cmd.Parameters.Clear(); diff --git a/OpenSim/Framework/RegionSettings.cs b/OpenSim/Framework/RegionSettings.cs index 9b5bbf28cb..0a59f43153 100644 --- a/OpenSim/Framework/RegionSettings.cs +++ b/OpenSim/Framework/RegionSettings.cs @@ -32,6 +32,47 @@ using OpenMetaverse; namespace OpenSim.Framework { + public struct SpawnPoint + { + public float Yaw; + public float Pitch; + public float Distance; + + public void SetLocation(Vector3 pos, Quaternion rot, Vector3 point) + { + // The point is an absolute position, so we need the relative + // location to the spawn point + Vector3 offset = pos - point; + Distance = Vector3.Mag(offset); + + // Next we need to rotate this vector into the spawn point's + // coordinate system + offset = offset * rot; + + Vector3 dir = Vector3.Normalize(offset); + + // Get the bearing (yaw) + Yaw = (float)Math.Atan2(dir.Y, dir.X); + + // Get the elevation (pitch) + Pitch = (float)-Math.Atan2(dir.Z, Math.Sqrt(dir.X * dir.X + dir.Y * dir.Y)); + } + + public Vector3 GetLocation(Vector3 pos, Quaternion rot) + { + Quaternion y = Quaternion.CreateFromEulers(0, 0, Yaw); + Quaternion p = Quaternion.CreateFromEulers(0, Pitch, 0); + + Vector3 dir = new Vector3(1, 0, 0) * p * y; + Vector3 offset = dir * (float)Distance; + + rot.W = -rot.W; + offset *= rot; + + return pos + offset; + } + } + public class RegionSettings { public delegate void SaveDelegate(RegionSettings rs); @@ -398,28 +439,13 @@ namespace OpenSim.Framework set { m_LoadedCreationID = value; } } - // Telehub support - private bool m_TelehubEnabled = false; - public bool HasTelehub - { - get { return m_TelehubEnabled; } - set { m_TelehubEnabled = value; } - } - // Connected Telehub object private UUID m_TelehubObject; public UUID TelehubObject { get { - if (HasTelehub) - { - return m_TelehubObject; - } - else - { - return UUID.Zero; - } + return m_TelehubObject; } set { @@ -427,66 +453,14 @@ namespace OpenSim.Framework } } - // Connected Telehub name - private string m_TelehubName; - public string TelehubName - { - get - { - if (HasTelehub) - { - return m_TelehubName; - } - else - { - return String.Empty; - } - } - set - { - m_TelehubName = value; - } - } - - // Connected Telehub position - private Vector3 m_TelehubPos; - public Vector3 TelehubPos - { - get - { - if (HasTelehub) - { - return m_TelehubPos; - } - else - { - return Vector3.Zero; - } - } - set - { - m_TelehubPos = value; - } - } - - // Connected Telehub rotation - private Quaternion m_TelehubRot; - public Quaternion TelehubRot - { - get - { return m_TelehubRot; } - set - { m_TelehubRot = value; } - } - // Our Connected Telehub's SpawnPoints - public List l_SpawnPoints = new List(); + public List l_SpawnPoints = new List(); // Add a SpawnPoint // ** These are not region coordinates ** // They are relative to the Telehub coordinates // - public void AddSpawnPoint(Vector3 point) + public void AddSpawnPoint(SpawnPoint point) { l_SpawnPoints.Add(point); } @@ -498,7 +472,7 @@ namespace OpenSim.Framework } // Return the List of SpawnPoints - public List SpawnPoints() + public List SpawnPoints() { return l_SpawnPoints; diff --git a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs index cdcea65a3f..2789d5f2cd 100644 --- a/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Estate/EstateManagementModule.cs @@ -609,59 +609,37 @@ namespace OpenSim.Region.CoreModules.World.Estate { case "info ui": // Send info: - if (Scene.RegionInfo.RegionSettings.HasTelehub) - { - RegionSettings settings = this.Scene.RegionInfo.RegionSettings; - client.SendTelehubInfo(settings.TelehubObject, settings.TelehubName, settings.TelehubPos, - settings.TelehubRot, settings.SpawnPoints()); - } - else - { - return; - } + SendTelehubInfo(client); break; case "connect": // Add the Telehub part = Scene.GetSceneObjectPart((uint)param1); - if (m_Telehub.Connect(part)) - { - RegionSettings settings = this.Scene.RegionInfo.RegionSettings; - client.SendTelehubInfo(settings.TelehubObject, settings.TelehubName, settings.TelehubPos, - settings.TelehubRot, settings.SpawnPoints()); - } + if (part == null) + return; + SceneObjectGroup grp = part.ParentGroup; + + if (m_Telehub.Connect(grp)) + SendTelehubInfo(client); break; case "delete": // Disconnect Telehub - part = Scene.GetSceneObjectPart((uint)param1); - if (m_Telehub.DisConnect(part)) - { - RegionSettings settings = this.Scene.RegionInfo.RegionSettings; - client.SendTelehubInfo(settings.TelehubObject, settings.TelehubName, settings.TelehubPos, - settings.TelehubRot, settings.SpawnPoints()); - } + if (m_Telehub.Disconnect()) + SendTelehubInfo(client); break; case "spawnpoint add": // Add SpawnPoint to the Telehub part = Scene.GetSceneObjectPart((uint)param1); if( m_Telehub.AddSpawnPoint(part.AbsolutePosition)) - { - RegionSettings settings = this.Scene.RegionInfo.RegionSettings; - client.SendTelehubInfo(settings.TelehubObject, settings.TelehubName, settings.TelehubPos, - settings.TelehubRot, settings.SpawnPoints()); - } + SendTelehubInfo(client); break; case "spawnpoint remove": // Remove SpawnPoint from Telehub if (m_Telehub.RemoveSpawnPoint((int)param1)) - { - RegionSettings settings = this.Scene.RegionInfo.RegionSettings; - client.SendTelehubInfo(settings.TelehubObject, settings.TelehubName, settings.TelehubPos, - settings.TelehubRot, settings.SpawnPoints()); - } + SendTelehubInfo(client); break; default: @@ -1316,5 +1294,39 @@ namespace OpenSim.Region.CoreModules.World.Estate if (onmessage != null) onmessage(Scene.RegionInfo.RegionID, fromID, fromName, message); } + + + private void SendTelehubInfo(IClientAPI client) + { + RegionSettings settings = + this.Scene.RegionInfo.RegionSettings; + + SceneObjectGroup telehub = null; + if (settings.TelehubObject != UUID.Zero && + (telehub = Scene.GetSceneObjectGroup(settings.TelehubObject)) != null) + { + List spawnPoints = new List(); + + foreach (SpawnPoint sp in settings.SpawnPoints()) + { + spawnPoints.Add(sp.GetLocation(telehub.AbsolutePosition, telehub.GroupRotation)); + } + + client.SendTelehubInfo(settings.TelehubObject, + telehub.Name, + telehub.AbsolutePosition, + telehub.GroupRotation, + spawnPoints); + } + else + { + client.SendTelehubInfo(UUID.Zero, + String.Empty, + Vector3.Zero, + Quaternion.Identity, + new List()); + } + } } } + diff --git a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs index 2d7d0eef90..3eb7efa327 100644 --- a/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs +++ b/OpenSim/Region/CoreModules/World/Estate/TelehubManager.cs @@ -43,102 +43,72 @@ namespace OpenSim.Region.CoreModules.World.Estate } // Connect the Telehub - public bool Connect(SceneObjectPart part) + public bool Connect(SceneObjectGroup grp) { - bool result = false; - - if (m_Scene.RegionInfo.RegionSettings.HasTelehub) - return result; - try { m_Scene.RegionInfo.RegionSettings.ClearSpawnPoints(); - m_Scene.RegionInfo.RegionSettings.TelehubObject = part.UUID; - m_Scene.RegionInfo.RegionSettings.TelehubName = part.Name; - m_Scene.RegionInfo.RegionSettings.TelehubPos = part.AbsolutePosition; - m_Scene.RegionInfo.RegionSettings.TelehubRot = part.GetWorldRotation(); - m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(new Vector3(0.0f,0.0f,0.0f)); - m_Scene.RegionInfo.RegionSettings.HasTelehub = true; + m_Scene.RegionInfo.RegionSettings.TelehubObject = grp.UUID; m_Scene.RegionInfo.RegionSettings.Save(); - - result = true; } catch (Exception ex) { - result = false; + return false; } - return result; + return true; } // Disconnect the Telehub: - public bool DisConnect(SceneObjectPart part) + public bool Disconnect() { - bool result = false; - - if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) - return result; + if (m_Scene.RegionInfo.RegionSettings.TelehubObject == UUID.Zero) + return false; try { m_Scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero; - m_Scene.RegionInfo.RegionSettings.TelehubName = String.Empty; - m_Scene.RegionInfo.RegionSettings.TelehubPos = Vector3.Zero; m_Scene.RegionInfo.RegionSettings.ClearSpawnPoints(); - m_Scene.RegionInfo.RegionSettings.HasTelehub = false; m_Scene.RegionInfo.RegionSettings.Save(); - - result = true; } catch (Exception ex) { - result = false; + return false; } - return result; + return true; } // Add a SpawnPoint to the Telehub public bool AddSpawnPoint(Vector3 point) { - bool result = false; + if (m_Scene.RegionInfo.RegionSettings.TelehubObject == UUID.Zero) + return false; - if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) - return result; + SceneObjectGroup grp = m_Scene.GetSceneObjectGroup(m_Scene.RegionInfo.RegionSettings.TelehubObject); + if (grp == null) + return false; try { - // Need to update the position in case the Telehubn has been moved - UUID TelehubID = m_Scene.RegionInfo.RegionSettings.TelehubObject; - SceneObjectPart part = m_Scene.GetSceneObjectPart(TelehubID); - - Vector3 TelehubPos = part.AbsolutePosition; - Quaternion TelehubRot = part.GetWorldRotation(); - - m_Scene.RegionInfo.RegionSettings.TelehubPos = TelehubPos; - m_Scene.RegionInfo.RegionSettings.TelehubRot = TelehubRot; - - float dist = (float) Util.GetDistanceTo(TelehubPos, point); - Vector3 nvec = Util.GetNormalizedVector(point - TelehubPos); - Vector3 spoint = nvec * dist; - - m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(spoint); + SpawnPoint sp = new SpawnPoint(); + sp.SetLocation(grp.AbsolutePosition, grp.GroupRotation, point); + m_Scene.RegionInfo.RegionSettings.AddSpawnPoint(sp); m_Scene.RegionInfo.RegionSettings.Save(); - result = true; } catch (Exception ex) { - result = false; + return false; } - return result; + return true; } // Remove a SpawnPoint from the Telehub public bool RemoveSpawnPoint(int spawnpoint) { - if (!m_Scene.RegionInfo.RegionSettings.HasTelehub) + if (m_Scene.RegionInfo.RegionSettings.TelehubObject == UUID.Zero) return false; m_Scene.RegionInfo.RegionSettings.RemoveSpawnPoint(spawnpoint);