From 873bd79fd6b6ff62924e35d562b5a80ee6b66118 Mon Sep 17 00:00:00 2001
From: breadbyte <14045257+breadbyte@users.noreply.github.com>
Date: Thu, 7 Mar 2024 07:21:11 +0800
Subject: [PATCH 1/3] Fix offline client reconnecting as a microsoft account
Consider an empty string as a blank password as well as the default dash.
---
MinecraftClient/Program.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs
index 9c126bee..2055afd5 100644
--- a/MinecraftClient/Program.cs
+++ b/MinecraftClient/Program.cs
@@ -406,7 +406,7 @@ namespace MinecraftClient
ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired;
string loginLower = ToLowerIfNeed(InternalConfig.Account.Login);
- if (InternalConfig.Account.Password == "-")
+ if (InternalConfig.Account.Password == "-" || InternalConfig.Account.Password == string.Empty)
{
ConsoleIO.WriteLineFormatted("ยง8" + Translations.mcc_offline, acceptnewlines: true);
result = ProtocolHandler.LoginResult.Success;
From c78245c056d23369b2cc1fb7800de1d16509eb3e Mon Sep 17 00:00:00 2001
From: breadbyte <14045257+breadbyte@users.noreply.github.com>
Date: Thu, 7 Mar 2024 09:37:55 +0800
Subject: [PATCH 2/3] Fix Server Version prompt
Actually use the provided server version when reconnecting to a server that doesn't broadcast their protocol version
---
MinecraftClient/Program.cs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs
index 2055afd5..599ee722 100644
--- a/MinecraftClient/Program.cs
+++ b/MinecraftClient/Program.cs
@@ -398,7 +398,12 @@ namespace MinecraftClient
///
private static void InitializeClient()
{
- InternalConfig.MinecraftVersion = Config.Main.Advanced.MinecraftVersion;
+ // Ensure that we use the provided Minecraft version if we can't connect automatically.
+ //
+ // useMcVersionOnce is set to true on HandleFailure()
+ // whenever we are unable to connect to the server and the user provides a version number.
+ if (!useMcVersionOnce)
+ InternalConfig.MinecraftVersion = Config.Main.Advanced.MinecraftVersion;
SessionToken session = new();
PlayerKeyPair? playerKeyPair = null;
@@ -749,7 +754,7 @@ namespace MinecraftClient
if (InternalConfig.MinecraftVersion != "")
{
useMcVersionOnce = true;
- Restart();
+ Restart(0, true);
return;
}
}
From a72a8cf833bce7d69b1c65dd902eb1a8edae7530 Mon Sep 17 00:00:00 2001
From: breadbyte <14045257+breadbyte@users.noreply.github.com>
Date: Thu, 7 Mar 2024 09:54:40 +0800
Subject: [PATCH 3/3] Make AutoRelog more reliable
Makes AutoRelog more hands on with the relogging rather than have the general relogging handler handle it.
Fallback to the general handler only when the AutoRelog module is disabled.
---
MinecraftClient/ChatBots/AutoRelog.cs | 7 ++--
MinecraftClient/McClient.cs | 55 ++++++++++++++++++---------
2 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs
index c384eb7c..24e6570a 100644
--- a/MinecraftClient/ChatBots/AutoRelog.cs
+++ b/MinecraftClient/ChatBots/AutoRelog.cs
@@ -137,9 +137,10 @@ namespace MinecraftClient.ChatBots
{
double delay = random.NextDouble() * (Config.Delay.max - Config.Delay.min) + Config.Delay.min;
LogDebugToConsole(string.Format(string.IsNullOrEmpty(msg) ? Translations.bot_autoRelog_reconnect_always : Translations.bot_autoRelog_reconnect, msg));
- LogToConsole(string.Format(Translations.bot_autoRelog_wait, delay));
- System.Threading.Thread.Sleep((int)Math.Floor(delay * 1000));
- ReconnectToTheServer();
+
+ // TODO: Change this translation string to add the retries left text
+ LogToConsole(string.Format(Translations.bot_autoRelog_wait, delay) + $" ({Config.Retries - Configs._BotRecoAttempts} retries left)");
+ ReconnectToTheServer(Config.Retries - Configs._BotRecoAttempts, (int)Math.Floor(delay), true);
}
public static bool OnDisconnectStatic(DisconnectReason reason, string message)
diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs
index 294c3a97..48f1cbaa 100644
--- a/MinecraftClient/McClient.cs
+++ b/MinecraftClient/McClient.cs
@@ -153,6 +153,7 @@ namespace MinecraftClient
private static IMinecraftComHandler? instance;
public static IMinecraftComHandler? Instance => instance;
+
///
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
///
@@ -245,28 +246,48 @@ namespace MinecraftClient
return;
- Retry:
+ Retry:
if (timeoutdetector != null)
{
timeoutdetector.Item2.Cancel();
timeoutdetector = null;
}
- if (ReconnectionAttemptsLeft > 0)
- {
- Log.Info(string.Format(Translations.mcc_reconnect, ReconnectionAttemptsLeft));
- Thread.Sleep(5000);
- ReconnectionAttemptsLeft--;
- Program.Restart();
- }
- else if (InternalConfig.InteractiveMode)
- {
- ConsoleInteractive.ConsoleReader.StopReadThread();
- ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
- ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
- Program.HandleFailure();
- }
- throw new Exception("Initialization failed.");
+ if (!Config.ChatBot.AutoRelog.Enabled)
+ {
+ if (ReconnectionAttemptsLeft > 0)
+ {
+ Log.Info(string.Format(Translations.mcc_reconnect, ReconnectionAttemptsLeft));
+ Thread.Sleep(5000);
+ ReconnectionAttemptsLeft--;
+ Program.Restart();
+ }
+ else if (InternalConfig.InteractiveMode)
+ {
+ ConsoleInteractive.ConsoleReader.StopReadThread();
+ ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
+ ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
+ Program.HandleFailure();
+ }
+
+ throw new Exception("Initialization failed.");
+ }
+ else
+ {
+ // The AutoRelog ChatBot will handle reconnection at this point.
+ // This is important, or else we'll have multiple instances of the client running at the same time.
+
+ if (ReconnectionAttemptsLeft == 0)
+ {
+ if (InternalConfig.InteractiveMode)
+ {
+ ConsoleInteractive.ConsoleReader.StopReadThread();
+ ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
+ ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
+ Program.HandleFailure();
+ }
+ }
+ }
}
///
@@ -572,7 +593,7 @@ namespace MinecraftClient
ConsoleInteractive.ConsoleReader.StopReadThread();
ConsoleInteractive.ConsoleReader.MessageReceived -= ConsoleReaderOnMessageReceived;
ConsoleInteractive.ConsoleReader.OnInputChange -= ConsoleIO.AutocompleteHandler;
- Program.HandleFailure();
+ Program.HandleFailure(message, false, reason);
}
}