From 87fc4c1f5121f95e56c117fc07a614e36643cc85 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sat, 18 Jul 2026 00:27:29 +0100 Subject: [PATCH] cosmetics --- .../Data/MySQL/MySQLGenericTableHandler.cs | 53 +++++++++---------- OpenSim/Data/MySQL/MySQLGridUserData.cs | 3 +- OpenSim/Data/MySQL/MySQLUserAccountData.cs | 15 ++---- OpenSim/Data/PGSQL/PGSQLUserAccountData.cs | 2 +- OpenSim/Data/SQLite/SQLiteUserAccountData.cs | 9 ++-- OpenSim/Region/Framework/Scenes/Scene.cs | 8 +-- 6 files changed, 38 insertions(+), 52 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index a583285733..d91c0dc500 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -39,7 +39,7 @@ namespace OpenSim.Data.MySQL { //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - protected Dictionary m_Fields = new Dictionary(); + protected Dictionary m_Fields = []; protected List m_ColumnNames = null; protected string m_Realm; @@ -71,7 +71,7 @@ namespace OpenSim.Data.MySQL if (!string.IsNullOrEmpty(storeName)) { // We always use a new connection for any Migrations - using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + using (MySqlConnection dbcon = new(m_connectionString)) { dbcon.Open(); Migration m = new Migration(dbcon, Assembly, storeName); @@ -101,7 +101,7 @@ namespace OpenSim.Data.MySQL if (m_ColumnNames != null) return; - List columnNames = new List(); + List columnNames = []; DataTable schemaTable = reader.GetSchemaTable(); foreach (DataRow row in schemaTable.Rows) @@ -116,7 +116,7 @@ namespace OpenSim.Data.MySQL public virtual T[] Get(string field, string key) { - using (MySqlCommand cmd = new MySqlCommand()) + using (MySqlCommand cmd = new()) { cmd.Parameters.AddWithValue(field, key); cmd.CommandText = $"select * from {m_Realm} where `{field}` = ?{field}"; @@ -128,7 +128,7 @@ namespace OpenSim.Data.MySQL { int flen = keys.Length; if(flen == 0) - return new T[0]; + return []; int flast = flen - 1; StringBuilder sb = new StringBuilder(1024); @@ -144,7 +144,7 @@ namespace OpenSim.Data.MySQL if(i < flast) sb.Append(",?"); else - sb.Append(")"); + sb.Append(')'); } cmd.CommandText = sb.ToString(); return DoQuery(cmd); @@ -153,14 +153,14 @@ namespace OpenSim.Data.MySQL public virtual T[] Get(string[] fields, string[] keys) { - return Get(fields, keys, String.Empty); + return Get(fields, keys, string.Empty); } public virtual T[] Get(string[] fields, string[] keys, string options) { int flen = fields.Length; if (flen == 0 || flen != keys.Length) - return new T[0]; + return []; int flast = flen - 1; StringBuilder sb = new StringBuilder(1024); @@ -188,7 +188,7 @@ namespace OpenSim.Data.MySQL { if (m_trans == null) { - using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) + using (MySqlConnection dbcon = new(m_connectionString)) { dbcon.Open(); T[] ret = DoQueryWithConnection(cmd, dbcon); @@ -211,14 +211,14 @@ namespace OpenSim.Data.MySQL protected T[] DoQueryWithConnection(MySqlCommand cmd, MySqlConnection dbcon) { - List result = new List(); + List result = []; cmd.Connection = dbcon; - using (IDataReader reader = cmd.ExecuteReader()) + using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader == null) - return new T[0]; + return []; CheckColumnNames(reader); @@ -259,14 +259,13 @@ namespace OpenSim.Data.MySQL if (m_DataField != null) { - Dictionary data = - new Dictionary(); + Dictionary data = []; foreach (string col in m_ColumnNames) { data[col] = reader[col].ToString(); if (data[col] == null) - data[col] = String.Empty; + data[col] = string.Empty; } m_DataField.SetValue(row, data); @@ -281,10 +280,9 @@ namespace OpenSim.Data.MySQL public virtual T[] Get(string where) { - using (MySqlCommand cmd = new MySqlCommand()) + using (MySqlCommand cmd = new()) { - cmd.CommandText = $"select * from {m_Realm} where {where}"; ; - + cmd.CommandText = $"select * from {m_Realm} where {where}"; return DoQuery(cmd); } } @@ -293,11 +291,11 @@ namespace OpenSim.Data.MySQL { //m_log.DebugFormat("[MYSQL GENERIC TABLE HANDLER]: Store(T row) invoked"); - using (MySqlCommand cmd = new MySqlCommand()) + using (MySqlCommand cmd = new()) { string query = ""; - List names = new List(); - List values = new List(); + List names = []; + List values = []; foreach (FieldInfo fi in m_Fields.Values) { @@ -340,7 +338,7 @@ namespace OpenSim.Data.MySQL public virtual bool Delete(string field, string key) { - return Delete(new string[] { field }, new string[] { key }); + return Delete([field], [key]); } public virtual bool Delete(string[] fields, string[] keys) @@ -375,7 +373,7 @@ namespace OpenSim.Data.MySQL public long GetCount(string field, string key) { - return GetCount(new string[] { field }, new string[] { key }); + return GetCount([field], [key]); } public long GetCount(string[] fields, string[] keys) @@ -388,7 +386,7 @@ namespace OpenSim.Data.MySQL StringBuilder sb = new StringBuilder(1024); sb.AppendFormat("select count(*) from {0} where ", m_Realm); - using (MySqlCommand cmd = new MySqlCommand()) + using (MySqlCommand cmd = new()) { for (int i = 0 ; i < flen ; i++) { @@ -408,12 +406,9 @@ namespace OpenSim.Data.MySQL public long GetCount(string where) { - using (MySqlCommand cmd = new MySqlCommand()) + using (MySqlCommand cmd = new() ) { - string query = String.Format("select count(*) from {0} where {1}", - m_Realm, where); - - cmd.CommandText = query; + cmd.CommandText = $"select count(*) from {m_Realm} where {where}"; object result = DoQueryScalar(cmd); diff --git a/OpenSim/Data/MySQL/MySQLGridUserData.cs b/OpenSim/Data/MySQL/MySQLGridUserData.cs index 00560c11db..0aa54b937a 100644 --- a/OpenSim/Data/MySQL/MySQLGridUserData.cs +++ b/OpenSim/Data/MySQL/MySQLGridUserData.cs @@ -42,7 +42,7 @@ namespace OpenSim.Data.MySQL /// public class MySQLGridUserData : MySQLGenericTableHandler, IGridUserData { -// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public MySQLGridUserData(string connectionString, string realm) : base(connectionString, realm, "GridUserStore") {} @@ -58,6 +58,7 @@ namespace OpenSim.Data.MySQL public GridUserData[] GetAll(string userID) { + userID = MySqlHelper.EscapeString(userID); return base.Get(String.Format("UserID LIKE '{0}%'", userID)); } } diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index 2c531e9768..df45bd8482 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs @@ -44,7 +44,7 @@ namespace OpenSim.Data.MySQL public UserAccountData[] GetUsers(UUID scopeID, string query) { - string[] words = query.Split(); + string[] words = query.Split(' ', StringSplitOptions.RemoveEmptyEntries); bool valid = false; @@ -52,19 +52,10 @@ namespace OpenSim.Data.MySQL { if (words[i].Length > 2) valid = true; -// if (words[i].Length < 3) -// { -// if (i != words.Length - 1) -// Array.Copy(words, i + 1, words, i, words.Length - i - 1); -// Array.Resize(ref words, words.Length - 1); -// } } - if ((!valid) || words.Length == 0) - return new UserAccountData[0]; - - if (words.Length > 2) - return new UserAccountData[0]; + if ((!valid) || words.Length == 0 || words.Length > 2) + return []; using (MySqlCommand cmd = new MySqlCommand()) { diff --git a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs index 3dcb6a193a..719652af53 100644 --- a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs +++ b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs @@ -274,7 +274,7 @@ namespace OpenSim.Data.PGSQL public UserAccountData[] GetUsers(UUID scopeID, string query) { - string[] words = query.Split(); + string[] words = query.Split(' ', StringSplitOptions.RemoveEmptyEntries);; for (int i = 0; i < words.Length; i++) { diff --git a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs index 4bb8d25754..056e7b2525 100644 --- a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs +++ b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs @@ -44,7 +44,7 @@ namespace OpenSim.Data.SQLite public UserAccountData[] GetUsers(UUID scopeID, string query) { - string[] words = query.Split(); + string[] words = query.Split(' ', StringSplitOptions.RemoveEmptyEntries);; for (int i = 0 ; i < words.Length ; i++) { @@ -56,11 +56,8 @@ namespace OpenSim.Data.SQLite } } - if (words.Length == 0) - return new UserAccountData[0]; - - if (words.Length > 2) - return new UserAccountData[0]; + if (words.Length == 0 || words.Length > 2) + return []; using (SQLiteCommand cmd = new SQLiteCommand()) { diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 1039265a53..8099b72308 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -784,6 +784,7 @@ namespace OpenSim.Region.Framework.Scenes #region Constructors + public Scene(RegionInfo regInfo, AgentCircuitManager authen, ISimulationDataService simDataService, IEstateDataService estateDataService, IConfigSource config, string simulatorVersion) @@ -1004,7 +1005,8 @@ namespace OpenSim.Region.Framework.Scenes m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl); m_seeIntoBannedRegion = startupConfig.GetBoolean("SeeIntoBannedRegion", m_seeIntoBannedRegion); - string[] possibleMapConfigSections = new string[] { "Map", "Startup" }; + + string[] possibleMapConfigSections = ["Map", "Startup"]; m_generateMaptiles = Util.GetConfigVarFromSections(config, "GenerateMaptiles", possibleMapConfigSections, true); @@ -1037,7 +1039,7 @@ namespace OpenSim.Region.Framework.Scenes } } - string[] possibleAccessControlConfigSections = new string[] { "Startup", "AccessControl"}; + string[] possibleAccessControlConfigSections = ["Startup", "AccessControl"]; string grant = Util.GetConfigVarFromSections( config, "AllowedClients", possibleAccessControlConfigSections, string.Empty); @@ -1078,7 +1080,7 @@ namespace OpenSim.Region.Framework.Scenes m_update_terrain = startupConfig.GetInt("UpdateTerrainEveryNFrames", m_update_terrain); m_update_temp_cleaning = startupConfig.GetInt("UpdateTempCleaningEveryNSeconds", m_update_temp_cleaning); - string[] possibleScriptConfigSections = new string[] { "YEngine", "Xengine", "Scripts" }; + string[] possibleScriptConfigSections = ["YEngine", "Xengine", "Scripts"]; m_LinkSetDataLimit = Util.GetConfigVarFromSections(config, "LinksetDataLimit", possibleScriptConfigSections, m_LinkSetDataLimit); }