Fix Unhandled WebException

This commit fixes an unhandled WebException that may occur when
attempting to connect to the Minecraft session server when it is very
slow or unreachable.
This commit is contained in:
justcool393 2013-10-13 16:21:18 -07:00
parent 1284017245
commit 0e2ccdd1f6

View file

@ -79,7 +79,19 @@ namespace MinecraftClient
Console.ForegroundColor = ConsoleColor.DarkGray;
WebClient client = new WebClient();
Console.Write("http://session.minecraft.net/game/joinserver.jsp?user=" + user + "&sessionId=" + sessionID + "&serverId=" + hash + " ... ");
string result = client.DownloadString("http://session.minecraft.net/game/joinserver.jsp?user=" + user + "&sessionId=" + sessionID + "&serverId=" + hash);
string result;
try
{
result = client.DownloadString("http://session.minecraft.net/game/joinserver.jsp?user=" + user + "&sessionId=" + sessionID + "&serverId=" + hash);
}
catch (WebException e)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
Console.WriteLine("Error while connecting to session server: " + e.Message);
Console.ForegroundColor = ConsoleColor.DarkGray;
return false;
}
Console.WriteLine(result);
Console.ForegroundColor = ConsoleColor.Gray;
return (result == "OK");