diff --git a/MultiAdmin/Config/Config.cs b/MultiAdmin/Config/Config.cs index 6778c33..133de2e 100644 --- a/MultiAdmin/Config/Config.cs +++ b/MultiAdmin/Config/Config.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Text; using MultiAdmin.ConsoleTools; +using MultiAdmin.ServerIO; using MultiAdmin.Utility; namespace MultiAdmin.Config @@ -241,5 +242,22 @@ public bool GetBool(string key, bool def = false) return def; } + + public InputHandler.ConsoleInputSystem GetConsoleInputSystem(string key, InputHandler.ConsoleInputSystem def = InputHandler.ConsoleInputSystem.New) + { + try + { + string value = GetString(key); + + if (!string.IsNullOrEmpty(value) && Enum.TryParse(value, out var consoleInputSystem)) + return consoleInputSystem; + } + catch (Exception e) + { + Program.LogDebugException(nameof(GetConsoleInputSystem), e); + } + + return def; + } } } diff --git a/MultiAdmin/Config/MultiAdminConfig.cs b/MultiAdmin/Config/MultiAdminConfig.cs index 28a6e14..7911b7e 100644 --- a/MultiAdmin/Config/MultiAdminConfig.cs +++ b/MultiAdmin/Config/MultiAdminConfig.cs @@ -52,7 +52,11 @@ public class MultiAdminConfig : InheritableConfigRegister public ConfigEntry UseNewInputSystem { get; } = new ConfigEntry("use_new_input_system", true, - "Use New Input System", "Whether to use the new input system, if false, the original input system will be used"); + "Use New Input System", "**OBSOLETE: Use `console_input_system` instead, this config option may be removed in a future version of MultiAdmin.** Whether to use the new input system, if false, the original input system will be used"); + + public ConfigEntry ConsoleInputSystem { get; } = + new ConfigEntry("console_input_system", InputHandler.ConsoleInputSystem.New, + "Console Input System", "Which console input system to use"); public ConfigEntry HideInput { get; } = new ConfigEntry("hide_input", false, @@ -172,6 +176,26 @@ public class MultiAdminConfig : InheritableConfigRegister #endregion + public InputHandler.ConsoleInputSystem ActualConsoleInputSystem + { + get + { + if (UseNewInputSystem.Value) + { + switch (ConsoleInputSystem.Value) + { + case InputHandler.ConsoleInputSystem.New: + return HideInput.Value ? InputHandler.ConsoleInputSystem.Old : InputHandler.ConsoleInputSystem.New; + + case InputHandler.ConsoleInputSystem.Old: + return InputHandler.ConsoleInputSystem.Old; + } + } + + return InputHandler.ConsoleInputSystem.Original; + } + } + public const string ConfigFileName = "scp_multiadmin.cfg"; public static readonly string GlobalConfigFilePath = Utils.GetFullPathSafe(ConfigFileName); @@ -299,6 +323,12 @@ public override void UpdateConfigValueInheritable(ConfigEntry configEntry) break; } + case ConfigEntry config: + { + config.Value = Config.GetConsoleInputSystem(config.Key, config.Default); + break; + } + default: { throw new ArgumentException( diff --git a/MultiAdmin/Features/GithubGenerator.cs b/MultiAdmin/Features/GithubGenerator.cs index 156532c..3da39b2 100644 --- a/MultiAdmin/Features/GithubGenerator.cs +++ b/MultiAdmin/Features/GithubGenerator.cs @@ -4,6 +4,7 @@ using MultiAdmin.Config; using MultiAdmin.Config.ConfigHandler; using MultiAdmin.Features.Attributes; +using MultiAdmin.ServerIO; using MultiAdmin.Utility; namespace MultiAdmin.Features @@ -122,6 +123,12 @@ public void OnCall(string[] args) break; } + case ConfigEntry config: + { + stringBuilder.Append($"ConsoleInputSystem{ColumnSeparator}{config.Default}"); + break; + } + default: { stringBuilder.Append( diff --git a/MultiAdmin/Program.cs b/MultiAdmin/Program.cs index 5d24ef2..b96fcf9 100644 --- a/MultiAdmin/Program.cs +++ b/MultiAdmin/Program.cs @@ -80,8 +80,7 @@ public static void Write(string message, ConsoleColor color = ConsoleColor.DarkY { if (Headless) return; - new ColoredMessage(Utils.TimeStampMessage(message), color).WriteLine((!MultiAdminConfig.GlobalConfig?.HideInput?.Value ?? false) && - (MultiAdminConfig.GlobalConfig?.UseNewInputSystem?.Value ?? false)); + new ColoredMessage(Utils.TimeStampMessage(message), color).WriteLine(MultiAdminConfig.GlobalConfig?.ActualConsoleInputSystem == InputHandler.ConsoleInputSystem.New); } } diff --git a/MultiAdmin/Server.cs b/MultiAdmin/Server.cs index 11fb793..e1f1873 100644 --- a/MultiAdmin/Server.cs +++ b/MultiAdmin/Server.cs @@ -388,6 +388,9 @@ public void StartServer(bool restartOnCrash = true) Write($"Starting server with the following parameters:\n{scpslExe} {startInfo.Arguments}"); + if (ServerConfig.ActualConsoleInputSystem == InputHandler.ConsoleInputSystem.Original) + Write("You are using the original input system. It may prevent MultiAdmin from closing and/or cause ghost game processes", ConsoleColor.Red); + // Reset the supported mod features supportedModFeatures = ModFeatures.None; @@ -650,10 +653,10 @@ public void Write(ColoredMessage[] messages, ConsoleColor? timeStampColor = null ColoredMessage[] timeStampedMessage = Utils.TimeStampMessage(messages, timeStampColor); - timeStampedMessage.WriteLine(!ServerConfig.HideInput.Value && ServerConfig.UseNewInputSystem.Value); + timeStampedMessage.WriteLine(ServerConfig.ActualConsoleInputSystem == InputHandler.ConsoleInputSystem.New); - if (!ServerConfig.HideInput.Value && ServerConfig.UseNewInputSystem.Value) - InputHandler.WriteInputAndSetCursor(ServerConfig); + if (ServerConfig.ActualConsoleInputSystem == InputHandler.ConsoleInputSystem.New) + InputHandler.WriteInputAndSetCursor(true); } } diff --git a/MultiAdmin/ServerIO/InputHandler.cs b/MultiAdmin/ServerIO/InputHandler.cs index cd00f46..4888a65 100644 --- a/MultiAdmin/ServerIO/InputHandler.cs +++ b/MultiAdmin/ServerIO/InputHandler.cs @@ -4,7 +4,6 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using MultiAdmin.Config; using MultiAdmin.ConsoleTools; using MultiAdmin.Utility; @@ -61,14 +60,18 @@ public static async void Write(Server server, CancellationToken cancellationToke } string message; - if (!server.ServerConfig.HideInput.Value && server.ServerConfig.UseNewInputSystem.Value && SectionBufferWidth - TotalIndicatorLength > 0) + if (server.ServerConfig.ActualConsoleInputSystem == ConsoleInputSystem.New && SectionBufferWidth - TotalIndicatorLength > 0) { message = await GetInputLineNew(server, cancellationToken, prevMessages); } - else + else if (server.ServerConfig.ActualConsoleInputSystem == ConsoleInputSystem.Old) { message = await GetInputLineOld(server, cancellationToken); } + else + { + message = Console.ReadLine(); + } if (string.IsNullOrEmpty(message)) continue; @@ -252,8 +255,7 @@ public static async Task GetInputLineNew(Server server, CancellationToke SetCurrentInput(curSection.Value.Section); CurrentCursor = curSection.Value.GetRelativeIndex(messageCursor); - - WriteInputAndSetCursor(server.ServerConfig); + WriteInputAndSetCursor(true); } else { @@ -267,7 +269,7 @@ public static async Task GetInputLineNew(Server server, CancellationToke SetCurrentInput(message); CurrentCursor = messageCursor; - WriteInputAndSetCursor(server.ServerConfig); + WriteInputAndSetCursor(true); } } else if (CurrentCursor != messageCursor) @@ -291,7 +293,7 @@ public static async Task GetInputLineNew(Server server, CancellationToke SetCurrentInput(curSection.Value.Section); - WriteInputAndSetCursor(server.ServerConfig); + WriteInputAndSetCursor(true); } // Otherwise, if only the relative cursor index has changed, set only the cursor @@ -400,29 +402,28 @@ public static void SetCursor() SetCursor(CurrentCursor); } - public static void WriteInput(ColoredMessage[] message, MultiAdminConfig config = null) + public static void WriteInput(ColoredMessage[] message, bool clearConsoleLine = false) { lock (ColoredConsole.WriteLock) { if (Program.Headless) return; - MultiAdminConfig curConfig = config ?? MultiAdminConfig.GlobalConfig; - message?.Write(!curConfig.HideInput.Value && curConfig.UseNewInputSystem.Value); + message?.Write(clearConsoleLine); CurrentInput = message; } } - public static void WriteInput(MultiAdminConfig config = null) + public static void WriteInput(bool clearConsoleLine = false) { - WriteInput(CurrentInput, config); + WriteInput(CurrentInput, clearConsoleLine); } - public static void WriteInputAndSetCursor(MultiAdminConfig config = null) + public static void WriteInputAndSetCursor(bool clearConsoleLine = false) { lock (ColoredConsole.WriteLock) { - WriteInput(config); + WriteInput(clearConsoleLine); SetCursor(); } } @@ -450,5 +451,16 @@ public static void RandomizeInputColors() Program.LogDebugException(nameof(RandomizeInputColors), e); } } + + public enum ConsoleInputSystem + { + // Represents the default input system, which calls Console.ReadLine and blocks the calling context + Original, + // Represents the "old" input system, which calls non-blocking methods + Old, + // Represents the "new" input system, which also calls non-blocking methods, + // but the main difference is great display + New, + } } } diff --git a/README.md b/README.md index 676f4c0..9b640c5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Make sure that you are running Mono 5.18.0 or higher, otherwise you might have i 4. Optional: Create a file named `scp_multiadmin.cfg` within your server's folder for configuring MultiAdmin specifically for that server ## Features + - Config Generator: Generates a full default MultiAdmin config file - Config Reload: Reloads the MultiAdmin configuration file - Exit Command: Adds a graceful exit command @@ -71,7 +72,8 @@ multiadmin_nolog | Boolean | False | Disable logging to file multiadmin_debug_log | Boolean | True | Enables MultiAdmin debug logging, this logs to a separate file than any other logs multiadmin_debug_log_blacklist | String List | HandleMessage, StringMatches, MessageListener | Which tags to block for MultiAdmin debug logging multiadmin_debug_log_whitelist | String List | **Empty** | Which tags to log for MultiAdmin debug logging (Defaults to logging all if none are provided) -use_new_input_system | Boolean | True | Whether to use the new input system, if false, the original input system will be used +use_new_input_system | Boolean | True | **OBSOLETE: Use `console_input_system` instead, this config option may be removed in a future version of MultiAdmin.** Whether to use the new input system, if false, the original input system will be used +console_input_system | ConsoleInputSystem | New | Which console input system to use hide_input | Boolean | False | Whether to hide console input, if true, typed input will not be printed port | Unsigned Integer | 7777 | The port for the server to use copy_from_folder_on_reload | String | **Empty** | The location of a folder to copy files from into the folder defined by `config_location` whenever the configuration file is reloaded @@ -101,3 +103,12 @@ multiadmin_tick_delay | Integer | 1000 | The time in milliseconds between MultiA servers_folder | String | servers | The location of the `servers` folder for MultiAdmin to load multiple server configurations from set_title_bar | Boolean | True | Whether to set the console window's titlebar, if false, this feature won't be used start_config_on_full | String | **Empty** | Start server with this config folder once the server becomes full [Requires Modding] + +## ConsoleInputSystem +If you are running into issues with the `tmux send-keys` command, switch to the original input system. + +String Value | Integer Value | Description +--- | :---: | :----: +Original | 0 | Represents the original input system. It may prevent MultiAdmin from closing and/or cause ghost game processes. +Old | 1 | Represents the old input system. This input system should operate similarly to the original input system but won't cause issues with MultiAdmin's functionality. +New | 2 | Represents the new input system. The main difference from the original input system is an improved display.