From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001
From: David Walter Seikel
Date: Thu, 3 Nov 2016 21:44:39 +1000
Subject: Initial update to OpenSim 0.8.2.1 source code.

---
 OpenSim/Data/MySQL/MySQLSimulationData.cs | 805 ++++++++++++++++--------------
 1 file changed, 420 insertions(+), 385 deletions(-)

(limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs')

diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
index d562783..bb0ab75 100644
--- a/OpenSim/Data/MySQL/MySQLSimulationData.cs
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -48,8 +48,18 @@ namespace OpenSim.Data.MySQL
     public class MySQLSimulationData : ISimulationDataStore
     {
         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
+        private static string LogHeader = "[REGION DB MYSQL]";
 
         private string m_connectionString;
+
+        /// <summary>
+        /// This lock was being used to serialize database operations when the connection was shared, but this has
+        /// been unnecessary for a long time after we switched to using MySQL's underlying connection pooling instead.
+        /// FIXME: However, the locks remain in many places since they are effectively providing a level of 
+        /// transactionality.  This should be replaced by more efficient database transactions which would not require
+        /// unrelated operations to block each other or unrelated operations on the same tables from blocking each
+        /// other.
+        /// </summary>
         private object m_dbLock = new object();
 
         protected virtual Assembly Assembly
@@ -91,7 +101,7 @@ namespace OpenSim.Data.MySQL
             }
             catch (Exception e)
             {
-                m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message);
+                m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e);
                 throw;
             }
 
@@ -119,8 +129,10 @@ namespace OpenSim.Data.MySQL
 
             // Eligibility check
             //
-            if ((flags & (uint)PrimFlags.Temporary) != 0)
-                return;
+            // PrimFlags.Temporary is not used in OpenSim code and cannot
+            // be guaranteed to always be clear. Don't check it.
+//            if ((flags & (uint)PrimFlags.Temporary) != 0)
+//                return;
             if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
                 return;
 
@@ -135,7 +147,7 @@ namespace OpenSim.Data.MySQL
                         foreach (SceneObjectPart prim in obj.Parts)
                         {
                             cmd.Parameters.Clear();
-    
+
                             cmd.CommandText = "replace into prims (" +
                                     "UUID, CreationDate, " +
                                     "Name, Text, Description, " +
@@ -171,7 +183,11 @@ namespace OpenSim.Data.MySQL
                                     "ParticleSystem, ClickAction, Material, " +
                                     "CollisionSound, CollisionSoundVolume, " +
                                     "PassTouches, " +
-                                    "LinkNumber, MediaURL) values (" + "?UUID, " +
+                                    "LinkNumber, MediaURL, AttachedPosX, " +
+				    "AttachedPosY, AttachedPosZ, KeyframeMotion, " +
+                                    "PhysicsShapeType, Density, GravityModifier, " +
+                                    "Friction, Restitution, DynAttrs " +
+                                    ") values (" + "?UUID, " +
                                     "?CreationDate, ?Name, ?Text, " +
                                     "?Description, ?SitName, ?TouchName, " +
                                     "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
@@ -202,14 +218,18 @@ namespace OpenSim.Data.MySQL
                                     "?SaleType, ?ColorR, ?ColorG, " +
                                     "?ColorB, ?ColorA, ?ParticleSystem, " +
                                     "?ClickAction, ?Material, ?CollisionSound, " +
-                                    "?CollisionSoundVolume, ?PassTouches, ?LinkNumber, ?MediaURL)";
-    
+                                    "?CollisionSoundVolume, ?PassTouches, " +
+                                    "?LinkNumber, ?MediaURL, ?AttachedPosX, " +
+				    "?AttachedPosY, ?AttachedPosZ, ?KeyframeMotion, " +
+                                    "?PhysicsShapeType, ?Density, ?GravityModifier, " +
+                                    "?Friction, ?Restitution, ?DynAttrs)";
+
                             FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
-    
+
                             ExecuteNonQuery(cmd);
-    
+
                             cmd.Parameters.Clear();
-    
+
                             cmd.CommandText = "replace into primshapes (" +
                                     "UUID, Shape, ScaleX, ScaleY, " +
                                     "ScaleZ, PCode, PathBegin, PathEnd, " +
@@ -219,7 +239,8 @@ namespace OpenSim.Data.MySQL
                                     "PathTaperX, PathTaperY, PathTwist, " +
                                     "PathTwistBegin, ProfileBegin, ProfileEnd, " +
                                     "ProfileCurve, ProfileHollow, Texture, " +
-                                    "ExtraParams, State, Media) values (?UUID, " +
+                                    "ExtraParams, State, LastAttachPoint, Media) " +
+                                    "values (?UUID, " +
                                     "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
                                     "?PCode, ?PathBegin, ?PathEnd, " +
                                     "?PathScaleX, ?PathScaleY, " +
@@ -230,10 +251,10 @@ namespace OpenSim.Data.MySQL
                                     "?PathTwistBegin, ?ProfileBegin, " +
                                     "?ProfileEnd, ?ProfileCurve, " +
                                     "?ProfileHollow, ?Texture, ?ExtraParams, " +
-                                    "?State, ?Media)";
-    
+                                    "?State, ?LastAttachPoint, ?Media)";
+
                             FillShapeCommand(cmd, prim);
-    
+
                             ExecuteNonQuery(cmd);
                         }
                     }
@@ -446,7 +467,9 @@ namespace OpenSim.Data.MySQL
             foreach (SceneObjectPart prim in prims.Values)
             {
                 if (prim.ParentUUID == UUID.Zero)
+                {
                     objects[prim.UUID] = new SceneObjectGroup(prim);
+                }
             }
 
             // Add all of the children objects to the SOGs
@@ -559,10 +582,14 @@ namespace OpenSim.Data.MySQL
             }
         }
 
+        // Legacy entry point for when terrain was always a 256x256 hieghtmap
         public void StoreTerrain(double[,] ter, UUID regionID)
         {
-            m_log.Info("[REGION DB]: Storing terrain");
+            StoreTerrain(new HeightmapTerrainData(ter), regionID);
+        }
 
+        public void StoreTerrain(TerrainData terrData, UUID regionID)
+        {
             lock (m_dbLock)
             {
                 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
@@ -576,11 +603,18 @@ namespace OpenSim.Data.MySQL
 
                         ExecuteNonQuery(cmd);
 
-                        cmd.CommandText = "insert into terrain (RegionUUID, " +
-                            "Revision, Heightfield) values (?RegionUUID, " +
-                            "1, ?Heightfield)";
+                        int terrainDBRevision;
+                        Array terrainDBblob;
+                        terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
+
+                        m_log.InfoFormat("{0} Storing terrain. X={1}, Y={2}, rev={3}",
+                                    LogHeader, terrData.SizeX, terrData.SizeY, terrainDBRevision);
 
-                        cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
+                        cmd.CommandText = "insert into terrain (RegionUUID, Revision, Heightfield)"
+                        +   "values (?RegionUUID, ?Revision, ?Heightfield)";
+
+                        cmd.Parameters.AddWithValue("Revision", terrainDBRevision);
+                        cmd.Parameters.AddWithValue("Heightfield", terrainDBblob);
 
                         ExecuteNonQuery(cmd);
                     }
@@ -588,9 +622,20 @@ namespace OpenSim.Data.MySQL
             }
         }
 
+        // Legacy region loading
         public double[,] LoadTerrain(UUID regionID)
         {
-            double[,] terrain = null;
+            double[,] ret = null;
+            TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
+            if (terrData != null)
+                ret = terrData.GetDoubles();
+            return ret;
+        }
+
+        // Returns 'null' if region not found
+        public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
+        {
+            TerrainData terrData = null;
 
             lock (m_dbLock)
             {
@@ -610,32 +655,15 @@ namespace OpenSim.Data.MySQL
                             while (reader.Read())
                             {
                                 int rev = Convert.ToInt32(reader["Revision"]);
-
-                                terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
-                                terrain.Initialize();
-
-                                using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
-                                {
-                                    using (BinaryReader br = new BinaryReader(mstr))
-                                    {
-                                        for (int x = 0; x < (int)Constants.RegionSize; x++)
-                                        {
-                                            for (int y = 0; y < (int)Constants.RegionSize; y++)
-                                            {
-                                                terrain[x, y] = br.ReadDouble();
-                                            }
-                                        }
-                                    }
-
-                                    m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
-                                }
+                                byte[] blob = (byte[])reader["Heightfield"];
+                                terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
                             }
                         }
                     }
                 }
             }
 
-            return terrain;
+            return terrData;
         }
 
         public void RemoveLandObject(UUID globalID)
@@ -676,7 +704,7 @@ namespace OpenSim.Data.MySQL
                             "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
                             "UserLocationX, UserLocationY, UserLocationZ, " +
                             "UserLookAtX, UserLookAtY, UserLookAtZ, " +
-                            "AuthbuyerID, OtherCleanTime, MediaType, MediaDescription, " +
+                            "AuthbuyerID, OtherCleanTime, Dwell, MediaType, MediaDescription, " +
                             "MediaSize, MediaLoop, ObscureMusic, ObscureMedia) values (" +
                             "?UUID, ?RegionUUID, " +
                             "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
@@ -687,7 +715,7 @@ namespace OpenSim.Data.MySQL
                             "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
                             "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
                             "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
-                            "?AuthbuyerID, ?OtherCleanTime, ?MediaType, ?MediaDescription, "+
+                            "?AuthbuyerID, ?OtherCleanTime, ?Dwell, ?MediaType, ?MediaDescription, "+
                             "CONCAT(?MediaWidth, ',', ?MediaHeight), ?MediaLoop, ?ObscureMusic, ?ObscureMedia)";
 
                         FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
@@ -719,95 +747,92 @@ namespace OpenSim.Data.MySQL
             RegionLightShareData nWP = new RegionLightShareData();
             nWP.OnSave += StoreRegionWindlightSettings;
 
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                string command = "select * from `regionwindlight` where region_id = ?regionID";
+
+                using (MySqlCommand cmd = new MySqlCommand(command))
                 {
-                    dbcon.Open();
-    
-                    string command = "select * from `regionwindlight` where region_id = ?regionID";
-    
-                    using (MySqlCommand cmd = new MySqlCommand(command))
+                    cmd.Connection = dbcon;
+
+                    cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString());
+
+                    IDataReader result = ExecuteReader(cmd);
+                    if (!result.Read())
                     {
-                        cmd.Connection = dbcon;
-    
-                        cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString());
-    
-                        IDataReader result = ExecuteReader(cmd);
-                        if (!result.Read())
-                        {
-                            //No result, so store our default windlight profile and return it
-                            nWP.regionID = regionUUID;
-                            StoreRegionWindlightSettings(nWP);
-                            return nWP;
-                        }
-                        else
-                        {
-                            nWP.regionID = DBGuid.FromDB(result["region_id"]);
-                            nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
-                            nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
-                            nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
-                            nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
-                            nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
-                            nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
-                            nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
-                            nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
-                            nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
-                            nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
-                            nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
-                            nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
-                            nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
-                            nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
-                            nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
-                            nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
-                            nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
-                            UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
-                            nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
-                            nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
-                            nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
-                            nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
-                            nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
-                            nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
-                            nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
-                            nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
-                            nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
-                            nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
-                            nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
-                            nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
-                            nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
-                            nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
-                            nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
-                            nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
-                            nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
-                            nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
-                            nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
-                            nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
-                            nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
-                            nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
-                            nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
-                            nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
-                            nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
-                            nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
-                            nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
-                            nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
-                            nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
-                            nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
-                            nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
-                            nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
-                            nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
-                            nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
-                            nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
-                            nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
-                            nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
-                            nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
-                            nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
-                            nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
-                            nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
-                            nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
-                            nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
-                            nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
-                            nWP.valid = true;
-                        }
+                        //No result, so store our default windlight profile and return it
+                        nWP.regionID = regionUUID;
+//                            StoreRegionWindlightSettings(nWP);
+                        return nWP;
+                    }
+                    else
+                    {
+                        nWP.regionID = DBGuid.FromDB(result["region_id"]);
+                        nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
+                        nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
+                        nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
+                        nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
+                        nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
+                        nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
+                        nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
+                        nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
+                        nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
+                        nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
+                        nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
+                        nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
+                        nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
+                        nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
+                        nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
+                        nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
+                        nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
+                        UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
+                        nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
+                        nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
+                        nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
+                        nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
+                        nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
+                        nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
+                        nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
+                        nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
+                        nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
+                        nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
+                        nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
+                        nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
+                        nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
+                        nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
+                        nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
+                        nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
+                        nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
+                        nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
+                        nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
+                        nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
+                        nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
+                        nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
+                        nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
+                        nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
+                        nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
+                        nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
+                        nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
+                        nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
+                        nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
+                        nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
+                        nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
+                        nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
+                        nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
+                        nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
+                        nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
+                        nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
+                        nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
+                        nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
+                        nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
+                        nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
+                        nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
+                        nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
+                        nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
+                        nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
+                        nWP.valid = true;
                     }
                 }
             }
@@ -857,124 +882,118 @@ namespace OpenSim.Data.MySQL
 
         public void StoreRegionWindlightSettings(RegionLightShareData wl)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                using (MySqlCommand cmd = dbcon.CreateCommand())
                 {
-                    dbcon.Open();
-    
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, ";
-                        cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, ";
-                        cmd.CommandText += "`reflection_wavelet_scale_1`, `reflection_wavelet_scale_2`, `reflection_wavelet_scale_3`, ";
-                        cmd.CommandText += "`fresnel_scale`, `fresnel_offset`, `refract_scale_above`, `refract_scale_below`, ";
-                        cmd.CommandText += "`blur_multiplier`, `big_wave_direction_x`, `big_wave_direction_y`, `little_wave_direction_x`, ";
-                        cmd.CommandText += "`little_wave_direction_y`, `normal_map_texture`, `horizon_r`, `horizon_g`, `horizon_b`, ";
-                        cmd.CommandText += "`horizon_i`, `haze_horizon`, `blue_density_r`, `blue_density_g`, `blue_density_b`, ";
-                        cmd.CommandText += "`blue_density_i`, `haze_density`, `density_multiplier`, `distance_multiplier`, `max_altitude`, ";
-                        cmd.CommandText += "`sun_moon_color_r`, `sun_moon_color_g`, `sun_moon_color_b`, `sun_moon_color_i`, `sun_moon_position`, ";
-                        cmd.CommandText += "`ambient_r`, `ambient_g`, `ambient_b`, `ambient_i`, `east_angle`, `sun_glow_focus`, `sun_glow_size`, ";
-                        cmd.CommandText += "`scene_gamma`, `star_brightness`, `cloud_color_r`, `cloud_color_g`, `cloud_color_b`, `cloud_color_i`, ";
-                        cmd.CommandText += "`cloud_x`, `cloud_y`, `cloud_density`, `cloud_coverage`, `cloud_scale`, `cloud_detail_x`, ";
-                        cmd.CommandText += "`cloud_detail_y`, `cloud_detail_density`, `cloud_scroll_x`, `cloud_scroll_x_lock`, `cloud_scroll_y`, ";
-                        cmd.CommandText += "`cloud_scroll_y_lock`, `draw_classic_clouds`) VALUES (?region_id, ?water_color_r, ";
-                        cmd.CommandText += "?water_color_g, ?water_color_b, ?water_fog_density_exponent, ?underwater_fog_modifier, ?reflection_wavelet_scale_1, ";
-                        cmd.CommandText += "?reflection_wavelet_scale_2, ?reflection_wavelet_scale_3, ?fresnel_scale, ?fresnel_offset, ?refract_scale_above, ";
-                        cmd.CommandText += "?refract_scale_below, ?blur_multiplier, ?big_wave_direction_x, ?big_wave_direction_y, ?little_wave_direction_x, ";
-                        cmd.CommandText += "?little_wave_direction_y, ?normal_map_texture, ?horizon_r, ?horizon_g, ?horizon_b, ?horizon_i, ?haze_horizon, ";
-                        cmd.CommandText += "?blue_density_r, ?blue_density_g, ?blue_density_b, ?blue_density_i, ?haze_density, ?density_multiplier, ";
-                        cmd.CommandText += "?distance_multiplier, ?max_altitude, ?sun_moon_color_r, ?sun_moon_color_g, ?sun_moon_color_b, ";
-                        cmd.CommandText += "?sun_moon_color_i, ?sun_moon_position, ?ambient_r, ?ambient_g, ?ambient_b, ?ambient_i, ?east_angle, ";
-                        cmd.CommandText += "?sun_glow_focus, ?sun_glow_size, ?scene_gamma, ?star_brightness, ?cloud_color_r, ?cloud_color_g, ";
-                        cmd.CommandText += "?cloud_color_b, ?cloud_color_i, ?cloud_x, ?cloud_y, ?cloud_density, ?cloud_coverage, ?cloud_scale, ";
-                        cmd.CommandText += "?cloud_detail_x, ?cloud_detail_y, ?cloud_detail_density, ?cloud_scroll_x, ?cloud_scroll_x_lock, ";
-                        cmd.CommandText += "?cloud_scroll_y, ?cloud_scroll_y_lock, ?draw_classic_clouds)";
-    
-                        cmd.Parameters.AddWithValue("region_id", wl.regionID);
-                        cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
-                        cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
-                        cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
-                        cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
-                        cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
-                        cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
-                        cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
-                        cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
-                        cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
-                        cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
-                        cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
-                        cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
-                        cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
-                        cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
-                        cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
-                        cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
-                        cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
-                        cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
-                        cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
-                        cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
-                        cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
-                        cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
-                        cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
-                        cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
-                        cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
-                        cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
-                        cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
-                        cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
-                        cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
-                        cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
-                        cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
-                        cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
-                        cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
-                        cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
-                        cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
-                        cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
-                        cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
-                        cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
-                        cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
-                        cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
-                        cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
-                        cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
-                        cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
-                        cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
-                        cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
-                        cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
-                        cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
-                        cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
-                        cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
-                        cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
-                        cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
-                        cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
-                        cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
-                        cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
-                        cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
-                        cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
-                        cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
-                        cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
-                        cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
-                        cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
-                        cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
-                        cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
-                        
-                        ExecuteNonQuery(cmd);
-                    }
+                    cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, ";
+                    cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, ";
+                    cmd.CommandText += "`reflection_wavelet_scale_1`, `reflection_wavelet_scale_2`, `reflection_wavelet_scale_3`, ";
+                    cmd.CommandText += "`fresnel_scale`, `fresnel_offset`, `refract_scale_above`, `refract_scale_below`, ";
+                    cmd.CommandText += "`blur_multiplier`, `big_wave_direction_x`, `big_wave_direction_y`, `little_wave_direction_x`, ";
+                    cmd.CommandText += "`little_wave_direction_y`, `normal_map_texture`, `horizon_r`, `horizon_g`, `horizon_b`, ";
+                    cmd.CommandText += "`horizon_i`, `haze_horizon`, `blue_density_r`, `blue_density_g`, `blue_density_b`, ";
+                    cmd.CommandText += "`blue_density_i`, `haze_density`, `density_multiplier`, `distance_multiplier`, `max_altitude`, ";
+                    cmd.CommandText += "`sun_moon_color_r`, `sun_moon_color_g`, `sun_moon_color_b`, `sun_moon_color_i`, `sun_moon_position`, ";
+                    cmd.CommandText += "`ambient_r`, `ambient_g`, `ambient_b`, `ambient_i`, `east_angle`, `sun_glow_focus`, `sun_glow_size`, ";
+                    cmd.CommandText += "`scene_gamma`, `star_brightness`, `cloud_color_r`, `cloud_color_g`, `cloud_color_b`, `cloud_color_i`, ";
+                    cmd.CommandText += "`cloud_x`, `cloud_y`, `cloud_density`, `cloud_coverage`, `cloud_scale`, `cloud_detail_x`, ";
+                    cmd.CommandText += "`cloud_detail_y`, `cloud_detail_density`, `cloud_scroll_x`, `cloud_scroll_x_lock`, `cloud_scroll_y`, ";
+                    cmd.CommandText += "`cloud_scroll_y_lock`, `draw_classic_clouds`) VALUES (?region_id, ?water_color_r, ";
+                    cmd.CommandText += "?water_color_g, ?water_color_b, ?water_fog_density_exponent, ?underwater_fog_modifier, ?reflection_wavelet_scale_1, ";
+                    cmd.CommandText += "?reflection_wavelet_scale_2, ?reflection_wavelet_scale_3, ?fresnel_scale, ?fresnel_offset, ?refract_scale_above, ";
+                    cmd.CommandText += "?refract_scale_below, ?blur_multiplier, ?big_wave_direction_x, ?big_wave_direction_y, ?little_wave_direction_x, ";
+                    cmd.CommandText += "?little_wave_direction_y, ?normal_map_texture, ?horizon_r, ?horizon_g, ?horizon_b, ?horizon_i, ?haze_horizon, ";
+                    cmd.CommandText += "?blue_density_r, ?blue_density_g, ?blue_density_b, ?blue_density_i, ?haze_density, ?density_multiplier, ";
+                    cmd.CommandText += "?distance_multiplier, ?max_altitude, ?sun_moon_color_r, ?sun_moon_color_g, ?sun_moon_color_b, ";
+                    cmd.CommandText += "?sun_moon_color_i, ?sun_moon_position, ?ambient_r, ?ambient_g, ?ambient_b, ?ambient_i, ?east_angle, ";
+                    cmd.CommandText += "?sun_glow_focus, ?sun_glow_size, ?scene_gamma, ?star_brightness, ?cloud_color_r, ?cloud_color_g, ";
+                    cmd.CommandText += "?cloud_color_b, ?cloud_color_i, ?cloud_x, ?cloud_y, ?cloud_density, ?cloud_coverage, ?cloud_scale, ";
+                    cmd.CommandText += "?cloud_detail_x, ?cloud_detail_y, ?cloud_detail_density, ?cloud_scroll_x, ?cloud_scroll_x_lock, ";
+                    cmd.CommandText += "?cloud_scroll_y, ?cloud_scroll_y_lock, ?draw_classic_clouds)";
+
+                    cmd.Parameters.AddWithValue("region_id", wl.regionID);
+                    cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
+                    cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
+                    cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
+                    cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
+                    cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
+                    cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
+                    cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
+                    cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
+                    cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
+                    cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
+                    cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
+                    cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
+                    cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
+                    cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
+                    cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
+                    cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
+                    cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
+                    cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
+                    cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
+                    cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
+                    cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
+                    cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
+                    cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
+                    cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
+                    cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
+                    cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
+                    cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
+                    cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
+                    cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
+                    cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
+                    cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
+                    cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
+                    cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
+                    cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
+                    cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
+                    cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
+                    cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
+                    cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
+                    cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
+                    cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
+                    cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
+                    cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
+                    cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
+                    cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
+                    cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
+                    cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
+                    cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
+                    cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
+                    cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
+                    cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
+                    cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
+                    cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
+                    cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
+                    cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
+                    cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
+                    cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
+                    cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
+                    cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
+                    cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
+                    cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
+                    cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
+                    cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
+                    
+                    ExecuteNonQuery(cmd);
                 }
             }
         }
 
         public void RemoveRegionWindlightSettings(UUID regionID)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                using (MySqlCommand cmd = dbcon.CreateCommand())
                 {
-                    dbcon.Open();
-    
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "delete from `regionwindlight` where `region_id`=?regionID";
-                        cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
-                        ExecuteNonQuery(cmd);
-                    }
+                    cmd.CommandText = "delete from `regionwindlight` where `region_id`=?regionID";
+                    cmd.Parameters.AddWithValue("?regionID", regionID.ToString());
+                    ExecuteNonQuery(cmd);
                 }
             }
         }
@@ -982,29 +1001,26 @@ namespace OpenSim.Data.MySQL
         #region RegionEnvironmentSettings
         public string LoadRegionEnvironmentSettings(UUID regionUUID)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                string command = "select * from `regionenvironment` where region_id = ?region_id";
+
+                using (MySqlCommand cmd = new MySqlCommand(command))
                 {
-                    dbcon.Open();
-    
-                    string command = "select * from `regionenvironment` where region_id = ?region_id";
-    
-                    using (MySqlCommand cmd = new MySqlCommand(command))
+                    cmd.Connection = dbcon;
+
+                    cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
+
+                    IDataReader result = ExecuteReader(cmd);
+                    if (!result.Read())
                     {
-                        cmd.Connection = dbcon;
-    
-                        cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
-    
-                        IDataReader result = ExecuteReader(cmd);
-                        if (!result.Read())
-                        {
-                            return String.Empty;
-                        }
-                        else
-                        {
-                            return Convert.ToString(result["llsd_settings"]);
-                        }
+                        return String.Empty;
+                    }
+                    else
+                    {
+                        return Convert.ToString(result["llsd_settings"]);
                     }
                 }
             }
@@ -1012,39 +1028,33 @@ namespace OpenSim.Data.MySQL
 
         public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                using (MySqlCommand cmd = dbcon.CreateCommand())
                 {
-                    dbcon.Open();
-    
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "REPLACE INTO `regionenvironment` (`region_id`, `llsd_settings`) VALUES (?region_id, ?llsd_settings)";
-    
-                        cmd.Parameters.AddWithValue("region_id", regionUUID);
-                        cmd.Parameters.AddWithValue("llsd_settings", settings);
-    
-                        ExecuteNonQuery(cmd);
-                    }
+                    cmd.CommandText = "REPLACE INTO `regionenvironment` (`region_id`, `llsd_settings`) VALUES (?region_id, ?llsd_settings)";
+
+                    cmd.Parameters.AddWithValue("region_id", regionUUID);
+                    cmd.Parameters.AddWithValue("llsd_settings", settings);
+
+                    ExecuteNonQuery(cmd);
                 }
             }
         }
 
         public void RemoveRegionEnvironmentSettings(UUID regionUUID)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
+                dbcon.Open();
+
+                using (MySqlCommand cmd = dbcon.CreateCommand())
                 {
-                    dbcon.Open();
-    
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "delete from `regionenvironment` where region_id = ?region_id";
-                        cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
-                        ExecuteNonQuery(cmd);
-                    }
+                    cmd.CommandText = "delete from `regionenvironment` where region_id = ?region_id";
+                    cmd.Parameters.AddWithValue("?region_id", regionUUID.ToString());
+                    ExecuteNonQuery(cmd);
                 }
             }
         }
@@ -1052,56 +1062,55 @@ namespace OpenSim.Data.MySQL
 
         public void StoreRegionSettings(RegionSettings rs)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
-                {
-                    dbcon.Open();
-
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "replace into regionsettings (regionUUID, " +
-                            "block_terraform, block_fly, allow_damage, " +
-                            "restrict_pushing, allow_land_resell, " +
-                            "allow_land_join_divide, block_show_in_search, " +
-                            "agent_limit, object_bonus, maturity, " +
-                            "disable_scripts, disable_collisions, " +
-                            "disable_physics, terrain_texture_1, " +
-                            "terrain_texture_2, terrain_texture_3, " +
-                            "terrain_texture_4, elevation_1_nw, " +
-                            "elevation_2_nw, elevation_1_ne, " +
-                            "elevation_2_ne, elevation_1_se, " +
-                            "elevation_2_se, elevation_1_sw, " +
-                            "elevation_2_sw, water_height, " +
-                            "terrain_raise_limit, terrain_lower_limit, " +
-                            "use_estate_sun, fixed_sun, sun_position, " +
-                            "covenant, covenant_datetime, Sandbox, sunvectorx, sunvectory, " +
-                            "sunvectorz, loaded_creation_datetime, " +
-                            "loaded_creation_id, map_tile_ID, " +
-                            "TelehubObject, parcel_tile_ID) " +
-                             "values (?RegionUUID, ?BlockTerraform, " +
-                            "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
-                            "?AllowLandResell, ?AllowLandJoinDivide, " +
-                            "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
-                            "?Maturity, ?DisableScripts, ?DisableCollisions, " +
-                            "?DisablePhysics, ?TerrainTexture1, " +
-                            "?TerrainTexture2, ?TerrainTexture3, " +
-                            "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
-                            "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
-                            "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
-                            "?WaterHeight, ?TerrainRaiseLimit, " +
-                            "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
-                            "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
-                            "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
-                            "?LoadedCreationDateTime, ?LoadedCreationID, " +
-                            "?TerrainImageID, ?TelehubObject, ?ParcelImageID) ";
-
-                        FillRegionSettingsCommand(cmd, rs);
+                dbcon.Open();
 
-                        ExecuteNonQuery(cmd);
-                    }
+                using (MySqlCommand cmd = dbcon.CreateCommand())
+                {
+                    cmd.CommandText = "replace into regionsettings (regionUUID, " +
+                        "block_terraform, block_fly, allow_damage, " +
+                        "restrict_pushing, allow_land_resell, " +
+                        "allow_land_join_divide, block_show_in_search, " +
+                        "agent_limit, object_bonus, maturity, " +
+                        "disable_scripts, disable_collisions, " +
+                        "disable_physics, terrain_texture_1, " +
+                        "terrain_texture_2, terrain_texture_3, " +
+                        "terrain_texture_4, elevation_1_nw, " +
+                        "elevation_2_nw, elevation_1_ne, " +
+                        "elevation_2_ne, elevation_1_se, " +
+                        "elevation_2_se, elevation_1_sw, " +
+                        "elevation_2_sw, water_height, " +
+                        "terrain_raise_limit, terrain_lower_limit, " +
+                        "use_estate_sun, fixed_sun, sun_position, " +
+                        "covenant, covenant_datetime, Sandbox, sunvectorx, sunvectory, " +
+                        "sunvectorz, loaded_creation_datetime, " +
+                        "loaded_creation_id, map_tile_ID, " +
+                        "TelehubObject, parcel_tile_ID) " +
+                         "values (?RegionUUID, ?BlockTerraform, " +
+                        "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
+                        "?AllowLandResell, ?AllowLandJoinDivide, " +
+                        "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
+                        "?Maturity, ?DisableScripts, ?DisableCollisions, " +
+                        "?DisablePhysics, ?TerrainTexture1, " +
+                        "?TerrainTexture2, ?TerrainTexture3, " +
+                        "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
+                        "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
+                        "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
+                        "?WaterHeight, ?TerrainRaiseLimit, " +
+                        "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
+                        "?SunPosition, ?Covenant, ?CovenantChangedDateTime, ?Sandbox, " +
+                        "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
+                        "?LoadedCreationDateTime, ?LoadedCreationID, " +
+                        "?TerrainImageID, " +
+                        "?TelehubObject, ?ParcelImageID)";
+
+                    FillRegionSettingsCommand(cmd, rs);
+
+                    ExecuteNonQuery(cmd);
                 }
             }
+
             SaveSpawnPoints(rs);
         }
 
@@ -1292,6 +1301,39 @@ namespace OpenSim.Data.MySQL
             if (!(row["MediaURL"] is System.DBNull))
                 prim.MediaUrl = (string)row["MediaURL"];
 
+            if (!(row["AttachedPosX"] is System.DBNull))
+            {
+                prim.AttachedPos = new Vector3(
+                    (float)(double)row["AttachedPosX"],
+                    (float)(double)row["AttachedPosY"],
+                    (float)(double)row["AttachedPosZ"]
+                    );
+            }
+
+            if (!(row["DynAttrs"] is System.DBNull))
+                prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
+            else
+                prim.DynAttrs = new DAMap();        
+
+            if (!(row["KeyframeMotion"] is DBNull))
+            {
+                Byte[] data = (byte[])row["KeyframeMotion"];
+                if (data.Length > 0)
+                    prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
+                else
+                    prim.KeyframeMotion = null;
+            }
+            else
+            {
+                prim.KeyframeMotion = null;
+            }
+
+            prim.PhysicsShapeType = (byte)Convert.ToInt32(row["PhysicsShapeType"].ToString());
+            prim.Density = (float)(double)row["Density"];
+            prim.GravityModifier = (float)(double)row["GravityModifier"];
+            prim.Friction = (float)(double)row["Friction"];
+            prim.Restitution = (float)(double)row["Restitution"];
+            
             return prim;
         }
 
@@ -1431,6 +1473,7 @@ namespace OpenSim.Data.MySQL
             UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
             UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
             newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
+            newData.Dwell = Convert.ToSingle(row["Dwell"]);
 
             newData.AuthBuyerID = authedbuyer;
             newData.SnapshotID = snapshotID;
@@ -1478,30 +1521,6 @@ namespace OpenSim.Data.MySQL
         }
 
         /// <summary>
-        ///
-        /// </summary>
-        /// <param name="val"></param>
-        /// <returns></returns>
-        private static Array SerializeTerrain(double[,] val)
-        {
-            MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
-            BinaryWriter bw = new BinaryWriter(str);
-
-            // TODO: COMPATIBILITY - Add byte-order conversions
-            for (int x = 0; x < (int)Constants.RegionSize; x++)
-                for (int y = 0; y < (int)Constants.RegionSize; y++)
-                {
-                    double height = val[x, y];
-                    if (height == 0.0)
-                        height = double.Epsilon;
-
-                    bw.Write(height);
-                }
-
-            return str.ToArray();
-        }
-
-        /// <summary>
         /// Fill the prim command with prim values
         /// </summary>
         /// <param name="row"></param>
@@ -1637,6 +1656,28 @@ namespace OpenSim.Data.MySQL
 
             cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
             cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
+            if (prim.AttachedPos != null)
+            {
+                cmd.Parameters.AddWithValue("AttachedPosX", (double)prim.AttachedPos.X);
+                cmd.Parameters.AddWithValue("AttachedPosY", (double)prim.AttachedPos.Y);
+                cmd.Parameters.AddWithValue("AttachedPosZ", (double)prim.AttachedPos.Z);
+            }
+
+            if (prim.KeyframeMotion != null)
+                cmd.Parameters.AddWithValue("KeyframeMotion", prim.KeyframeMotion.Serialize());
+            else
+                cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]);
+
+            if (prim.DynAttrs.CountNamespaces > 0)
+                cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
+            else
+                cmd.Parameters.AddWithValue("DynAttrs", null);
+
+            cmd.Parameters.AddWithValue("PhysicsShapeType", prim.PhysicsShapeType);
+            cmd.Parameters.AddWithValue("Density", (double)prim.Density);
+            cmd.Parameters.AddWithValue("GravityModifier", (double)prim.GravityModifier);
+            cmd.Parameters.AddWithValue("Friction", (double)prim.Friction);
+            cmd.Parameters.AddWithValue("Restitution", (double)prim.Restitution);
         }
 
         /// <summary>
@@ -1715,6 +1756,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("ParcelImageID", settings.ParcelImageID);
             cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
         }
@@ -1763,6 +1805,7 @@ namespace OpenSim.Data.MySQL
             cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
             cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
             cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
+            cmd.Parameters.AddWithValue("Dwell", land.Dwell);
             cmd.Parameters.AddWithValue("MediaDescription", land.MediaDescription);
             cmd.Parameters.AddWithValue("MediaType", land.MediaType);
             cmd.Parameters.AddWithValue("MediaWidth", land.MediaWidth);
@@ -1770,7 +1813,6 @@ namespace OpenSim.Data.MySQL
             cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop);
             cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic);
             cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia);
-
         }
 
         /// <summary>
@@ -1826,6 +1868,7 @@ namespace OpenSim.Data.MySQL
             s.ExtraParams = (byte[])row["ExtraParams"];
 
             s.State = (byte)(int)row["State"];
+            s.LastAttachPoint = (byte)(int)row["LastAttachPoint"];
             
             if (!(row["Media"] is System.DBNull))
                 s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
@@ -1872,6 +1915,7 @@ namespace OpenSim.Data.MySQL
             cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
             cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
             cmd.Parameters.AddWithValue("State", s.State);
+            cmd.Parameters.AddWithValue("LastAttachPoint", s.LastAttachPoint);
             cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
         }
 
@@ -1988,41 +2032,35 @@ namespace OpenSim.Data.MySQL
 
         public void SaveExtra(UUID regionID, string name, string val)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
-                {
-                    dbcon.Open();
+                dbcon.Open();
 
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "replace into regionextra values (?RegionID, ?Name, ?value)";
-                        cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
-                        cmd.Parameters.AddWithValue("?Name", name);
-                        cmd.Parameters.AddWithValue("?value", val);
+                using (MySqlCommand cmd = dbcon.CreateCommand())
+                {
+                    cmd.CommandText = "replace into regionextra values (?RegionID, ?Name, ?value)";
+                    cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
+                    cmd.Parameters.AddWithValue("?Name", name);
+                    cmd.Parameters.AddWithValue("?value", val);
 
-                        cmd.ExecuteNonQuery();
-                    }
+                    cmd.ExecuteNonQuery();
                 }
             }
         }
 
         public void RemoveExtra(UUID regionID, string name)
         {
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
-                {
-                    dbcon.Open();
+                dbcon.Open();
 
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
-                    {
-                        cmd.CommandText = "delete from regionextra where RegionID=?RegionID and Name=?Name";
-                        cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
-                        cmd.Parameters.AddWithValue("?Name", name);
+                using (MySqlCommand cmd = dbcon.CreateCommand())
+                {
+                    cmd.CommandText = "delete from regionextra where RegionID=?RegionID and Name=?Name";
+                    cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
+                    cmd.Parameters.AddWithValue("?Name", name);
 
-                        cmd.ExecuteNonQuery();
-                    }
+                    cmd.ExecuteNonQuery();
                 }
             }
         }
@@ -2031,22 +2069,19 @@ namespace OpenSim.Data.MySQL
         {
             Dictionary<string, string> ret = new Dictionary<string, string>();
 
-            lock (m_dbLock)
+            using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
             {
-                using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
-                {
-                    dbcon.Open();
+                dbcon.Open();
 
-                    using (MySqlCommand cmd = dbcon.CreateCommand())
+                using (MySqlCommand cmd = dbcon.CreateCommand())
+                {
+                    cmd.CommandText = "select * from regionextra where RegionID=?RegionID";
+                    cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
+                    using (IDataReader r = cmd.ExecuteReader())
                     {
-                        cmd.CommandText = "select * from regionextra where RegionID=?RegionID";
-                        cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
-                        using (IDataReader r = cmd.ExecuteReader())
+                        while (r.Read())
                         {
-                            while (r.Read())
-                            {
-                                ret[r["Name"].ToString()] = r["value"].ToString();
-                            }
+                            ret[r["Name"].ToString()] = r["value"].ToString();
                         }
                     }
                 }
-- 
cgit v1.1