diff options
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteSimulationData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteSimulationData.cs | 183 |
1 files changed, 111 insertions, 72 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs index 29cac3c..6ed3d40 100644 --- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs +++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs | |||
@@ -51,6 +51,7 @@ namespace OpenSim.Data.SQLite | |||
51 | public class SQLiteSimulationData : ISimulationDataStore | 51 | public class SQLiteSimulationData : ISimulationDataStore |
52 | { | 52 | { |
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | private static readonly string LogHeader = "[REGION DB SQLITE]"; | ||
54 | 55 | ||
55 | private const string primSelect = "select * from prims"; | 56 | private const string primSelect = "select * from prims"; |
56 | private const string shapeSelect = "select * from primshapes"; | 57 | private const string shapeSelect = "select * from primshapes"; |
@@ -732,9 +733,12 @@ namespace OpenSim.Data.SQLite | |||
732 | } | 733 | } |
733 | 734 | ||
734 | SceneObjectGroup group = new SceneObjectGroup(prim); | 735 | SceneObjectGroup group = new SceneObjectGroup(prim); |
736 | |||
735 | createdObjects.Add(group.UUID, group); | 737 | createdObjects.Add(group.UUID, group); |
736 | retvals.Add(group); | 738 | retvals.Add(group); |
737 | LoadItems(prim); | 739 | LoadItems(prim); |
740 | |||
741 | |||
738 | } | 742 | } |
739 | } | 743 | } |
740 | catch (Exception e) | 744 | catch (Exception e) |
@@ -816,45 +820,44 @@ namespace OpenSim.Data.SQLite | |||
816 | prim.Inventory.RestoreInventoryItems(inventory); | 820 | prim.Inventory.RestoreInventoryItems(inventory); |
817 | } | 821 | } |
818 | 822 | ||
823 | // Legacy entry point for when terrain was always a 256x256 hieghtmap | ||
824 | public void StoreTerrain(double[,] ter, UUID regionID) | ||
825 | { | ||
826 | StoreTerrain(new HeightmapTerrainData(ter), regionID); | ||
827 | } | ||
828 | |||
819 | /// <summary> | 829 | /// <summary> |
820 | /// Store a terrain revision in region storage | 830 | /// Store a terrain revision in region storage |
821 | /// </summary> | 831 | /// </summary> |
822 | /// <param name="ter">terrain heightfield</param> | 832 | /// <param name="ter">terrain heightfield</param> |
823 | /// <param name="regionID">region UUID</param> | 833 | /// <param name="regionID">region UUID</param> |
824 | public void StoreTerrain(double[,] ter, UUID regionID) | 834 | public void StoreTerrain(TerrainData terrData, UUID regionID) |
825 | { | 835 | { |
826 | lock (ds) | 836 | lock (ds) |
827 | { | 837 | { |
828 | int revision = Util.UnixTimeSinceEpoch(); | ||
829 | |||
830 | // This is added to get rid of the infinitely growing | ||
831 | // terrain databases which negatively impact on SQLite | ||
832 | // over time. Before reenabling this feature there | ||
833 | // needs to be a limitter put on the number of | ||
834 | // revisions in the database, as this old | ||
835 | // implementation is a DOS attack waiting to happen. | ||
836 | |||
837 | using ( | 838 | using ( |
838 | SqliteCommand cmd = | 839 | SqliteCommand cmd = new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID", m_conn)) |
839 | new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision", | ||
840 | m_conn)) | ||
841 | { | 840 | { |
842 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | 841 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); |
843 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | ||
844 | cmd.ExecuteNonQuery(); | 842 | cmd.ExecuteNonQuery(); |
845 | } | 843 | } |
846 | 844 | ||
847 | // the following is an work around for .NET. The perf | 845 | // the following is an work around for .NET. The perf |
848 | // issues associated with it aren't as bad as you think. | 846 | // issues associated with it aren't as bad as you think. |
849 | m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString()); | ||
850 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + | 847 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + |
851 | " values(:RegionUUID, :Revision, :Heightfield)"; | 848 | " values(:RegionUUID, :Revision, :Heightfield)"; |
852 | 849 | ||
850 | int terrainDBRevision; | ||
851 | Array terrainDBblob; | ||
852 | terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); | ||
853 | |||
854 | m_log.DebugFormat("{0} Storing terrain revision r {1}", LogHeader, terrainDBRevision); | ||
855 | |||
853 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) | 856 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) |
854 | { | 857 | { |
855 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | 858 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); |
856 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | 859 | cmd.Parameters.Add(new SqliteParameter(":Revision", terrainDBRevision)); |
857 | cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); | 860 | cmd.Parameters.Add(new SqliteParameter(":Heightfield", terrainDBblob)); |
858 | cmd.ExecuteNonQuery(); | 861 | cmd.ExecuteNonQuery(); |
859 | } | 862 | } |
860 | } | 863 | } |
@@ -867,11 +870,20 @@ namespace OpenSim.Data.SQLite | |||
867 | /// <returns>Heightfield data</returns> | 870 | /// <returns>Heightfield data</returns> |
868 | public double[,] LoadTerrain(UUID regionID) | 871 | public double[,] LoadTerrain(UUID regionID) |
869 | { | 872 | { |
873 | double[,] ret = null; | ||
874 | TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); | ||
875 | if (terrData != null) | ||
876 | ret = terrData.GetDoubles(); | ||
877 | return ret; | ||
878 | } | ||
879 | |||
880 | // Returns 'null' if region not found | ||
881 | public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) | ||
882 | { | ||
883 | TerrainData terrData = null; | ||
884 | |||
870 | lock (ds) | 885 | lock (ds) |
871 | { | 886 | { |
872 | double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; | ||
873 | terret.Initialize(); | ||
874 | |||
875 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + | 887 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + |
876 | " where RegionUUID=:RegionUUID order by Revision desc"; | 888 | " where RegionUUID=:RegionUUID order by Revision desc"; |
877 | 889 | ||
@@ -884,21 +896,9 @@ namespace OpenSim.Data.SQLite | |||
884 | int rev = 0; | 896 | int rev = 0; |
885 | if (row.Read()) | 897 | if (row.Read()) |
886 | { | 898 | { |
887 | // TODO: put this into a function | ||
888 | using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"])) | ||
889 | { | ||
890 | using (BinaryReader br = new BinaryReader(str)) | ||
891 | { | ||
892 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
893 | { | ||
894 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
895 | { | ||
896 | terret[x, y] = br.ReadDouble(); | ||
897 | } | ||
898 | } | ||
899 | } | ||
900 | } | ||
901 | rev = Convert.ToInt32(row["Revision"]); | 899 | rev = Convert.ToInt32(row["Revision"]); |
900 | byte[] blob = (byte[])row["Heightfield"]; | ||
901 | terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); | ||
902 | } | 902 | } |
903 | else | 903 | else |
904 | { | 904 | { |
@@ -909,8 +909,8 @@ namespace OpenSim.Data.SQLite | |||
909 | m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); | 909 | m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString()); |
910 | } | 910 | } |
911 | } | 911 | } |
912 | return terret; | ||
913 | } | 912 | } |
913 | return terrData; | ||
914 | } | 914 | } |
915 | 915 | ||
916 | public void RemoveLandObject(UUID globalID) | 916 | public void RemoveLandObject(UUID globalID) |
@@ -1232,7 +1232,20 @@ namespace OpenSim.Data.SQLite | |||
1232 | createCol(prims, "VolumeDetect", typeof(Int16)); | 1232 | createCol(prims, "VolumeDetect", typeof(Int16)); |
1233 | 1233 | ||
1234 | createCol(prims, "MediaURL", typeof(String)); | 1234 | createCol(prims, "MediaURL", typeof(String)); |
1235 | |||
1236 | createCol(prims, "AttachedPosX", typeof(Double)); | ||
1237 | createCol(prims, "AttachedPosY", typeof(Double)); | ||
1238 | createCol(prims, "AttachedPosZ", typeof(Double)); | ||
1239 | |||
1240 | createCol(prims, "DynAttrs", typeof(String)); | ||
1241 | |||
1242 | createCol(prims, "PhysicsShapeType", typeof(Byte)); | ||
1243 | createCol(prims, "Density", typeof(Double)); | ||
1244 | createCol(prims, "GravityModifier", typeof(Double)); | ||
1245 | createCol(prims, "Friction", typeof(Double)); | ||
1246 | createCol(prims, "Restitution", typeof(Double)); | ||
1235 | 1247 | ||
1248 | createCol(prims, "KeyframeMotion", typeof(Byte[])); | ||
1236 | // Add in contraints | 1249 | // Add in contraints |
1237 | prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; | 1250 | prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; |
1238 | 1251 | ||
@@ -1592,7 +1605,7 @@ namespace OpenSim.Data.SQLite | |||
1592 | prim.SitName = (String)row["SitName"]; | 1605 | prim.SitName = (String)row["SitName"]; |
1593 | prim.TouchName = (String)row["TouchName"]; | 1606 | prim.TouchName = (String)row["TouchName"]; |
1594 | // permissions | 1607 | // permissions |
1595 | prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]); | 1608 | prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]); |
1596 | prim.CreatorIdentification = (String)row["CreatorID"]; | 1609 | prim.CreatorIdentification = (String)row["CreatorID"]; |
1597 | prim.OwnerID = new UUID((String)row["OwnerID"]); | 1610 | prim.OwnerID = new UUID((String)row["OwnerID"]); |
1598 | prim.GroupID = new UUID((String)row["GroupID"]); | 1611 | prim.GroupID = new UUID((String)row["GroupID"]); |
@@ -1711,7 +1724,43 @@ namespace OpenSim.Data.SQLite | |||
1711 | // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType()); | 1724 | // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType()); |
1712 | prim.MediaUrl = (string)row["MediaURL"]; | 1725 | prim.MediaUrl = (string)row["MediaURL"]; |
1713 | } | 1726 | } |
1727 | |||
1728 | prim.AttachedPos = new Vector3( | ||
1729 | Convert.ToSingle(row["AttachedPosX"]), | ||
1730 | Convert.ToSingle(row["AttachedPosY"]), | ||
1731 | Convert.ToSingle(row["AttachedPosZ"]) | ||
1732 | ); | ||
1733 | |||
1734 | if (!(row["DynAttrs"] is System.DBNull)) | ||
1735 | { | ||
1736 | //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType()); | ||
1737 | prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]); | ||
1738 | } | ||
1739 | else | ||
1740 | { | ||
1741 | prim.DynAttrs = new DAMap(); | ||
1742 | } | ||
1743 | |||
1744 | prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]); | ||
1745 | prim.Density = Convert.ToSingle(row["Density"]); | ||
1746 | prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]); | ||
1747 | prim.Friction = Convert.ToSingle(row["Friction"]); | ||
1748 | prim.Restitution = Convert.ToSingle(row["Restitution"]); | ||
1714 | 1749 | ||
1750 | |||
1751 | if (!(row["KeyframeMotion"] is DBNull)) | ||
1752 | { | ||
1753 | Byte[] data = (byte[])row["KeyframeMotion"]; | ||
1754 | if (data.Length > 0) | ||
1755 | prim.KeyframeMotion = KeyframeMotion.FromData(null, data); | ||
1756 | else | ||
1757 | prim.KeyframeMotion = null; | ||
1758 | } | ||
1759 | else | ||
1760 | { | ||
1761 | prim.KeyframeMotion = null; | ||
1762 | } | ||
1763 | |||
1715 | return prim; | 1764 | return prim; |
1716 | } | 1765 | } |
1717 | 1766 | ||
@@ -1967,40 +2016,6 @@ namespace OpenSim.Data.SQLite | |||
1967 | /// <summary> | 2016 | /// <summary> |
1968 | /// | 2017 | /// |
1969 | /// </summary> | 2018 | /// </summary> |
1970 | /// <param name="val"></param> | ||
1971 | /// <returns></returns> | ||
1972 | private static Array serializeTerrain(double[,] val) | ||
1973 | { | ||
1974 | MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double)); | ||
1975 | BinaryWriter bw = new BinaryWriter(str); | ||
1976 | |||
1977 | // TODO: COMPATIBILITY - Add byte-order conversions | ||
1978 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1979 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1980 | bw.Write(val[x, y]); | ||
1981 | |||
1982 | return str.ToArray(); | ||
1983 | } | ||
1984 | |||
1985 | // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) | ||
1986 | // { | ||
1987 | // row["RegionUUID"] = regionUUID; | ||
1988 | // row["Revision"] = rev; | ||
1989 | |||
1990 | // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double)); | ||
1991 | // BinaryWriter bw = new BinaryWriter(str); | ||
1992 | |||
1993 | // // TODO: COMPATIBILITY - Add byte-order conversions | ||
1994 | // for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1995 | // for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1996 | // bw.Write(val[x, y]); | ||
1997 | |||
1998 | // row["Heightfield"] = str.ToArray(); | ||
1999 | // } | ||
2000 | |||
2001 | /// <summary> | ||
2002 | /// | ||
2003 | /// </summary> | ||
2004 | /// <param name="row"></param> | 2019 | /// <param name="row"></param> |
2005 | /// <param name="prim"></param> | 2020 | /// <param name="prim"></param> |
2006 | /// <param name="sceneGroupID"></param> | 2021 | /// <param name="sceneGroupID"></param> |
@@ -2019,7 +2034,7 @@ namespace OpenSim.Data.SQLite | |||
2019 | row["SitName"] = prim.SitName; | 2034 | row["SitName"] = prim.SitName; |
2020 | row["TouchName"] = prim.TouchName; | 2035 | row["TouchName"] = prim.TouchName; |
2021 | // permissions | 2036 | // permissions |
2022 | row["ObjectFlags"] = prim.ObjectFlags; | 2037 | row["ObjectFlags"] = (uint)prim.Flags; |
2023 | row["CreatorID"] = prim.CreatorIdentification.ToString(); | 2038 | row["CreatorID"] = prim.CreatorIdentification.ToString(); |
2024 | row["OwnerID"] = prim.OwnerID.ToString(); | 2039 | row["OwnerID"] = prim.OwnerID.ToString(); |
2025 | row["GroupID"] = prim.GroupID.ToString(); | 2040 | row["GroupID"] = prim.GroupID.ToString(); |
@@ -2133,6 +2148,28 @@ namespace OpenSim.Data.SQLite | |||
2133 | row["VolumeDetect"] = 0; | 2148 | row["VolumeDetect"] = 0; |
2134 | 2149 | ||
2135 | row["MediaURL"] = prim.MediaUrl; | 2150 | row["MediaURL"] = prim.MediaUrl; |
2151 | |||
2152 | row["AttachedPosX"] = prim.AttachedPos.X; | ||
2153 | row["AttachedPosY"] = prim.AttachedPos.Y; | ||
2154 | row["AttachedPosZ"] = prim.AttachedPos.Z; | ||
2155 | |||
2156 | if (prim.DynAttrs.CountNamespaces > 0) | ||
2157 | row["DynAttrs"] = prim.DynAttrs.ToXml(); | ||
2158 | else | ||
2159 | row["DynAttrs"] = null; | ||
2160 | |||
2161 | row["PhysicsShapeType"] = prim.PhysicsShapeType; | ||
2162 | row["Density"] = (double)prim.Density; | ||
2163 | row["GravityModifier"] = (double)prim.GravityModifier; | ||
2164 | row["Friction"] = (double)prim.Friction; | ||
2165 | row["Restitution"] = (double)prim.Restitution; | ||
2166 | |||
2167 | if (prim.KeyframeMotion != null) | ||
2168 | row["KeyframeMotion"] = prim.KeyframeMotion.Serialize(); | ||
2169 | else | ||
2170 | row["KeyframeMotion"] = new Byte[0]; | ||
2171 | |||
2172 | |||
2136 | } | 2173 | } |
2137 | 2174 | ||
2138 | /// <summary> | 2175 | /// <summary> |
@@ -2384,6 +2421,7 @@ namespace OpenSim.Data.SQLite | |||
2384 | s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]); | 2421 | s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]); |
2385 | s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]); | 2422 | s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]); |
2386 | s.State = Convert.ToByte(row["State"]); | 2423 | s.State = Convert.ToByte(row["State"]); |
2424 | s.LastAttachPoint = Convert.ToByte(row["LastAttachPoint"]); | ||
2387 | 2425 | ||
2388 | byte[] textureEntry = (byte[])row["Texture"]; | 2426 | byte[] textureEntry = (byte[])row["Texture"]; |
2389 | s.TextureEntry = textureEntry; | 2427 | s.TextureEntry = textureEntry; |
@@ -2392,7 +2430,7 @@ namespace OpenSim.Data.SQLite | |||
2392 | 2430 | ||
2393 | if (!(row["Media"] is System.DBNull)) | 2431 | if (!(row["Media"] is System.DBNull)) |
2394 | s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]); | 2432 | s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]); |
2395 | 2433 | ||
2396 | return s; | 2434 | return s; |
2397 | } | 2435 | } |
2398 | 2436 | ||
@@ -2433,6 +2471,7 @@ namespace OpenSim.Data.SQLite | |||
2433 | row["ProfileCurve"] = s.ProfileCurve; | 2471 | row["ProfileCurve"] = s.ProfileCurve; |
2434 | row["ProfileHollow"] = s.ProfileHollow; | 2472 | row["ProfileHollow"] = s.ProfileHollow; |
2435 | row["State"] = s.State; | 2473 | row["State"] = s.State; |
2474 | row["LastAttachPoint"] = s.LastAttachPoint; | ||
2436 | 2475 | ||
2437 | row["Texture"] = s.TextureEntry; | 2476 | row["Texture"] = s.TextureEntry; |
2438 | row["ExtraParams"] = s.ExtraParams; | 2477 | row["ExtraParams"] = s.ExtraParams; |