From cb5a7246a26afd03f405c316520a72c0268fbdf2 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 21 Jan 2018 16:40:58 +0000 Subject: cosmetics (or not) --- OpenSim/Data/MySQL/MySQLGenericTableHandler.cs | 28 ++++++++-------- .../Linden/Caps/EventQueue/EventQueueHelper.cs | 18 +++++----- .../UserAccountService/UserAccountService.cs | 39 +++++++++++----------- 3 files changed, 42 insertions(+), 43 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index 9bd3c0c..1564140 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -29,11 +29,9 @@ using System; using System.Collections.Generic; using System.Data; using System.Reflection; -using log4net; +using System.Text; using MySql.Data.MySqlClient; using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Region.Framework.Interfaces; namespace OpenSim.Data.MySQL { @@ -129,25 +127,27 @@ namespace OpenSim.Data.MySQL public virtual T[] Get(string[] fields, string[] keys, string options) { - if (fields.Length != keys.Length) + int flen = fields.Length; + if (flen == 0 || flen != keys.Length) return new T[0]; - List terms = new List(); + int flast = flen - 1; + StringBuilder sb = new StringBuilder(1024); + sb.AppendFormat("select * from {0} where ", m_Realm); using (MySqlCommand cmd = new MySqlCommand()) { - for (int i = 0 ; i < fields.Length ; i++) + for (int i = 0 ; i < flen ; i++) { cmd.Parameters.AddWithValue(fields[i], keys[i]); - terms.Add("`" + fields[i] + "` = ?" + fields[i]); + if(i< flast) + sb.AppendFormat("`{0}` = ?{0} and ", fields[i]); + else + sb.AppendFormat("`{0}` = ?{0} ", fields[i]); } - string where = String.Join(" and ", terms.ToArray()); - - string query = String.Format("select * from {0} where {1} {2}", - m_Realm, where, options); - - cmd.CommandText = query; + sb.Append(options); + cmd.CommandText = sb.ToString(); return DoQuery(cmd); } @@ -204,7 +204,7 @@ namespace OpenSim.Data.MySQL if (m_Fields[name].FieldType == typeof(bool)) { int v = Convert.ToInt32(reader[name]); - m_Fields[name].SetValue(row, v != 0 ? true : false); + m_Fields[name].SetValue(row, v != 0); } else if (m_Fields[name].FieldType == typeof(UUID)) { diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs index 461f776..52cfd48 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueHelper.cs @@ -43,16 +43,16 @@ namespace OpenSim.Region.ClientStack.Linden private static byte[] ulongToByteArray(ulong uLongValue) { // Reverse endianness of RegionHandle - return new byte[] + return new byte[8] { - (byte)((uLongValue >> 56) % 256), - (byte)((uLongValue >> 48) % 256), - (byte)((uLongValue >> 40) % 256), - (byte)((uLongValue >> 32) % 256), - (byte)((uLongValue >> 24) % 256), - (byte)((uLongValue >> 16) % 256), - (byte)((uLongValue >> 8) % 256), - (byte)(uLongValue % 256) + (byte)((uLongValue >> 56) & 0xff), + (byte)((uLongValue >> 48) & 0xff), + (byte)((uLongValue >> 40) & 0xff), + (byte)((uLongValue >> 32) & 0xff), + (byte)((uLongValue >> 24) & 0xff), + (byte)((uLongValue >> 16) & 0xff), + (byte)((uLongValue >> 8) & 0xff), + (byte)(uLongValue & 0xff) }; } diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 48929ee..5561287 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -86,30 +86,29 @@ namespace OpenSim.Services.UserAccountService m_CreateDefaultAvatarEntries = userConfig.GetBoolean("CreateDefaultAvatarEntries", false); - // create a system grid god account - UserAccount ggod = GetUserAccount(UUID.Zero, UUID_GRID_GOD); - if(ggod == null) - { - UserAccountData d = new UserAccountData(); - - d.FirstName = "GRID"; - d.LastName = "SERVICES"; - d.PrincipalID = UUID_GRID_GOD; - d.ScopeID = UUID.Zero; - d.Data = new Dictionary(); - d.Data["Email"] = string.Empty; - d.Data["Created"] = Util.UnixTimeSinceEpoch().ToString(); - d.Data["UserLevel"] = "240"; - d.Data["UserFlags"] = "0"; - d.Data["ServiceURLs"] = string.Empty; - - m_Database.Store(d); - } - if (m_RootInstance == null) { m_RootInstance = this; + // create a system grid god account + UserAccount ggod = GetUserAccount(UUID.Zero, UUID_GRID_GOD); + if(ggod == null) + { + UserAccountData d = new UserAccountData(); + d.FirstName = "GRID"; + d.LastName = "SERVICES"; + d.PrincipalID = UUID_GRID_GOD; + d.ScopeID = UUID.Zero; + d.Data = new Dictionary(); + d.Data["Email"] = string.Empty; + d.Data["Created"] = Util.UnixTimeSinceEpoch().ToString(); + d.Data["UserLevel"] = "240"; + d.Data["UserFlags"] = "0"; + d.Data["ServiceURLs"] = string.Empty; + + m_Database.Store(d); + } + // In case there are several instances of this class in the same process, // the console commands are only registered for the root instance if (MainConsole.Instance != null) -- cgit v1.1