mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
parent
a254a282cd
commit
59b12ff900
2 changed files with 11 additions and 4 deletions
|
|
@ -501,11 +501,12 @@ namespace MinecraftClient
|
||||||
/// Disconnect from the server and restart the program
|
/// Disconnect from the server and restart the program
|
||||||
/// It will unload and reload all the bots and then reconnect to the server
|
/// It will unload and reload all the bots and then reconnect to the server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="attempts">If connection fails, the client will make X extra attempts</param>
|
/// <param name="attempts">In case of failure, maximum extra attempts before aborting</param>
|
||||||
protected void ReconnectToTheServer(int ExtraAttempts = 3)
|
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
||||||
|
protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0)
|
||||||
{
|
{
|
||||||
McTcpClient.ReconnectionAttemptsLeft = ExtraAttempts;
|
McTcpClient.ReconnectionAttemptsLeft = ExtraAttempts;
|
||||||
Program.Restart();
|
Program.Restart(delaySeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -268,12 +268,18 @@ namespace MinecraftClient
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disconnect the current client from the server and restart it
|
/// Disconnect the current client from the server and restart it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Restart()
|
/// <param name="delay">Optional delay, in seconds, before restarting</param>
|
||||||
|
public static void Restart(int delaySeconds = 0)
|
||||||
{
|
{
|
||||||
new Thread(new ThreadStart(delegate
|
new Thread(new ThreadStart(delegate
|
||||||
{
|
{
|
||||||
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
|
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
|
||||||
if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); }
|
if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); }
|
||||||
|
if (delaySeconds > 0)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Waiting " + delaySeconds + " seconds before restarting...");
|
||||||
|
System.Threading.Thread.Sleep(delaySeconds * 1000);
|
||||||
|
}
|
||||||
Console.WriteLine("Restarting Minecraft Console Client...");
|
Console.WriteLine("Restarting Minecraft Console Client...");
|
||||||
InitializeClient();
|
InitializeClient();
|
||||||
})).Start();
|
})).Start();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue