diff --git a/Database/Native/NativeCommand.cs b/Database/Native/NativeCommand.cs index 97623c040..9ec0bf618 100644 --- a/Database/Native/NativeCommand.cs +++ b/Database/Native/NativeCommand.cs @@ -76,16 +76,13 @@ namespace MCGalaxy.SQL.Native { code = sqlite3_bind_text(Statement, nParam.Index, dataPtr, dataCount - 1, IntPtr.Zero); break; case DbType.UInt16: - ushort value_u16 = (ushort)nParam.Value; - code = sqlite3_bind_int(Statement, nParam.Index, value_u16); + code = sqlite3_bind_int(Statement, nParam.Index, nParam.U16Value); break; case DbType.Byte: - byte value_u8 = (byte)nParam.Value; - code = sqlite3_bind_int(Statement, nParam.Index, value_u8); + code = sqlite3_bind_int(Statement, nParam.Index, nParam.U8Value); break; case DbType.Boolean: - bool value_bool = (bool)nParam.Value; - code = sqlite3_bind_int(Statement, nParam.Index, value_bool ? 1 : 0); + code = sqlite3_bind_int(Statement, nParam.Index, nParam.BoolValue ? 1 : 0); break; } if (code > 0) throw new NativeException(code); diff --git a/Database/Native/Utils.cs b/Database/Native/Utils.cs index 7a9436ec8..5b5560417 100644 --- a/Database/Native/Utils.cs +++ b/Database/Native/Utils.cs @@ -44,7 +44,7 @@ namespace MCGalaxy.SQL.Native { } } - sealed class NativeParameter : IDataParameter { + internal sealed class NativeParameter : IDataParameter { public DbType DbType { get { return type; } set { type = value; } } public ParameterDirection Direction { get; set; } public bool IsNullable { get { return false; } } @@ -54,7 +54,10 @@ namespace MCGalaxy.SQL.Native { public object Value { get; set; } public DbType type; - public int Index = -1; + public int Index = -1; + public ushort U16Value; + public byte U8Value; + public bool BoolValue; } sealed class NativeParamsList : List, IDataParameterCollection { diff --git a/Levels/Level.cs b/Levels/Level.cs index 64aee0cbe..ee15ba0c4 100644 --- a/Levels/Level.cs +++ b/Levels/Level.cs @@ -30,6 +30,7 @@ using Timer = System.Timers.Timer; using MCGalaxy.BlockPhysics; using MCGalaxy.Games; using MCGalaxy.Levels.IO; +using MCGalaxy.SQL.Native; //WARNING! DO NOT CHANGE THE WAY THE LEVEL IS SAVED/LOADED! //You MUST make it able to save and load as a new version other wise you will make old levels incompatible! @@ -391,6 +392,7 @@ namespace MCGalaxy IDataParameter zP = transaction.CreateParam("@Z", DbType.UInt16); cmd.Parameters.Add(zP); IDataParameter tileP = transaction.CreateParam("@Tile", DbType.Byte); cmd.Parameters.Add(tileP); IDataParameter delP = transaction.CreateParam("@Del", DbType.Boolean); cmd.Parameters.Add(delP); + bool isNative = transaction is NativeBulkTransaction; for (int i = 0; i < tempCache.Count; i++) { BlockPos bP = tempCache[i]; @@ -401,9 +403,18 @@ namespace MCGalaxy MakeInt(time.Hour, 2, 11, ptr); MakeInt(time.Minute, 2, 14, ptr); MakeInt(time.Second, 2, 17, ptr); timeP.Value = date; - xP.Value = x; yP.Value = y; zP.Value = z; - tileP.Value = (bP.flags & 2) != 0 ? Block.custom_block : bP.rawType; - delP.Value = (bP.flags & 1) != 0; + // For NativeParameter, we make the optimisation of avoiding boxing primitive types. + if (!isNative) { + xP.Value = x; yP.Value = y; zP.Value = z; + tileP.Value = (bP.flags & 2) != 0 ? Block.custom_block : bP.rawType; + delP.Value = (bP.flags & 1) != 0; + } else { + ((NativeParameter)xP).U16Value = x; + ((NativeParameter)yP).U16Value = y; + ((NativeParameter)zP).U16Value = z; + ((NativeParameter)tileP).U8Value = (bP.flags & 2) != 0 ? Block.custom_block : bP.rawType; + ((NativeParameter)delP).BoolValue = (bP.flags & 1) != 0; + } if (!BulkTransaction.Execute(template, cmd)) { cmd.Dispose(); diff --git a/Server/Properties.cs b/Server/Properties.cs index 341883e35..58374f57f 100644 --- a/Server/Properties.cs +++ b/Server/Properties.cs @@ -27,38 +27,15 @@ namespace MCGalaxy { public static class SrvProperties { public static void Load(string givenPath, bool skipsalt = false) { - /* - if (!skipsalt) - { - Server.salt = ""; - string rndchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - Random rnd = new Random(); - for (int i = 0; i < 16; ++i) { Server.salt += rndchars[rnd.Next(rndchars.Length)]; } - }*/ - if ( !skipsalt ) { - bool gotSalt = false; - if ( File.Exists("text/salt.txt") ) { - string salt = File.ReadAllText("text/salt.txt"); - if ( salt.Length != 16 ) - Server.s.Log("Invalid salt in salt.txt!"); - else { - Server.salt = salt; - gotSalt = true; - } - } - if ( !gotSalt ) { - RandomNumberGenerator prng = RandomNumberGenerator.Create(); - StringBuilder sb = new StringBuilder(); - byte[] oneChar = new byte[1]; - while ( sb.Length < 16 ) { - prng.GetBytes(oneChar); - if ( Char.IsLetterOrDigit((char)oneChar[0]) ) { - sb.Append((char)oneChar[0]); - } - } - Server.salt = sb.ToString(); - } - } + RandomNumberGenerator prng = RandomNumberGenerator.Create(); + StringBuilder sb = new StringBuilder(); + byte[] oneChar = new byte[1]; + while (sb.Length < 16) { + prng.GetBytes(oneChar); + if (Char.IsLetterOrDigit((char)oneChar[0])) + sb.Append((char)oneChar[0]); + } + Server.salt = sb.ToString(); if (PropertiesFile.Read(givenPath, LineProcessor)) Server.s.SettingsUpdate();