mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add timeout for server ping
Thanks doranchak & FantomHD (post no.1193) + Add missing doc for MinecraftVersionPrompt
This commit is contained in:
parent
2cf46c0487
commit
791ecba454
2 changed files with 21 additions and 15 deletions
|
|
@ -327,9 +327,9 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Ask for server version when failed to ping server and/or determinate serveur version
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns>TRUE if a Minecraft version has been read from prompt</returns>
|
||||||
|
|
||||||
public static bool MinecraftVersionPrompt()
|
public static bool MinecraftVersionPrompt()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,26 +24,32 @@ namespace MinecraftClient.Protocol
|
||||||
/// <returns>TRUE if ping was successful</returns>
|
/// <returns>TRUE if ping was successful</returns>
|
||||||
|
|
||||||
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion)
|
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
int protocolversionTmp = 0;
|
||||||
|
if (AutoTimeout.Perform(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversion))
|
if (Protocol16Handler.doPing(serverIP, serverPort, ref protocolversionTmp)
|
||||||
|
|| Protocol17Handler.doPing(serverIP, serverPort, ref protocolversionTmp))
|
||||||
{
|
{
|
||||||
return true;
|
success = true;
|
||||||
}
|
|
||||||
else if (Protocol17Handler.doPing(serverIP, serverPort, ref protocolversion))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
else ConsoleIO.WriteLineFormatted("§8Unexpected answer from the server (is that a Minecraft server ?)");
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP.");
|
ConsoleIO.WriteLineFormatted("§8An error occured while attempting to connect to this IP.");
|
||||||
|
}
|
||||||
|
}, TimeSpan.FromSeconds(30)))
|
||||||
|
{
|
||||||
|
protocolversion = protocolversionTmp;
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ConsoleIO.WriteLineFormatted("§8A timeout occured while attempting to connect to this IP.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -260,7 +266,7 @@ namespace MinecraftClient.Protocol
|
||||||
statusCode = Settings.str2int(raw_result.Split(' ')[1]);
|
statusCode = Settings.str2int(raw_result.Split(' ')[1]);
|
||||||
}
|
}
|
||||||
else statusCode = 520; //Web server is returning an unknown error
|
else statusCode = 520; //Web server is returning an unknown error
|
||||||
}, 30000);
|
}, TimeSpan.FromSeconds(30));
|
||||||
result = postResult;
|
result = postResult;
|
||||||
return statusCode;
|
return statusCode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue