diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 245dd15b..da7cbc92 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -228,6 +228,7 @@ namespace MinecraftClient SessionToken _sessionToken; CancellationTokenSource? cmdprompt = null; Tuple? timeoutdetector = null; + private Thread? basicIOReadThread; private int transferInProgress = 0; private bool consoleReadThreadOwned = false; private bool consoleHandlersAttached = false; @@ -527,6 +528,23 @@ namespace MinecraftClient { cmdprompt = new CancellationTokenSource(); + if (ConsoleIO.BasicIO || ConsoleIO.Backend is null) + { + if (!consoleReadThreadOwned) + { + CancellationToken token = cmdprompt.Token; + basicIOReadThread = new Thread(() => BasicIOReadLoop(token)) + { + IsBackground = true, + Name = "MCC BasicIO read thread" + }; + basicIOReadThread.Start(); + consoleReadThreadOwned = true; + } + + return; + } + if (!consoleReadThreadOwned) { ConsoleIO.Backend.BeginReadThread(); @@ -543,6 +561,15 @@ namespace MinecraftClient private void StopConsoleSession() { + if (ConsoleIO.BasicIO || ConsoleIO.Backend is null) + { + cmdprompt?.Cancel(); + basicIOReadThread = null; + consoleReadThreadOwned = false; + consoleHandlersAttached = false; + return; + } + if (consoleHandlersAttached) { ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived; @@ -557,6 +584,19 @@ namespace MinecraftClient } } + private void BasicIOReadLoop(CancellationToken token) + { + while (!token.IsCancellationRequested) + { + string? input = Console.ReadLine(); + if (input is null) + return; + + if (!token.IsCancellationRequested) + ConsoleReaderOnMessageReceived(this, input); + } + } + private void ResetStateForTransfer() { ClearTasks(); diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 78c6cde9..0a6b26cf 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -550,7 +550,7 @@ namespace MinecraftClient.Protocol.Handlers if (Settings.Config.Logging.DebugMessages) ConsoleIO.WriteLineFormatted("§8" + Translations.debug_crypto, acceptnewlines: true); - if (serverIDhash != "-") + if (serverIDhash != "-" && !string.IsNullOrWhiteSpace(sessionID)) { ConsoleIO.WriteLine(Translations.mcc_session); string serverHash = CryptoHandler.GetServerHash(serverIDhash, serverPublicKey, secretKey); diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 192dc451..bfb7faa3 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -4258,7 +4258,7 @@ namespace MinecraftClient.Protocol.Handlers log.Debug($"§8{Translations.debug_crypto}"); - if (serverIDhash != "-") + if (serverIDhash != "-" && !string.IsNullOrWhiteSpace(sessionID)) { log.Info(Translations.mcc_session);