diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs index b594a37148..a045b31446 100644 --- a/OpenSim/Data/MySQL/MySQLSimulationData.cs +++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs @@ -92,19 +92,15 @@ namespace OpenSim.Data.MySQL private IDataReader ExecuteReader(MySqlCommand c) { - IDataReader r = null; - try { - r = c.ExecuteReader(); + return c.ExecuteReader(); } catch (Exception e) { m_log.ErrorFormat("{0} MySQL error in ExecuteReader: {1}", LogHeader, e); throw; } - - return r; } private void ExecuteNonQuery(MySqlCommand c) @@ -298,17 +294,17 @@ namespace OpenSim.Data.MySQL sb.Append("IN ("); for(int i = 0; i < uuids.Count - 1; ++i ) { - sb.Append("'"); + sb.Append('\''); sb.Append(uuids[i]); sb.Append("',"); } - sb.Append("'"); + sb.Append('\''); sb.Append(uuids[uuids.Count - 1]); sb.Append("')"); sqlparams = sb.ToString(); } else - sqlparams = "='" + uuids[0] + "'"; + sqlparams = $"='{uuids[0]}'"; cmd.CommandText = "delete from primshapes where UUID " + sqlparams; ExecuteNonQuery(cmd); @@ -1095,9 +1091,9 @@ namespace OpenSim.Data.MySQL else prim.SoundFlags = 1; // If it's persisted at all, it's looped - if (!(row["TextureAnimation"] is DBNull)) + if (row["TextureAnimation"] is not DBNull) prim.TextureAnimation = (byte[])row["TextureAnimation"]; - if (!(row["ParticleSystem"] is DBNull)) + if (row["ParticleSystem"] is not DBNull) prim.ParticleSystem = (byte[])row["ParticleSystem"]; prim.SetCameraEyeOffset(new Vector3( @@ -1122,7 +1118,7 @@ namespace OpenSim.Data.MySQL prim.Material = unchecked((byte)(sbyte)row["Material"]); - if (!(row["ClickAction"] is DBNull)) + if (row["ClickAction"] is not DBNull) prim.ClickAction = unchecked((byte)(sbyte)row["ClickAction"]); prim.CollisionSound = DBGuid.FromDB(row["CollisionSound"]); @@ -1132,10 +1128,10 @@ namespace OpenSim.Data.MySQL prim.PassCollisions = ((sbyte)row["PassCollisions"] != 0); prim.LinkNum = (int)row["LinkNumber"]; - if (!(row["MediaURL"] is System.DBNull)) + if (row["MediaURL"] is not System.DBNull) prim.MediaUrl = (string)row["MediaURL"]; - if (!(row["AttachedPosX"] is System.DBNull)) + if (row["AttachedPosX"] is not System.DBNull) { prim.AttachedPos = new Vector3( (float)row["AttachedPosX"], @@ -1144,14 +1140,14 @@ namespace OpenSim.Data.MySQL ); } - if (!(row["DynAttrs"] is System.DBNull)) + if (row["DynAttrs"] is not System.DBNull) prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]); else prim.DynAttrs = null; - if (!(row["KeyframeMotion"] is DBNull)) + if (row["KeyframeMotion"] is not DBNull) { - Byte[] data = (byte[])row["KeyframeMotion"]; + byte[] data = (byte[])row["KeyframeMotion"]; if (data.Length > 0) prim.KeyframeMotion = KeyframeMotion.FromData(null, data); else @@ -1169,11 +1165,9 @@ namespace OpenSim.Data.MySQL prim.Restitution = (float)row["Restitution"]; prim.RotationAxisLocks = (byte)Convert.ToInt32(row["RotationAxisLocks"].ToString()); - SOPVehicle vehicle = null; - if (row["Vehicle"].ToString() != String.Empty) { - vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString()); + SOPVehicle vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString()); if (vehicle != null) prim.VehicleParams = vehicle; } @@ -1183,9 +1177,9 @@ namespace OpenSim.Data.MySQL pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString()); prim.PhysicsInertia = pdata; - if (!(row["sopanims"] is DBNull)) + if (row["sopanims"] is not DBNull) { - Byte[] data = (byte[])row["sopanims"]; + byte[] data = (byte[])row["sopanims"]; if (data.Length > 0) prim.DeSerializeAnimations(data); else @@ -1306,7 +1300,7 @@ namespace OpenSim.Data.MySQL newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]); newSettings.Casino = Convert.ToBoolean(row["casino"]); - if (!(row["cacheID"] is DBNull)) + if (row["cacheID"] is not DBNull) newSettings.CacheID = DBGuid.FromDB(row["cacheID"]); @@ -1350,11 +1344,9 @@ namespace OpenSim.Data.MySQL newData.MusicURL = (String) row["MusicURL"]; newData.PassHours = Convert.ToSingle(row["PassHours"]); newData.PassPrice = Convert.ToInt32(row["PassPrice"]); - UUID authedbuyer = UUID.Zero; - UUID snapshotID = UUID.Zero; - UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer); - UUID.TryParse((string)row["SnapshotUUID"], out snapshotID); + UUID.TryParse((string)row["AuthBuyerID"], out UUID authedbuyer); + UUID.TryParse((string)row["SnapshotUUID"], out UUID snapshotID); newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]); newData.Dwell = Convert.ToSingle(row["Dwell"]); @@ -1378,20 +1370,24 @@ namespace OpenSim.Data.MySQL newData.MediaDescription = (string) row["MediaDescription"]; newData.MediaType = (string) row["MediaType"]; - newData.MediaWidth = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[0]); - newData.MediaHeight = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[1]); + string[] sizes = ((string)row["MediaSize"]).Split(','); + if (sizes.Length > 1) + { + newData.MediaWidth = Convert.ToInt32(sizes[0]); + newData.MediaHeight = Convert.ToInt32(sizes[1]); + } newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]); newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]); newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]); newData.ParcelAccessList = new List(); - if (!(row["SeeAVs"] is System.DBNull)) - newData.SeeAVs = Convert.ToInt32(row["SeeAVs"]) != 0 ? true : false; - if (!(row["AnyAVSounds"] is System.DBNull)) - newData.AnyAVSounds = Convert.ToInt32(row["AnyAVSounds"]) != 0 ? true : false; - if (!(row["GroupAVSounds"] is System.DBNull)) - newData.GroupAVSounds = Convert.ToInt32(row["GroupAVSounds"]) != 0 ? true : false; + if (row["SeeAVs"] is not System.DBNull) + newData.SeeAVs = Convert.ToInt32(row["SeeAVs"]) != 0; + if (row["AnyAVSounds"] is not System.DBNull) + newData.AnyAVSounds = Convert.ToInt32(row["AnyAVSounds"]) != 0; + if (row["GroupAVSounds"] is not System.DBNull) + newData.GroupAVSounds = Convert.ToInt32(row["GroupAVSounds"]) != 0; if (row["environment"] is DBNull) { @@ -1831,7 +1827,7 @@ namespace OpenSim.Data.MySQL s.State = (byte)(int)row["State"]; s.LastAttachPoint = (byte)(int)row["LastAttachPoint"]; - if (!(row["Media"] is System.DBNull)) + if (row["Media"] is not System.DBNull) s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]); return s; @@ -1951,7 +1947,7 @@ namespace OpenSim.Data.MySQL { while (reader.Read()) { - UUID id = new UUID(reader["UUID"].ToString()); + UUID id = new UUID(reader["UUID"].ToString().AsSpan()); uuids.Add(id); } diff --git a/OpenSim/Data/Null/NullAvatarData.cs b/OpenSim/Data/Null/NullAvatarData.cs index c81ba43e6e..5d0f847138 100644 --- a/OpenSim/Data/Null/NullAvatarData.cs +++ b/OpenSim/Data/Null/NullAvatarData.cs @@ -46,14 +46,13 @@ namespace OpenSim.Data.Null { if (field == "PrincipalID") { - UUID id = UUID.Zero; - if (UUID.TryParse(val, out id)) - if (m_DataByUUID.ContainsKey(id)) - return new AvatarBaseData[] { m_DataByUUID[id] }; + if (UUID.TryParse(val, out UUID id)) + if (m_DataByUUID.TryGetValue(id, out AvatarBaseData abd)) + return new AvatarBaseData[] { abd }; } // Fail - return new AvatarBaseData[0]; + return Array.Empty(); } public bool Store(AvatarBaseData data) @@ -64,12 +63,10 @@ namespace OpenSim.Data.Null public bool Delete(UUID principalID, string name) { - if (m_DataByUUID.ContainsKey(principalID) && m_DataByUUID[principalID].Data.ContainsKey(name)) + if (m_DataByUUID.TryGetValue(principalID, out AvatarBaseData abd)) { - m_DataByUUID[principalID].Data.Remove(name); - return true; + return abd.Data.Remove(name); } - return false; } @@ -77,15 +74,9 @@ namespace OpenSim.Data.Null { if (field == "PrincipalID") { - UUID id = UUID.Zero; - if (UUID.TryParse(val, out id)) - if (m_DataByUUID.ContainsKey(id)) - { - m_DataByUUID.Remove(id); - return true; - } + if (UUID.TryParse(val, out UUID id)) + return m_DataByUUID.Remove(id); } - return false; } diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs index 759528448f..f8cbc5e970 100755 --- a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs +++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs @@ -1157,8 +1157,12 @@ namespace OpenSim.Data.PGSQL newData.ParcelAccessList = new List(); newData.MediaDescription = (string)row["MediaDescription"]; newData.MediaType = (string)row["MediaType"]; - newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]); - newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]); + string[] sizes = ((string)row["MediaSize"]).Split(','); + if (sizes.Length > 1) + { + newData.MediaWidth = Convert.ToInt32(sizes[0]); + newData.MediaHeight = Convert.ToInt32(sizes[1]); + } newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]); newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]); newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]); diff --git a/OpenSim/Data/SQLite/SQLiteSimulationData.cs b/OpenSim/Data/SQLite/SQLiteSimulationData.cs index d2270acc78..a07c82805f 100644 --- a/OpenSim/Data/SQLite/SQLiteSimulationData.cs +++ b/OpenSim/Data/SQLite/SQLiteSimulationData.cs @@ -1878,8 +1878,12 @@ namespace OpenSim.Data.SQLite newData.Dwell = Convert.ToInt32(row["Dwell"]); newData.MediaType = (String)row["MediaType"]; newData.MediaDescription = (String)row["MediaDescription"]; - newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]); - newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]); + string[] sizes = ((string)row["MediaSize"]).Split(','); + if (sizes.Length > 1) + { + newData.MediaWidth = Convert.ToInt32(sizes[0]); + newData.MediaHeight = Convert.ToInt32(sizes[1]); + } newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]); newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]); newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]); @@ -1904,9 +1908,8 @@ namespace OpenSim.Data.SQLite newData.UserLookAt = Vector3.Zero; } newData.ParcelAccessList = new List(); - UUID authBuyerID = UUID.Zero; - - UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID); + UUID.TryParse((string)row["AuthbuyerID"], out UUID authBuyerID); + newData.AuthBuyerID = authBuyerID; newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]); @@ -1992,7 +1995,7 @@ namespace OpenSim.Data.SQLite newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]); newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]); newSettings.Casino = Convert.ToBoolean(row["casino"]); - if (!(row["cacheID"] is System.DBNull)) + if (row["cacheID"] is not System.DBNull) newSettings.CacheID = new UUID((String)row["cacheID"]); return newSettings; @@ -2393,7 +2396,7 @@ namespace OpenSim.Data.SQLite s.ExtraParams = (byte[])row["ExtraParams"]; - if (!(row["Media"] is System.DBNull)) + if (row["Media"] is not System.DBNull) s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]); return s; @@ -2441,7 +2444,7 @@ namespace OpenSim.Data.SQLite row["Texture"] = s.TextureEntry; row["ExtraParams"] = s.ExtraParams; - if (s.Media != null) + if (s.Media is not null) row["Media"] = s.Media.ToXml(); }