Better exception catching

- Better catch in proxy handler
- Better catch in StartClient (thx doranchak)
This commit is contained in:
ORelio 2015-04-06 11:42:43 +02:00
parent 2c31efd0c9
commit ea17ec87f1
3 changed files with 51 additions and 28 deletions

View file

@ -89,6 +89,7 @@ namespace MinecraftClient
private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, bool singlecommand, string command) private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, bool singlecommand, string command)
{ {
bool retry = false;
this.sessionid = sessionID; this.sessionid = sessionID;
this.uuid = uuid; this.uuid = uuid;
this.username = user; this.username = user;
@ -114,6 +115,8 @@ namespace MinecraftClient
handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this); handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this);
Console.WriteLine("Version is supported.\nLogging in..."); Console.WriteLine("Version is supported.\nLogging in...");
try
{
if (handler.Login()) if (handler.Login())
{ {
if (singlecommand) if (singlecommand)
@ -141,9 +144,21 @@ namespace MinecraftClient
} }
} }
} }
catch (Exception e)
{
ConsoleIO.WriteLineFormatted("§8" + e.Message);
Console.WriteLine("Failed to join this server.");
retry = true;
}
}
catch (SocketException) catch (SocketException)
{ {
Console.WriteLine("Failed to connect to this IP."); Console.WriteLine("Failed to connect to this IP.");
retry = true;
}
if (retry)
{
if (AttemptsLeft > 0) if (AttemptsLeft > 0)
{ {
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)..."); ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
@ -428,6 +443,10 @@ namespace MinecraftClient
public void OnPlayerJoin(Guid uuid, string name) public void OnPlayerJoin(Guid uuid, string name)
{ {
//Ignore TabListPlus placeholders
if (name.StartsWith("0000tab#"))
return;
lock (onlinePlayers) lock (onlinePlayers)
{ {
onlinePlayers[uuid] = name; onlinePlayers[uuid] = name;

View file

@ -57,12 +57,16 @@ namespace MinecraftClient.Proxy
} }
else return new TcpClient(host, port); else return new TcpClient(host, port);
} }
catch (ProxyException e) catch (Exception e)
{
if (e is ProxyException || e is SocketException)
{ {
ConsoleIO.WriteLineFormatted("§8" + e.Message); ConsoleIO.WriteLineFormatted("§8" + e.Message);
proxy = null; proxy = null;
return null; return null;
} }
else throw;
}
} }
} }
} }