From 8006fa20df642547bd0299979a1147215e8c964e Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 14 Feb 2021 18:30:53 -0800 Subject: [PATCH] fix(core): Fixes errors from missing files (#511) --- .../Buffers/CircularBufferReaderTests.cs | 19 ++++++++++--------- .../Configuration/ServerConfiguration.cs | 2 +- Projects/Server/Main.cs | 8 +++++++- Projects/Server/Maps/MapLoader.cs | 5 +++++ Projects/Server/Regions/RegionLoader.cs | 5 +++++ .../Commands/Object Creation/CAGLoader.cs | 5 +++++ .../Configuration/EmailConfiguration.cs | 3 ++- Projects/UOContent/Gumps/Go/LocationTree.cs | 5 +++++ Projects/UOContent/Misc/NameList.cs | 7 +++++++ Projects/UOContent/Misc/ShrinkTable.cs | 9 +++++++-- 10 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs b/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs index 8ca445382..ebed95b1d 100644 --- a/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs +++ b/Projects/Server.Tests/Tests/Buffers/CircularBufferReaderTests.cs @@ -10,41 +10,42 @@ namespace Server.Tests.Network { [Theory] [InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 0)] - [InlineData("Test String", "utf-u", false, -1, 1024, 1024, 0)] + [InlineData("Test String", "utf-8", false, -1, 1024, 1024, 0)] [InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 0)] [InlineData("Test String", "utf-16", false, -1, 1024, 1024, 0)] [InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 1030)] - [InlineData("Test String", "utf-u", false, -1, 1024, 1024, 1030)] + [InlineData("Test String", "utf-8", false, -1, 1024, 1024, 1030)] [InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 1030)] [InlineData("Test String", "utf-16", false, -1, 1024, 1024, 1030)] [InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 1020)] - [InlineData("Test String", "utf-u", false, -1, 1024, 1024, 1020)] + [InlineData("Test String", "utf-8", false, -1, 1024, 1024, 1020)] [InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 1020)] [InlineData("Test String", "utf-16", false, -1, 1024, 1024, 1020)] [InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 0)] - [InlineData("Test String", "utf-u", false, 8, 1024, 1024, 0)] + [InlineData("Test String", "utf-8", false, 8, 1024, 1024, 0)] [InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 0)] [InlineData("Test String", "utf-16", false, 8, 1024, 1024, 0)] [InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 1030)] - [InlineData("Test String", "utf-u", false, 8, 1024, 1024, 1030)] + [InlineData("Test String", "utf-8", false, 8, 1024, 1024, 1030)] [InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 1030)] [InlineData("Test String", "utf-16", false, 8, 1024, 1024, 1030)] [InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 1020)] - [InlineData("Test String", "utf-u", false, 8, 1024, 1024, 1020)] + [InlineData("Test String", "utf-8", false, 8, 1024, 1024, 1020)] [InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 1020)] [InlineData("Test String", "utf-16", false, 8, 1024, 1024, 1020)] [InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 0)] - [InlineData("Test String", "utf-u", false, 20, 1024, 1024, 0)] + [InlineData("Test String", "utf-8", false, 20, 1024, 1024, 0)] [InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 0)] [InlineData("Test String", "utf-16", false, 20, 1024, 1024, 0)] [InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 1030)] - [InlineData("Test String", "utf-u", false, 20, 1024, 1024, 1030)] + [InlineData("Test String", "utf-8", false, 20, 1024, 1024, 1030)] [InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 1030)] [InlineData("Test String", "utf-16", false, 20, 1024, 1024, 1030)] [InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 1020)] - [InlineData("Test String", "utf-u", false, 20, 1024, 1024, 1020)] + [InlineData("Test String", "utf-8", false, 20, 1024, 1024, 1020)] [InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 1020)] [InlineData("Test String", "utf-16", false, 20, 1024, 1024, 1020)] + [InlineData("测试", "utf-8", true, -1, 1024, 1024, 0)] public void TestReadString( string value, string encodingStr, diff --git a/Projects/Server/Configuration/ServerConfiguration.cs b/Projects/Server/Configuration/ServerConfiguration.cs index 88a53300e..9a0739445 100644 --- a/Projects/Server/Configuration/ServerConfiguration.cs +++ b/Projects/Server/Configuration/ServerConfiguration.cs @@ -176,7 +176,7 @@ namespace Server Utility.PushColor(ConsoleColor.Red); Console.WriteLine("failed"); Utility.PopColor(); - throw new Exception("Core: Server configuration failed to deserialize."); + throw new FileNotFoundException($"Failed to deserialize {m_FilePath}."); } Console.WriteLine("done"); diff --git a/Projects/Server/Main.cs b/Projects/Server/Main.cs index eafc01d00..4ced23a24 100644 --- a/Projects/Server/Main.cs +++ b/Projects/Server/Main.cs @@ -22,6 +22,7 @@ using System.Runtime; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; +using System.Text.Json; using System.Threading; using System.Threading.Tasks; using Server.Json; @@ -445,7 +446,12 @@ namespace Server var assemblyPath = Path.Join(BaseDirectory, AssembliesConfiguration); // Load UOContent.dll - var assemblyFiles = JsonConfig.Deserialize>(assemblyPath).ToArray(); + var assemblyFiles = JsonConfig.Deserialize>(assemblyPath)?.ToArray(); + if (assemblyFiles == null) + { + throw new JsonException($"Failed to deserialize {assemblyPath}."); + } + for (var i = 0; i < assemblyFiles.Length; i++) { assemblyFiles[i] = Path.Join(BaseDirectory, "Assemblies", assemblyFiles[i]); diff --git a/Projects/Server/Maps/MapLoader.cs b/Projects/Server/Maps/MapLoader.cs index ad93b00f6..2fb146daf 100644 --- a/Projects/Server/Maps/MapLoader.cs +++ b/Projects/Server/Maps/MapLoader.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Text.Json; using System.Text.Json.Serialization; using Server.Json; @@ -51,6 +52,10 @@ namespace Server var stopwatch = Stopwatch.StartNew(); var maps = JsonConfig.Deserialize>(path); + if (maps == null) + { + throw new JsonException($"Failed to deserialize {path}."); + } foreach (var def in maps) { diff --git a/Projects/Server/Regions/RegionLoader.cs b/Projects/Server/Regions/RegionLoader.cs index 06a5c87b4..ae9251f84 100644 --- a/Projects/Server/Regions/RegionLoader.cs +++ b/Projects/Server/Regions/RegionLoader.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Text.Json; using Server.Json; using Server.Utilities; @@ -35,6 +36,10 @@ namespace Server var stopwatch = Stopwatch.StartNew(); var regions = JsonConfig.Deserialize>(path); + if (regions == null) + { + throw new JsonException($"Failed to deserialize {path}."); + } foreach (var json in regions) { diff --git a/Projects/UOContent/Commands/Object Creation/CAGLoader.cs b/Projects/UOContent/Commands/Object Creation/CAGLoader.cs index b2dc4a603..47c54071f 100644 --- a/Projects/UOContent/Commands/Object Creation/CAGLoader.cs +++ b/Projects/UOContent/Commands/Object Creation/CAGLoader.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.Json; using System.Text.Json.Serialization; using Server.Items; using Server.Json; @@ -31,6 +32,10 @@ namespace Server.Commands var path = Path.Combine(Core.BaseDirectory, "Data/categorization.json"); var list = JsonConfig.Deserialize>(path); + if (list == null) + { + throw new JsonException($"Failed to deserialize {path}."); + } // Not an optimized solution foreach (var cag in list) diff --git a/Projects/UOContent/Configuration/EmailConfiguration.cs b/Projects/UOContent/Configuration/EmailConfiguration.cs index 05d715823..32bce55ce 100644 --- a/Projects/UOContent/Configuration/EmailConfiguration.cs +++ b/Projects/UOContent/Configuration/EmailConfiguration.cs @@ -15,6 +15,7 @@ using System; using System.IO; +using System.Text.Json; using System.Text.Json.Serialization; using MimeKit; using Server.Json; @@ -52,7 +53,7 @@ namespace Server.Configurations Utility.PushColor(ConsoleColor.Red); Console.WriteLine("failed"); Utility.PopColor(); - throw new Exception("Core: Email configuration failed to deserialize."); + throw new JsonException($"Failed to deserialize {path}."); } Console.WriteLine("done"); diff --git a/Projects/UOContent/Gumps/Go/LocationTree.cs b/Projects/UOContent/Gumps/Go/LocationTree.cs index 9154a382e..defd4908d 100644 --- a/Projects/UOContent/Gumps/Go/LocationTree.cs +++ b/Projects/UOContent/Gumps/Go/LocationTree.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.Json; using Server.Json; namespace Server.Gumps @@ -23,6 +24,10 @@ namespace Server.Gumps try { Root = JsonConfig.Deserialize(path); + if (Root == null) + { + throw new JsonException($"Failed to deserialize {path}."); + } SetParents(Root); } catch (Exception e) diff --git a/Projects/UOContent/Misc/NameList.cs b/Projects/UOContent/Misc/NameList.cs index 065fc9739..9de9e2a71 100644 --- a/Projects/UOContent/Misc/NameList.cs +++ b/Projects/UOContent/Misc/NameList.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.Json; using System.Text.Json.Serialization; using Server.Json; @@ -44,6 +45,12 @@ namespace Server var filePath = Path.Combine(Core.BaseDirectory, "Data/names.json"); var nameLists = JsonConfig.Deserialize>(filePath); + + if (nameLists == null) + { + throw new JsonException($"Failed to deserialize {filePath}."); + } + foreach (var nameList in nameLists) { nameList.FixNames(); diff --git a/Projects/UOContent/Misc/ShrinkTable.cs b/Projects/UOContent/Misc/ShrinkTable.cs index 2aad42a5d..dbb8a6a64 100644 --- a/Projects/UOContent/Misc/ShrinkTable.cs +++ b/Projects/UOContent/Misc/ShrinkTable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Text.Json; using Server.Json; namespace Server @@ -28,8 +29,12 @@ namespace Server private static int[] Load() { - var table = JsonConfig.Deserialize>("Data/shrink.json") - ?? new Dictionary(); + var path = "Data/shrink.json"; + var table = JsonConfig.Deserialize>(path); + if (table == null) + { + throw new JsonException($"Failed to deserialize {path}."); + } int length = 0;