From 4c5e225244643095e4e5a5a653b3a0a71b79b3cd Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Sat, 11 Sep 2021 02:56:47 -0400 Subject: [PATCH 01/12] Create publish script. --- publish.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 publish.py diff --git a/publish.py b/publish.py new file mode 100644 index 00000000..2d4d1912 --- /dev/null +++ b/publish.py @@ -0,0 +1,65 @@ +""" +TheNexusAvenger + +Creates the binaries for distribution. +""" + +PROJECTS = [ + "Uchu.Master", + "Uchu.Instance", + "Uchu.StandardScripts", +] +PLATFORMS = [ + ["Windows-x64", "win-x64"], + ["macOS-x64", "osx-x64"], + ["Linux-x64", "linux-x64"], +] + +import os +import shutil +import subprocess +import sys + + + +# Display a warning for Windows runs. +if os.name == "nt": + sys.stderr.write("Windows was detected. Linux and macOS binaries will be missing the permissions to run.\n") + +# Create the directory. +if os.path.exists("bin"): + shutil.rmtree("bin") +os.mkdir("bin") + +# Compile the releases. +for platform in PLATFORMS: + # Create the base directory. + print("Building Uchu for " + platform[0]) + platformDirectory = "bin/Uchu-" + platform[0] + if os.path.exists(platformDirectory): + shutil.rmtree(platformDirectory) + os.mkdir(platformDirectory) + + for project in PROJECTS: + # Compile the project for the platform. + print("\tExporting " + project + " for " + platform[0]) + buildParameters = ["dotnet", "publish", "-r", platform[1], "-c", "Release", project + "/" + project + ".csproj"] + subprocess.call(buildParameters, stdout=open(os.devnull, "w")) + + # Clear the unwanted files of the compile. + dotNetVersion = os.listdir(project + "/bin/Release/")[0] + outputDirectory = project + "/bin/Release/" + dotNetVersion + "/" + platform[1] + "/publish" + for file in os.listdir(outputDirectory): + if file.endswith(".pdb"): + os.remove(outputDirectory + "/" + file) + + # Copy the files. + for file in os.listdir(outputDirectory): + targetLocation = platformDirectory + "/" + file + if not os.path.exists(targetLocation): + shutil.copy(outputDirectory + "/" + file, targetLocation) + + # Create the archive. + print("\tCreating archive for " + platform[0]) + shutil.make_archive("bin/Uchu-" + platform[0], "zip", platformDirectory) + shutil.rmtree(platformDirectory) \ No newline at end of file From 709ecb8add4b8ab753a03d7ecd4852f3cd9ea5df Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Sat, 11 Sep 2021 03:00:34 -0400 Subject: [PATCH 02/12] Check for Uchu.Instance.dll and Uchu.StandardScripts.dll being in same directory. --- Uchu.Master/MasterServer.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Uchu.Master/MasterServer.cs b/Uchu.Master/MasterServer.cs index 4415a6fc..244ebb65 100644 --- a/Uchu.Master/MasterServer.cs +++ b/Uchu.Master/MasterServer.cs @@ -339,8 +339,14 @@ private static async Task ConfigureAsync() Logger.SetConfiguration(Config); Logger.SetServerTypeInformation("Master"); - // Add default value for script DLL source - Config.DllSource.ScriptDllSource.Add("../../../../Uchu.StandardScripts/bin/Debug/net5.0/Uchu.StandardScripts.dll"); + // Add default value for instance DLL source and script DLL source.. + if (File.Exists("Uchu.Instance.dll")) + { + Config.DllSource.Instance = "Uchu.Instance.dll"; + } + Config.DllSource.ScriptDllSource.Add(File.Exists("Uchu.StandardScripts.dll") + ? "Uchu.StandardScripts.dll" + : "../../../../Uchu.StandardScripts/bin/Debug/net5.0/Uchu.StandardScripts.dll"); // Write config file Config.Save(configFilename); From 5b290a1dc3cff34a45d6d527a69d64df8710024b Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Sat, 11 Sep 2021 03:03:54 -0400 Subject: [PATCH 03/12] Disable Redis by default (no longer mentioned in README). --- Uchu.Core/Config/UchuConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Uchu.Core/Config/UchuConfiguration.cs b/Uchu.Core/Config/UchuConfiguration.cs index 3e901ee5..cfd7fa04 100644 --- a/Uchu.Core/Config/UchuConfiguration.cs +++ b/Uchu.Core/Config/UchuConfiguration.cs @@ -142,7 +142,7 @@ public class CacheConfig /// if no service is installed and the connection will /// always timeout. /// - [XmlElement] public bool UseService { get; set; } = true; + [XmlElement] public bool UseService { get; set; } = false; /// /// Hostname to use when connecting to the cache service From 9b3ae5eff162607ee88ad63960e9e9750e6efae9 Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Sat, 11 Sep 2021 15:00:05 -0400 Subject: [PATCH 04/12] Handle dotnet not being installed. --- Uchu.Master/ServerInstance.cs | 44 +++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/Uchu.Master/ServerInstance.cs b/Uchu.Master/ServerInstance.cs index c4c58ce2..545e69b7 100644 --- a/Uchu.Master/ServerInstance.cs +++ b/Uchu.Master/ServerInstance.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using Uchu.Core; namespace Uchu.Master @@ -18,24 +19,54 @@ public class ServerInstance public int ApiPort { get; set; } - public List Zones { get; set; } + public List Zones { get; set; } = new List(); public bool Ready { get; set; } public ServerInstance(Guid id) { Id = id; - - Zones = new List(); } + /// + /// Starts the server instance. + /// + /// Executable location to use. + /// Location of the dotnet command. public void Start(string location, string dotnet) { + // Determine if the dotnet command should be used. + // If the default (dotnet) is used, the system PATH is checked. var useDotNet = !string.IsNullOrWhiteSpace(dotnet); + if (useDotNet && dotnet?.ToLower() == "dotnet" && !File.Exists(dotnet)) + { + var pathDirectories = (Environment.GetEnvironmentVariable("PATH") ?? "").Split(";"); + var dotNetInPath = pathDirectories.Any(pathDirectory => File.Exists(Path.Combine(pathDirectory, dotnet))); + if (!dotNetInPath) + { + useDotNet = false; + } + } + // Adjust the file name. + // If dotnet isn't used, the file name may need to be corrected to have .exe or no extension. var file = useDotNet ? dotnet : location; + if (!useDotNet && file.ToLower().EndsWith(".dll")) + { + var parentDirectory = Path.GetDirectoryName(file) ?? ""; + var baseFileName = Path.GetFileNameWithoutExtension(file); + var baseFileLocation = Path.Combine(parentDirectory, baseFileName); + if (File.Exists(baseFileLocation + ".exe")) + { + file = baseFileLocation + ".exe"; + } else if (File.Exists(baseFileLocation)) + { + file = baseFileLocation; + } + } - Process = new Process + // Create and start the process. + this.Process = new Process { StartInfo = { @@ -45,11 +76,10 @@ public void Start(string location, string dotnet) RedirectStandardOutput = false, UseShellExecute = true, CreateNoWindow = false, - WindowStyle = ProcessWindowStyle.Normal + WindowStyle = ProcessWindowStyle.Normal, } }; - - Process.Start(); + this.Process.Start(); } } } \ No newline at end of file From 850ee450e65d9275cdc3042dd93d16d45fac566e Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Sun, 12 Sep 2021 17:41:27 +0200 Subject: [PATCH 05/12] Don't rely on folders generated by dotnet --- publish.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/publish.py b/publish.py index 2d4d1912..9cb23cc6 100644 --- a/publish.py +++ b/publish.py @@ -1,5 +1,5 @@ """ -TheNexusAvenger +TheNexusAvenger, enteryournamehere Creates the binaries for distribution. """ @@ -43,23 +43,21 @@ for project in PROJECTS: # Compile the project for the platform. print("\tExporting " + project + " for " + platform[0]) - buildParameters = ["dotnet", "publish", "-r", platform[1], "-c", "Release", project + "/" + project + ".csproj"] + + buildParameters = ["dotnet", "publish", + "--runtime", platform[1], + "--configuration", "Release", + "--output", platformDirectory, + project + "/" + project + ".csproj" + ] subprocess.call(buildParameters, stdout=open(os.devnull, "w")) # Clear the unwanted files of the compile. - dotNetVersion = os.listdir(project + "/bin/Release/")[0] - outputDirectory = project + "/bin/Release/" + dotNetVersion + "/" + platform[1] + "/publish" - for file in os.listdir(outputDirectory): + for file in os.listdir(platformDirectory): if file.endswith(".pdb"): - os.remove(outputDirectory + "/" + file) - - # Copy the files. - for file in os.listdir(outputDirectory): - targetLocation = platformDirectory + "/" + file - if not os.path.exists(targetLocation): - shutil.copy(outputDirectory + "/" + file, targetLocation) + os.remove(platformDirectory + "/" + file) # Create the archive. print("\tCreating archive for " + platform[0]) shutil.make_archive("bin/Uchu-" + platform[0], "zip", platformDirectory) - shutil.rmtree(platformDirectory) \ No newline at end of file + shutil.rmtree(platformDirectory) From 414dce4dd4bf2f0f097f0929d0a485f044a59fbd Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Sun, 12 Sep 2021 17:41:48 +0200 Subject: [PATCH 06/12] Include readme & license --- publish.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/publish.py b/publish.py index 9cb23cc6..2798e06f 100644 --- a/publish.py +++ b/publish.py @@ -57,6 +57,10 @@ if file.endswith(".pdb"): os.remove(platformDirectory + "/" + file) + # Add documentation & license to the output directory. + for file in ["README.md", "Configuration.md", "LICENSE"]: + shutil.copy(file, platformDirectory) + # Create the archive. print("\tCreating archive for " + platform[0]) shutil.make_archive("bin/Uchu-" + platform[0], "zip", platformDirectory) From ffb9f78280f34eabdf75c6a593afbd912d7f6996 Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:01:06 -0400 Subject: [PATCH 07/12] Publish DLLs in lib directory. --- Uchu.Master/MasterServer.cs | 10 +++++----- Uchu.Master/Uchu.Master.csproj | 7 +++++++ publish.py | 15 ++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Uchu.Master/MasterServer.cs b/Uchu.Master/MasterServer.cs index 244ebb65..3132ff50 100644 --- a/Uchu.Master/MasterServer.cs +++ b/Uchu.Master/MasterServer.cs @@ -339,13 +339,13 @@ private static async Task ConfigureAsync() Logger.SetConfiguration(Config); Logger.SetServerTypeInformation("Master"); - // Add default value for instance DLL source and script DLL source.. - if (File.Exists("Uchu.Instance.dll")) + // Add default value for instance DLL source and script DLL source. + if (File.Exists("lib/Uchu.Instance.dll")) { - Config.DllSource.Instance = "Uchu.Instance.dll"; + Config.DllSource.Instance = "lib/Uchu.Instance.dll"; } - Config.DllSource.ScriptDllSource.Add(File.Exists("Uchu.StandardScripts.dll") - ? "Uchu.StandardScripts.dll" + Config.DllSource.ScriptDllSource.Add(File.Exists("lib/Uchu.StandardScripts.dll") + ? "lib/Uchu.StandardScripts.dll" : "../../../../Uchu.StandardScripts/bin/Debug/net5.0/Uchu.StandardScripts.dll"); // Write config file diff --git a/Uchu.Master/Uchu.Master.csproj b/Uchu.Master/Uchu.Master.csproj index 8091ebb3..9233b280 100644 --- a/Uchu.Master/Uchu.Master.csproj +++ b/Uchu.Master/Uchu.Master.csproj @@ -4,6 +4,9 @@ Exe net5.0 8 + lib + True + True @@ -11,4 +14,8 @@ + + + + diff --git a/publish.py b/publish.py index 2798e06f..0119b7c2 100644 --- a/publish.py +++ b/publish.py @@ -9,6 +9,10 @@ "Uchu.Instance", "Uchu.StandardScripts", ] +DIRECTORY_ADDITIONS = { + "Uchu.Instance": "/lib", + "Uchu.StandardScripts": "/lib", +} PLATFORMS = [ ["Windows-x64", "win-x64"], ["macOS-x64", "osx-x64"], @@ -44,18 +48,19 @@ # Compile the project for the platform. print("\tExporting " + project + " for " + platform[0]) + outputDirectory = platformDirectory + (project in DIRECTORY_ADDITIONS.keys() and DIRECTORY_ADDITIONS[project] or "") buildParameters = ["dotnet", "publish", "--runtime", platform[1], "--configuration", "Release", - "--output", platformDirectory, + "--output", outputDirectory, project + "/" + project + ".csproj" ] subprocess.call(buildParameters, stdout=open(os.devnull, "w")) # Clear the unwanted files of the compile. - for file in os.listdir(platformDirectory): - if file.endswith(".pdb"): - os.remove(platformDirectory + "/" + file) + for file in os.listdir(outputDirectory): + if file.endswith(".pdb") or file.endswith(".bak"): + os.remove(outputDirectory + "/" + file) # Add documentation & license to the output directory. for file in ["README.md", "Configuration.md", "LICENSE"]: @@ -64,4 +69,4 @@ # Create the archive. print("\tCreating archive for " + platform[0]) shutil.make_archive("bin/Uchu-" + platform[0], "zip", platformDirectory) - shutil.rmtree(platformDirectory) + shutil.rmtree(platformDirectory, True) From 31c92435699bdeb17302991006a73433381c8557 Mon Sep 17 00:00:00 2001 From: TheNexusAvenger <13441476+TheNexusAvenger@users.noreply.github.com> Date: Wed, 15 Sep 2021 00:02:14 -0400 Subject: [PATCH 08/12] Change default log level to Information for releases. --- Uchu.Core/Config/UchuConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Uchu.Core/Config/UchuConfiguration.cs b/Uchu.Core/Config/UchuConfiguration.cs index cfd7fa04..c2c50972 100644 --- a/Uchu.Core/Config/UchuConfiguration.cs +++ b/Uchu.Core/Config/UchuConfiguration.cs @@ -42,7 +42,7 @@ public class UchuConfiguration [XmlElement] public LoggingConfiguration ConsoleLogging { get; set; } = new LoggingConfiguration { - Level = LogLevel.Debug.ToString() + Level = LogLevel.Information.ToString() }; /// From d66adc3cf3c69894d68aa5f56d96c98960828330 Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Wed, 15 Sep 2021 10:00:22 +0200 Subject: [PATCH 09/12] Use dict.get() --- publish.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/publish.py b/publish.py index 0119b7c2..ac2f882e 100644 --- a/publish.py +++ b/publish.py @@ -48,7 +48,7 @@ # Compile the project for the platform. print("\tExporting " + project + " for " + platform[0]) - outputDirectory = platformDirectory + (project in DIRECTORY_ADDITIONS.keys() and DIRECTORY_ADDITIONS[project] or "") + outputDirectory = platformDirectory + DIRECTORY_ADDITIONS.get(project, "") buildParameters = ["dotnet", "publish", "--runtime", platform[1], "--configuration", "Release", From ef5b6f6ce4404c6f6b8f632d0ec8654e519ba22e Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Wed, 15 Sep 2021 10:54:14 +0200 Subject: [PATCH 10/12] Increase timeout to prevent exception --- Uchu.Core/Cache/DatabaseCache.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Uchu.Core/Cache/DatabaseCache.cs b/Uchu.Core/Cache/DatabaseCache.cs index 289a58b1..1f64ee83 100644 --- a/Uchu.Core/Cache/DatabaseCache.cs +++ b/Uchu.Core/Cache/DatabaseCache.cs @@ -95,7 +95,7 @@ public async Task GetSessionAsync(IPEndPoint endpoint) await using var ctx = new UchuContext(); string key; - var timeout = 1000; + var timeout = 5000; while (!_keys.TryGetValue(endpoint.ToString(), out key)) { @@ -160,4 +160,4 @@ public void Dispose() _rng.Dispose(); } } -} \ No newline at end of file +} From 6dd44311ef678fd62224e47e2349ae84d75e413e Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Wed, 15 Sep 2021 10:54:39 +0200 Subject: [PATCH 11/12] Get rid of warnings --- Uchu.Char/Packets/Client/CharacterListRequest.cs | 8 +++++++- Uchu.Core/UchuServer.cs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Uchu.Char/Packets/Client/CharacterListRequest.cs b/Uchu.Char/Packets/Client/CharacterListRequest.cs index 2d9869e0..a9b2caf0 100644 --- a/Uchu.Char/Packets/Client/CharacterListRequest.cs +++ b/Uchu.Char/Packets/Client/CharacterListRequest.cs @@ -1,3 +1,4 @@ +using RakDotNet.IO; using Uchu.Core; namespace Uchu.Char @@ -7,5 +8,10 @@ public class CharacterListRequest : Packet public override RemoteConnectionType RemoteConnectionType => RemoteConnectionType.Client; public override uint PacketId => 0x2; + + public override void Deserialize(BitReader reader) + { + + } } -} \ No newline at end of file +} diff --git a/Uchu.Core/UchuServer.cs b/Uchu.Core/UchuServer.cs index c843d8a1..dd7818ee 100644 --- a/Uchu.Core/UchuServer.cs +++ b/Uchu.Core/UchuServer.cs @@ -717,7 +717,7 @@ private static async Task InvokeHandlerAsync(Handler handler, object packet, IRa if (task && res != null) await ((Task) res).ConfigureAwait(false); if (res == null) - Logger.Warning($"Handler {handler.GetType().FullName} returned null for {endPoint}."); + Logger.Debug($"Handler {handler.GetType().FullName} returned null for {endPoint}."); } } } From 924418b34a6155fba5a1a7a49f6317406ab2e6cb Mon Sep 17 00:00:00 2001 From: enteryournamehere <11255568+enteryournamehere@users.noreply.github.com> Date: Wed, 15 Sep 2021 11:16:56 +0200 Subject: [PATCH 12/12] Save NLUL client location to config --- Uchu.Master/MasterServer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Uchu.Master/MasterServer.cs b/Uchu.Master/MasterServer.cs index 3132ff50..560511aa 100644 --- a/Uchu.Master/MasterServer.cs +++ b/Uchu.Master/MasterServer.cs @@ -371,6 +371,7 @@ private static async Task ConfigureAsync() try { Config.ResourcesConfiguration.GameResourceFolder = FindNlulClientResources(); + Config.Save(configFilename); Logger.Information($"Using automatically detected client resource folder: {Config.ResourcesConfiguration.GameResourceFolder}"); } catch