diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs
index 1cfdfa60..80fa62b1 100644
--- a/MinecraftClient/Program.cs
+++ b/MinecraftClient/Program.cs
@@ -327,9 +327,9 @@ namespace MinecraftClient
}
///
- ///
+ /// Ask for server version when failed to ping server and/or determinate serveur version
///
- ///
+ /// TRUE if a Minecraft version has been read from prompt
public static bool MinecraftVersionPrompt()
{
diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs
index 5141d16e..d33ef7e8 100644
--- a/MinecraftClient/Protocol/ProtocolHandler.cs
+++ b/MinecraftClient/Protocol/ProtocolHandler.cs
@@ -25,25 +25,31 @@ namespace MinecraftClient.Protocol
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion)
{
- try
+ bool success = false;
+ int protocolversionTmp = 0;
+ if (AutoTimeout.Perform(() =>
{
- if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversion))
+ try
{
- return true;
+ if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp)
+ || Protocol17Handler.doPing(serverIP, serverPort, ref protocolversionTmp))
+ {
+ success = true;
+ }
+ else ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
}
- else if (Protocol17Handler.doPing(serverIP, serverPort, ref protocolversion))
+ catch
{
- return true;
- }
- else
- {
- ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
- return false;
+ ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP.");
}
+ }, TimeSpan.FromSeconds(30)))
+ {
+ protocolversion = protocolversionTmp;
+ return success;
}
- catch
+ else
{
- ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP.");
+ ConsoleIO.WriteLineFormatted("§8A timeout occured while attempting to connect to this IP.");
return false;
}
}
@@ -260,7 +266,7 @@ namespace MinecraftClient.Protocol
statusCode = Settings.str2int(raw_result.Split(' ')[1]);
}
else statusCode = 520; //Web server is returning an unknown error
- }, 30000);
+ }, TimeSpan.FromSeconds(30));
result = postResult;
return statusCode;
}