mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
More startup error handling
- Pass minecraft login failure message to AutoRelog bot (suggestion by doranchak) - Fix NullReferenceException in McTcpClient caused by SocketException in ProxyHandler - Refactor error handling code in Program.InitializeClient() - More detailed error messages on network errors.
This commit is contained in:
parent
791ecba454
commit
6261e7adb7
5 changed files with 48 additions and 58 deletions
|
|
@ -62,5 +62,15 @@ namespace MinecraftClient.ChatBots
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool OnDisconnectStatic(DisconnectReason reason, string message)
|
||||||
|
{
|
||||||
|
if (Settings.AutoRelog_Enabled)
|
||||||
|
{
|
||||||
|
AutoRelog bot = new AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries);
|
||||||
|
return bot.OnDisconnect(reason, message);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,8 +151,9 @@ namespace MinecraftClient
|
||||||
retry = true;
|
retry = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SocketException)
|
catch (SocketException e)
|
||||||
{
|
{
|
||||||
|
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||||
Console.WriteLine("Failed to connect to this IP.");
|
Console.WriteLine("Failed to connect to this IP.");
|
||||||
retry = true;
|
retry = true;
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +167,7 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
else if (!singlecommand && Settings.interactiveMode)
|
else if (!singlecommand && Settings.interactiveMode)
|
||||||
{
|
{
|
||||||
Program.OfflineCommandPrompt();
|
Program.HandleOfflineMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -369,7 +370,8 @@ namespace MinecraftClient
|
||||||
foreach (ChatBot bot in bots)
|
foreach (ChatBot bot in bots)
|
||||||
will_restart |= bot.OnDisconnect(reason, message);
|
will_restart |= bot.OnDisconnect(reason, message);
|
||||||
|
|
||||||
if (!will_restart) { Program.OfflineCommandPrompt(); }
|
if (!will_restart)
|
||||||
|
Program.HandleOfflineMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -169,24 +169,8 @@ namespace MinecraftClient
|
||||||
if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion))
|
if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to ping this IP.");
|
Console.WriteLine("Failed to ping this IP.");
|
||||||
if (Settings.AutoRelog_Enabled)
|
if (!ChatBots.AutoRelog.OnDisconnectStatic(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP."))
|
||||||
{
|
HandleServerVersionFailure();
|
||||||
ChatBots.AutoRelog bot = new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries);
|
|
||||||
if (!bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP.")) { OfflineCommandPrompt(); }
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Settings.interactiveMode)
|
|
||||||
{
|
|
||||||
if (MinecraftVersionPrompt())
|
|
||||||
{
|
|
||||||
Restart();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
OfflineCommandPrompt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,42 +188,40 @@ namespace MinecraftClient
|
||||||
catch (NotSupportedException)
|
catch (NotSupportedException)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Cannot connect to the server : This version is not supported !");
|
Console.WriteLine("Cannot connect to the server : This version is not supported !");
|
||||||
OfflineCommandPrompt();
|
HandleServerVersionFailure();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Failed to determine server version.");
|
Console.WriteLine("Failed to determine server version.");
|
||||||
if (Settings.interactiveMode && MinecraftVersionPrompt())
|
HandleServerVersionFailure();
|
||||||
{
|
|
||||||
Restart();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Console.Write("Connection failed : ");
|
string failureMessage = "Minecraft Login failed : ";
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case ProtocolHandler.LoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break;
|
case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "Account migrated, use e-mail as username."; break;
|
||||||
case ProtocolHandler.LoginResult.ServiceUnavailable: Console.WriteLine("Login servers are unavailable. Please try again later."); break;
|
case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "Login servers are unavailable. Please try again later."; break;
|
||||||
case ProtocolHandler.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break;
|
case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "Incorrect password."; break;
|
||||||
case ProtocolHandler.LoginResult.NotPremium: Console.WriteLine("User not premium."); break;
|
case ProtocolHandler.LoginResult.NotPremium: failureMessage += "User not premium."; break;
|
||||||
case ProtocolHandler.LoginResult.OtherError: Console.WriteLine("Network error."); break;
|
case ProtocolHandler.LoginResult.OtherError: failureMessage += "Network error."; break;
|
||||||
case ProtocolHandler.LoginResult.SSLError: Console.WriteLine("SSL Error.");
|
case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL Error."; break;
|
||||||
if (isUsingMono)
|
default: failureMessage += "Unknown Error."; break;
|
||||||
{
|
}
|
||||||
ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program."
|
Console.WriteLine(failureMessage);
|
||||||
+ '\n' + "The first time, you have to import HTTPS certificates using:"
|
if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono)
|
||||||
+ '\n' + "mozroots --import --ask-remove");
|
{
|
||||||
return;
|
ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program."
|
||||||
}
|
+ '\n' + "The first time, you have to import HTTPS certificates using:"
|
||||||
break;
|
+ '\n' + "mozroots --import --ask-remove");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
while (Console.KeyAvailable) { Console.ReadKey(false); }
|
while (Console.KeyAvailable) { Console.ReadKey(false); }
|
||||||
if (Settings.SingleCommand == "") { OfflineCommandPrompt(); }
|
if (!ChatBots.AutoRelog.OnDisconnectStatic(ChatBot.DisconnectReason.LoginRejected, failureMessage))
|
||||||
|
HandleOfflineMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,10 +256,10 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Pause the program, usually when an error or a kick occured, letting the user press Enter to quit OR type /reconnect
|
/// Pause the program, usually when an error or a kick occured, letting the user typing commands to reconnect to a server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public static void OfflineCommandPrompt()
|
public static void HandleOfflineMode()
|
||||||
{
|
{
|
||||||
if (Settings.interactiveMode && offlinePrompt == null)
|
if (Settings.interactiveMode && offlinePrompt == null)
|
||||||
{
|
{
|
||||||
|
|
@ -331,7 +313,7 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>TRUE if a Minecraft version has been read from prompt</returns>
|
/// <returns>TRUE if a Minecraft version has been read from prompt</returns>
|
||||||
|
|
||||||
public static bool MinecraftVersionPrompt()
|
public static void HandleServerVersionFailure()
|
||||||
{
|
{
|
||||||
if (Settings.interactiveMode)
|
if (Settings.interactiveMode)
|
||||||
{
|
{
|
||||||
|
|
@ -340,10 +322,10 @@ namespace MinecraftClient
|
||||||
if (Settings.ServerVersion != "")
|
if (Settings.ServerVersion != "")
|
||||||
{
|
{
|
||||||
useMcVersionOnce = true;
|
useMcVersionOnce = true;
|
||||||
return true;
|
Restart();
|
||||||
}
|
}
|
||||||
|
else HandleOfflineMode();
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -38,9 +38,9 @@ namespace MinecraftClient.Protocol
|
||||||
}
|
}
|
||||||
else ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
|
else ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP.");
|
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||||
}
|
}
|
||||||
}, TimeSpan.FromSeconds(30)))
|
}, TimeSpan.FromSeconds(30)))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,15 +57,11 @@ namespace MinecraftClient.Proxy
|
||||||
}
|
}
|
||||||
else return new TcpClient(host, port);
|
else return new TcpClient(host, port);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (ProxyException e)
|
||||||
{
|
{
|
||||||
if (e is ProxyException || e is SocketException)
|
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||||
{
|
proxy = null;
|
||||||
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
return null;
|
||||||
proxy = null;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else throw;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue