mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
fixed the MCC incorrectly restarts the console input reader after transfer in classic mode.
This commit is contained in:
parent
0e15806722
commit
e0b21dd1d2
1 changed files with 42 additions and 20 deletions
|
|
@ -229,6 +229,8 @@ namespace MinecraftClient
|
||||||
CancellationTokenSource? cmdprompt = null;
|
CancellationTokenSource? cmdprompt = null;
|
||||||
Tuple<Thread, CancellationTokenSource>? timeoutdetector = null;
|
Tuple<Thread, CancellationTokenSource>? timeoutdetector = null;
|
||||||
private int transferInProgress = 0;
|
private int transferInProgress = 0;
|
||||||
|
private bool consoleReadThreadOwned = false;
|
||||||
|
private bool consoleHandlersAttached = false;
|
||||||
|
|
||||||
public ILogger Log;
|
public ILogger Log;
|
||||||
|
|
||||||
|
|
@ -328,10 +330,7 @@ namespace MinecraftClient
|
||||||
|
|
||||||
Log.Info(string.Format(Translations.mcc_joined, Config.Main.Advanced.InternalCmdChar.ToLogString()));
|
Log.Info(string.Format(Translations.mcc_joined, Config.Main.Advanced.InternalCmdChar.ToLogString()));
|
||||||
|
|
||||||
cmdprompt = new CancellationTokenSource();
|
StartConsoleSession();
|
||||||
ConsoleIO.Backend.BeginReadThread();
|
|
||||||
ConsoleIO.Backend.MessageReceived += ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange += ConsoleIO.AutocompleteHandler;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -373,9 +372,7 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
else if (InternalConfig.InteractiveMode)
|
else if (InternalConfig.InteractiveMode)
|
||||||
{
|
{
|
||||||
ConsoleIO.Backend.StopReadThread();
|
StopConsoleSession();
|
||||||
ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
|
||||||
Program.HandleFailure();
|
Program.HandleFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,9 +390,7 @@ namespace MinecraftClient
|
||||||
// kick messages and Ignore_Kick_Message is false, or retry limit reached)
|
// kick messages and Ignore_Kick_Message is false, or retry limit reached)
|
||||||
if (InternalConfig.InteractiveMode)
|
if (InternalConfig.InteractiveMode)
|
||||||
{
|
{
|
||||||
ConsoleIO.Backend.StopReadThread();
|
StopConsoleSession();
|
||||||
ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
|
||||||
Program.HandleFailure();
|
Program.HandleFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -456,10 +451,7 @@ namespace MinecraftClient
|
||||||
UpdateKeepAlive();
|
UpdateKeepAlive();
|
||||||
Log.Info($"Successfully transferred connection and logged in to {resolvedHost}:{resolvedPort}.");
|
Log.Info($"Successfully transferred connection and logged in to {resolvedHost}:{resolvedPort}.");
|
||||||
|
|
||||||
cmdprompt = new CancellationTokenSource();
|
StartConsoleSession();
|
||||||
ConsoleIO.Backend.BeginReadThread();
|
|
||||||
ConsoleIO.Backend.MessageReceived += ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange += ConsoleIO.AutocompleteHandler;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -503,9 +495,7 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
else if (InternalConfig.InteractiveMode)
|
else if (InternalConfig.InteractiveMode)
|
||||||
{
|
{
|
||||||
ConsoleIO.Backend.StopReadThread();
|
StopConsoleSession();
|
||||||
ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
|
||||||
Program.HandleFailure();
|
Program.HandleFailure();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -531,6 +521,40 @@ namespace MinecraftClient
|
||||||
port = resolvedPort;
|
port = resolvedPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void StartConsoleSession()
|
||||||
|
{
|
||||||
|
cmdprompt = new CancellationTokenSource();
|
||||||
|
|
||||||
|
if (!consoleReadThreadOwned)
|
||||||
|
{
|
||||||
|
ConsoleIO.Backend.BeginReadThread();
|
||||||
|
consoleReadThreadOwned = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!consoleHandlersAttached)
|
||||||
|
{
|
||||||
|
ConsoleIO.Backend.MessageReceived += ConsoleReaderOnMessageReceived;
|
||||||
|
ConsoleIO.Backend.OnInputChange += ConsoleIO.AutocompleteHandler;
|
||||||
|
consoleHandlersAttached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopConsoleSession()
|
||||||
|
{
|
||||||
|
if (consoleHandlersAttached)
|
||||||
|
{
|
||||||
|
ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived;
|
||||||
|
ConsoleIO.Backend.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
||||||
|
consoleHandlersAttached = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consoleReadThreadOwned)
|
||||||
|
{
|
||||||
|
ConsoleIO.Backend.StopReadThread();
|
||||||
|
consoleReadThreadOwned = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ResetStateForTransfer()
|
private void ResetStateForTransfer()
|
||||||
{
|
{
|
||||||
ClearTasks();
|
ClearTasks();
|
||||||
|
|
@ -893,9 +917,7 @@ namespace MinecraftClient
|
||||||
|
|
||||||
if (!will_restart)
|
if (!will_restart)
|
||||||
{
|
{
|
||||||
ConsoleIO.Backend.StopReadThread();
|
StopConsoleSession();
|
||||||
ConsoleIO.Backend.MessageReceived -= ConsoleReaderOnMessageReceived;
|
|
||||||
ConsoleIO.Backend.OnInputChange -= ConsoleIO.AutocompleteHandler;
|
|
||||||
Program.HandleFailure(null, false, reason);
|
Program.HandleFailure(null, false, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue