diff --git a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs index 2d8aef0bae..7fe70d2c7a 100644 --- a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs +++ b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs @@ -534,7 +534,7 @@ namespace OpenSim.Data.PGSQL { for (int i = 0; i < fields.Length; i++) { - cmd.Parameters.AddWithValue(fields[i], keys[i]); + cmd.Parameters.AddWithValue(fields[i], new Guid(keys[i])); terms.Add("\"" + fields[i] + "\" = :" + fields[i]); } diff --git a/OpenSim/Data/PGSQL/PGSQLMuteListData.cs b/OpenSim/Data/PGSQL/PGSQLMuteListData.cs new file mode 100644 index 0000000000..6b49f46fa7 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLMuteListData.cs @@ -0,0 +1,72 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using OpenSim.Framework; +using OpenMetaverse; +using Npgsql; + +namespace OpenSim.Data.PGSQL +{ + public class PGSQLMuteListData: PGSQLGenericTableHandler, IMuteListData + { + public PGSQLMuteListData(string connectionString) + : base(connectionString, "MuteList", "MuteListStore") + { + } + + public MuteData[] Get(UUID agentID) + { + var data = base.Get("AgentID", agentID.ToString()); + return data; + } + + public bool Delete(UUID agentID, UUID muteID, string muteName) + { + var query = $"DELETE FROM MuteList WHERE \"AgentID\" = :AgentID and " + + $"\"MuteID\" = :MuteID and " + + $"\"MuteName\" = :MuteName"; + + using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) + using (NpgsqlCommand cmd = new NpgsqlCommand()) + { + cmd.CommandText = query; + cmd.Parameters.AddWithValue(":AgentID", agentID.ToString()); + cmd.Parameters.AddWithValue(":MuteID", muteID.ToString()); + cmd.Parameters.AddWithValue("MuteName", muteName); + cmd.Connection = conn; + conn.Open(); + cmd.ExecuteNonQuery(); + + return true; + } + } + } +} \ No newline at end of file diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs index 155594f33c..b0b4639db1 100755 --- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs +++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs @@ -784,7 +784,7 @@ namespace OpenSim.Data.PGSQL cmd.ExecuteNonQuery(); } - sql = @"INSERT INTO landaccesslist (""LandUUID"",""AccessUUID"",""LandFlags"",""Expires"") VALUES (:LandUUID,:AccessUUID,:Flags,:Expires)"; + sql = @"INSERT INTO landaccesslist (""LandUUID"",""AccessUUID"",""Flags"",""Expires"") VALUES (:LandUUID,:AccessUUID,:Flags,:Expires)"; using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) @@ -920,7 +920,8 @@ namespace OpenSim.Data.PGSQL regionSettings.OnSave += StoreRegionSettings; //Store new values - StoreNewRegionSettings(regionSettings); + // StoreNewRegionSettings(regionSettings); + StoreRegionSettings(regionSettings); LoadSpawnPoints(regionSettings); @@ -928,51 +929,69 @@ namespace OpenSim.Data.PGSQL } /// - /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region. + /// Store region settings /// /// region settings. public void StoreRegionSettings(RegionSettings regionSettings) { - //Little check if regionUUID already exist in DB - string regionUUID; - string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID"; - using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) - using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) - { - cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID)); - conn.Open(); - regionUUID = cmd.ExecuteScalar().ToString(); - } + const string queryString = """ + INSERT 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", + block_search, casino, "TelehubObject", "parcel_tile_ID", "cacheID", "TerrainPBR1", "TerrainPBR2", + "TerrainPBR3", "TerrainPBR4") + VALUES + (: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, + :block_search, :casino, :TelehubObject, :ParcelImageID, :cacheID, :TerrainPBR1, :TerrainPBR2, + :TerrainPBR3, :TerrainPBR4) + ON CONFLICT ("regionUUID") + DO UPDATE SET "regionUUID" = :RegionUUID, block_terraform = :block_terraform, block_fly = :block_fly, + allow_damage = :allow_damage, restrict_pushing = :restrict_pushing, allow_land_resell = :allow_land_resell, + allow_land_join_divide = :allow_land_join_divide, block_show_in_search = :block_show_in_search, + agent_limit = :agent_limit, object_bonus = :object_bonus, maturity = :maturity, disable_scripts = :disable_scripts, + disable_collisions = :disable_collisions, disable_physics = :disable_physics, terrain_texture_1 = :terrain_texture_1, + terrain_texture_2 = :terrain_texture_2, terrain_texture_3 = :terrain_texture_3, terrain_texture_4 = :terrain_texture_4, + elevation_1_nw = :elevation_1_nw, elevation_2_nw = :elevation_2_nw, elevation_1_ne = :elevation_1_ne, + elevation_2_ne = :elevation_2_ne, elevation_1_se = :elevation_1_se, elevation_2_se = :elevation_2_se, + elevation_1_sw = :elevation_1_sw, elevation_2_sw = :elevation_2_sw, water_height = :water_height, + terrain_raise_limit = :terrain_raise_limit, terrain_lower_limit = :terrain_lower_limit, + use_estate_sun = :use_estate_sun, fixed_sun = :fixed_sun, sun_position = :sun_position, covenant = :covenant, + covenant_datetime = :covenant_datetime, "Sandbox" = :Sandbox, sunvectorx = :sunvectorx, + sunvectory = :sunvectory, sunvectorz = :sunvectorz, loaded_creation_datetime = :Loaded_Creation_DateTime, + loaded_creation_id = :Loaded_Creation_ID, "map_tile_ID" = :map_tile_ID, block_search = :block_search, + casino = :casino, "TelehubObject" = :TelehubObject, "parcel_tile_ID" = :ParcelImageID, "cacheID" = :cacheID, + "TerrainPBR1" = :TerrainPBR1, "TerrainPBR2" = :TerrainPBR2, "TerrainPBR3" = :TerrainPBR3, + "TerrainPBR4" = :TerrainPBR4 + """; - if (string.IsNullOrEmpty(regionUUID)) + using (var connection = new NpgsqlConnection(m_connectionString)) { - StoreNewRegionSettings(regionSettings); - } - else - { - //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB - sql = - @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage -,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide -,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity -,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics -,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3 -,terrain_texture_4 = :terrain_texture_4 , TerrainPBR1 = :TerrainPBR1, TerrainPBR2 = :TerrainPBR2, TerrainPBR3 = :TerrainPBR3 -,TerrainPBR4 = :TerrainPBR4, elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw -,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se -,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit -,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position -,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz, -""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID, -""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID, ""cacheID"" = :cacheID - WHERE ""regionUUID"" = :regionUUID"; - - using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) - using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) + connection.Open(); + NpgsqlCommand command = new NpgsqlCommand(queryString, connection, connection.BeginTransaction()); + using (command) { - cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings)); - conn.Open(); - cmd.ExecuteNonQuery(); + try + { + command.Parameters.AddRange(CreateRegionSettingParameters(regionSettings)); + command.ExecuteNonQuery(); + command.Transaction.Commit(); + } + catch (Exception e) + { + Console.WriteLine(e); + command.Transaction.Rollback(); + throw; + } } } SaveSpawnPoints(regionSettings); @@ -983,39 +1002,6 @@ namespace OpenSim.Data.PGSQL //Not used?? } - #region Private Methods - - /// - /// Stores new regionsettings. - /// - /// The region settings. - private void StoreNewRegionSettings(RegionSettings regionSettings) - { - string sql = @"INSERT 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,sunvectorx, sunvectory, sunvectorz, - ""Sandbox"", loaded_creation_datetime, loaded_creation_id - ) - VALUES - (: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, :sunvectorx,:sunvectory, - :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id )"; - - using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) - using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) - { - cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings)); - conn.Open(); - cmd.ExecuteNonQuery(); - } - } - #region Private DataRecord conversion methods /// @@ -1601,7 +1587,9 @@ namespace OpenSim.Data.PGSQL _Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime), _Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime), _Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID), - _Database.CreateParameter("TerrainImageID", settings.TerrainImageID), + _Database.CreateParameter("map_tile_ID", settings.TerrainImageID), + _Database.CreateParameter("block_search", settings.GodBlockSearch), + _Database.CreateParameter("casino", settings.Casino), _Database.CreateParameter("ParcelImageID", settings.ParcelImageID), _Database.CreateParameter("TelehubObject", settings.TelehubObject), _Database.CreateParameter("cacheID", settings.CacheID), @@ -1968,7 +1956,6 @@ namespace OpenSim.Data.PGSQL #endregion - #endregion private void LoadSpawnPoints(RegionSettings rs) { diff --git a/OpenSim/Data/PGSQL/Resources/MuteListStore.migrations b/OpenSim/Data/PGSQL/Resources/MuteListStore.migrations new file mode 100644 index 0000000000..83f3fcc2c0 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/MuteListStore.migrations @@ -0,0 +1,17 @@ +:VERSION 1 + +BEGIN TRANSACTION; + +CREATE TABLE IF NOT EXISTS MuteList ( + + "AgentID" varchar(36) NOT NULL, + "MuteId" varchar(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', + "MuteName" varchar(64) NOT NULL DEFAULT '', + "MuteType" int4 NOT NULL DEFAULT 1, + "MuteFlags" int4 NOT NULL DEFAULT 0, + "Stamp" int4 NOT NULL, + CONSTRAINT pk_agent_id PRIMARY KEY ("AgentID"), + CONSTRAINT unique_agent_2 UNIQUE ("AgentID", "MuteId", "MuteName") +); + +COMMIT; \ No newline at end of file diff --git a/OpenSim/Data/PGSQL/Resources/RegionStore.migrations b/OpenSim/Data/PGSQL/Resources/RegionStore.migrations index 7b86e28f04..a49c5df143 100644 --- a/OpenSim/Data/PGSQL/Resources/RegionStore.migrations +++ b/OpenSim/Data/PGSQL/Resources/RegionStore.migrations @@ -1267,3 +1267,22 @@ ALTER TABLE regionsettings ADD COLUMN "TerrainPBR2" uuid NOT NULL DEFAULT '00000 ALTER TABLE regionsettings ADD COLUMN "TerrainPBR3" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; ALTER TABLE regionsettings ADD COLUMN "TerrainPBR4" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; COMMIT; + +:VERSION 55 #----- Fix data type for columns +BEGIN; +ALTER TABLE public.regionsettings ALTER COLUMN "block_search" DROP DEFAULT; +ALTER TABLE public.regionsettings ALTER COLUMN "casino" DROP DEFAULT; +ALTER TABLE public.regionsettings + ALTER COLUMN "block_search" TYPE BOOLEAN + USING CASE WHEN "block_search" = 0 THEN FALSE + WHEN "block_search" = 1 THEN TRUE + ELSE NULL + END; + +ALTER TABLE public.regionsettings + ALTER COLUMN "casino" TYPE BOOLEAN + USING CASE WHEN "casino" = 0 THEN FALSE + WHEN "casino" = 1 THEN TRUE + ELSE NULL + END; +COMMIT; \ No newline at end of file