mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Better exception catching
- Better catch in proxy handler - Better catch in StartClient (thx doranchak)
This commit is contained in:
parent
2c31efd0c9
commit
ea17ec87f1
3 changed files with 51 additions and 28 deletions
|
|
@ -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)
|
||||
{
|
||||
bool retry = false;
|
||||
this.sessionid = sessionID;
|
||||
this.uuid = uuid;
|
||||
this.username = user;
|
||||
|
|
@ -113,37 +114,51 @@ namespace MinecraftClient
|
|||
client.ReceiveBufferSize = 1024 * 1024;
|
||||
handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this);
|
||||
Console.WriteLine("Version is supported.\nLogging in...");
|
||||
|
||||
if (handler.Login())
|
||||
|
||||
try
|
||||
{
|
||||
if (singlecommand)
|
||||
if (handler.Login())
|
||||
{
|
||||
handler.SendChatMessage(command);
|
||||
ConsoleIO.WriteLineFormatted("§7Command §8" + command + "§7 sent.");
|
||||
Thread.Sleep(5000);
|
||||
handler.Disconnect();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (ChatBot bot in scripts_on_hold)
|
||||
bot.SetHandler(this);
|
||||
bots.AddRange(scripts_on_hold);
|
||||
scripts_on_hold.Clear();
|
||||
|
||||
Console.WriteLine("Server was successfully joined.\nType '"
|
||||
+ (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar)
|
||||
+ "quit' to leave the server.");
|
||||
|
||||
cmdprompt = new Thread(new ThreadStart(CommandPrompt));
|
||||
cmdprompt.Name = "MCC Command prompt";
|
||||
cmdprompt.Start();
|
||||
if (singlecommand)
|
||||
{
|
||||
handler.SendChatMessage(command);
|
||||
ConsoleIO.WriteLineFormatted("§7Command §8" + command + "§7 sent.");
|
||||
Thread.Sleep(5000);
|
||||
handler.Disconnect();
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (ChatBot bot in scripts_on_hold)
|
||||
bot.SetHandler(this);
|
||||
bots.AddRange(scripts_on_hold);
|
||||
scripts_on_hold.Clear();
|
||||
|
||||
Console.WriteLine("Server was successfully joined.\nType '"
|
||||
+ (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar)
|
||||
+ "quit' to leave the server.");
|
||||
|
||||
cmdprompt = new Thread(new ThreadStart(CommandPrompt));
|
||||
cmdprompt.Name = "MCC Command prompt";
|
||||
cmdprompt.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||
Console.WriteLine("Failed to join this server.");
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
Console.WriteLine("Failed to connect to this IP.");
|
||||
retry = true;
|
||||
}
|
||||
|
||||
if (retry)
|
||||
{
|
||||
if (AttemptsLeft > 0)
|
||||
{
|
||||
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
||||
|
|
@ -428,6 +443,10 @@ namespace MinecraftClient
|
|||
|
||||
public void OnPlayerJoin(Guid uuid, string name)
|
||||
{
|
||||
//Ignore TabListPlus placeholders
|
||||
if (name.StartsWith("0000tab#"))
|
||||
return;
|
||||
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
onlinePlayers[uuid] = name;
|
||||
|
|
|
|||
|
|
@ -458,7 +458,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
byte[] server_adress_len = getVarInt(server_adress_val.Length);
|
||||
byte[] server_port = BitConverter.GetBytes((ushort)handler.getServerPort()); Array.Reverse(server_port);
|
||||
byte[] next_state = getVarInt(2);
|
||||
byte[] handshake_packet = concatBytes( protocol_version, server_adress_len, server_adress_val, server_port, next_state);
|
||||
byte[] handshake_packet = concatBytes(protocol_version, server_adress_len, server_adress_val, server_port, next_state);
|
||||
|
||||
SendPacket(0x00, handshake_packet);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,11 +57,15 @@ namespace MinecraftClient.Proxy
|
|||
}
|
||||
else return new TcpClient(host, port);
|
||||
}
|
||||
catch (ProxyException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||
proxy = null;
|
||||
return null;
|
||||
if (e is ProxyException || e is SocketException)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8" + e.Message);
|
||||
proxy = null;
|
||||
return null;
|
||||
}
|
||||
else throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue