mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
[SKIP_BUILD] FIx "/reco" and "/connect" not working properly
This commit is contained in:
parent
d56dd4a74a
commit
ae23ead4c3
7 changed files with 54 additions and 31 deletions
|
|
@ -23,7 +23,7 @@ namespace MinecraftClient.Commands
|
||||||
|
|
||||||
if (Settings.Config.Main.SetServerIP(new Settings.MainConfigHealper.MainConfig.ServerInfoConfig(args[0]), true))
|
if (Settings.Config.Main.SetServerIP(new Settings.MainConfigHealper.MainConfig.ServerInfoConfig(args[0]), true))
|
||||||
{
|
{
|
||||||
Program.Restart();
|
Program.Restart(keepAccountAndServerSettings: true);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
else return string.Format(Translations.cmd_connect_invalid_ip, args[0]);
|
else return string.Format(Translations.cmd_connect_invalid_ip, args[0]);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ namespace MinecraftClient.Commands
|
||||||
return string.Format(Translations.cmd_connect_unknown, args[0]);
|
return string.Format(Translations.cmd_connect_unknown, args[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Program.Restart();
|
Program.Restart(keepAccountAndServerSettings: true);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -710,7 +710,7 @@ namespace MinecraftClient
|
||||||
/// <param name="hard">Marks if bots need to be hard reloaded</param>
|
/// <param name="hard">Marks if bots need to be hard reloaded</param>
|
||||||
public void ReloadSettings()
|
public void ReloadSettings()
|
||||||
{
|
{
|
||||||
Program.ReloadSettings();
|
Program.ReloadSettings(true);
|
||||||
ReloadBots();
|
ReloadBots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -674,9 +674,9 @@ namespace MinecraftClient
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reloads settings
|
/// Reloads settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void ReloadSettings()
|
public static void ReloadSettings(bool keepAccountAndServerSettings = false)
|
||||||
{
|
{
|
||||||
if(Settings.LoadFromFile(settingsIniPath).Item1)
|
if(Settings.LoadFromFile(settingsIniPath, keepAccountAndServerSettings).Item1)
|
||||||
ConsoleIO.WriteLine(string.Format(Translations.config_load, settingsIniPath));
|
ConsoleIO.WriteLine(string.Format(Translations.config_load, settingsIniPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -692,7 +692,7 @@ namespace MinecraftClient
|
||||||
/// Disconnect the current client from the server and restart it
|
/// Disconnect the current client from the server and restart it
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
||||||
public static void Restart(int delaySeconds = 0)
|
public static void Restart(int delaySeconds = 0, bool keepAccountAndServerSettings = false)
|
||||||
{
|
{
|
||||||
ConsoleInteractive.ConsoleReader.StopReadThread();
|
ConsoleInteractive.ConsoleReader.StopReadThread();
|
||||||
new Thread(new ThreadStart(delegate
|
new Thread(new ThreadStart(delegate
|
||||||
|
|
@ -705,7 +705,7 @@ namespace MinecraftClient
|
||||||
Thread.Sleep(delaySeconds * 1000);
|
Thread.Sleep(delaySeconds * 1000);
|
||||||
}
|
}
|
||||||
ConsoleIO.WriteLine(Translations.mcc_restart);
|
ConsoleIO.WriteLine(Translations.mcc_restart);
|
||||||
ReloadSettings();
|
ReloadSettings(keepAccountAndServerSettings);
|
||||||
InitializeClient();
|
InitializeClient();
|
||||||
})).Start();
|
})).Start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -247,12 +247,12 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="extraAttempts">If connection fails, the client will make X extra attempts</param>
|
/// <param name="extraAttempts">If connection fails, the client will make X extra attempts</param>
|
||||||
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
||||||
new public void ReconnectToTheServer(int extraAttempts = -999999, int delaySeconds = 0)
|
new public void ReconnectToTheServer(int extraAttempts = -999999, int delaySeconds = 0, bool keepAccountAndServerSettings = false)
|
||||||
{
|
{
|
||||||
if (extraAttempts == -999999)
|
if (extraAttempts == -999999)
|
||||||
base.ReconnectToTheServer();
|
base.ReconnectToTheServer(delaySeconds: delaySeconds, keepAccountAndServerSettings: keepAccountAndServerSettings);
|
||||||
else
|
else
|
||||||
base.ReconnectToTheServer(extraAttempts);
|
base.ReconnectToTheServer(extraAttempts, delaySeconds, keepAccountAndServerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -361,7 +361,7 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
bool result = Settings.Config.Main.Advanced.SetAccount(accountAlias);
|
bool result = Settings.Config.Main.Advanced.SetAccount(accountAlias);
|
||||||
if (result && andReconnect)
|
if (result && andReconnect)
|
||||||
ReconnectToTheServer();
|
ReconnectToTheServer(keepAccountAndServerSettings: true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -374,7 +374,7 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
bool result = Settings.Config.Main.SetServerIP(new MainConfigHealper.MainConfig.ServerInfoConfig(server), true);
|
bool result = Settings.Config.Main.SetServerIP(new MainConfigHealper.MainConfig.ServerInfoConfig(server), true);
|
||||||
if (result && andReconnect)
|
if (result && andReconnect)
|
||||||
ReconnectToTheServer();
|
ReconnectToTheServer(keepAccountAndServerSettings: true);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -920,7 +920,7 @@ namespace MinecraftClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ExtraAttempts">In case of failure, maximum extra attempts before aborting</param>
|
/// <param name="ExtraAttempts">In case of failure, maximum extra attempts before aborting</param>
|
||||||
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
/// <param name="delaySeconds">Optional delay, in seconds, before restarting</param>
|
||||||
protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0)
|
protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0, bool keepAccountAndServerSettings = false)
|
||||||
{
|
{
|
||||||
if (Settings.Config.Logging.DebugMessages)
|
if (Settings.Config.Logging.DebugMessages)
|
||||||
{
|
{
|
||||||
|
|
@ -928,7 +928,7 @@ namespace MinecraftClient
|
||||||
ConsoleIO.WriteLogLine(string.Format(Translations.chatbot_reconnect, botName));
|
ConsoleIO.WriteLogLine(string.Format(Translations.chatbot_reconnect, botName));
|
||||||
}
|
}
|
||||||
McClient.ReconnectionAttemptsLeft = ExtraAttempts;
|
McClient.ReconnectionAttemptsLeft = ExtraAttempts;
|
||||||
Program.Restart(delaySeconds);
|
Program.Restart(delaySeconds, keepAccountAndServerSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,10 @@ namespace MinecraftClient
|
||||||
public static bool InteractiveMode = true;
|
public static bool InteractiveMode = true;
|
||||||
|
|
||||||
public static bool GravityEnabled = true;
|
public static bool GravityEnabled = true;
|
||||||
|
|
||||||
|
public static bool KeepAccountSettings = false;
|
||||||
|
|
||||||
|
public static bool KeepServerSettings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GlobalConfig
|
public class GlobalConfig
|
||||||
|
|
@ -125,8 +129,13 @@ namespace MinecraftClient
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Tuple<bool, bool> LoadFromFile(string filepath)
|
public static Tuple<bool, bool> LoadFromFile(string filepath, bool keepAccountAndServerSettings = false)
|
||||||
{
|
{
|
||||||
|
bool keepAccountSettings = InternalConfig.KeepAccountSettings;
|
||||||
|
bool keepServerSettings = InternalConfig.KeepServerSettings;
|
||||||
|
if (keepAccountAndServerSettings)
|
||||||
|
InternalConfig.KeepAccountSettings = InternalConfig.KeepServerSettings = true;
|
||||||
|
|
||||||
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
|
||||||
TomlDocument document;
|
TomlDocument document;
|
||||||
try
|
try
|
||||||
|
|
@ -157,6 +166,13 @@ namespace MinecraftClient
|
||||||
ConsoleIO.WriteLine(ex.GetFullMessage());
|
ConsoleIO.WriteLine(ex.GetFullMessage());
|
||||||
return new(false, false);
|
return new(false, false);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!keepAccountSettings)
|
||||||
|
InternalConfig.KeepAccountSettings = false;
|
||||||
|
if (!keepServerSettings)
|
||||||
|
InternalConfig.KeepServerSettings = false;
|
||||||
|
}
|
||||||
return new(true, false);
|
return new(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,12 +273,14 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
InternalConfig.Login = argument;
|
InternalConfig.Login = argument;
|
||||||
|
InternalConfig.KeepAccountSettings = true;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
InternalConfig.Password = argument;
|
InternalConfig.Password = argument;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Config.Main.SetServerIP(new MainConfig.ServerInfoConfig(argument), true);
|
Config.Main.SetServerIP(new MainConfig.ServerInfoConfig(argument), true);
|
||||||
|
InternalConfig.KeepServerSettings = true;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// SingleCommand = argument;
|
// SingleCommand = argument;
|
||||||
|
|
@ -373,7 +391,8 @@ namespace MinecraftClient
|
||||||
|
|
||||||
General.Account.Login ??= string.Empty;
|
General.Account.Login ??= string.Empty;
|
||||||
General.Account.Password ??= string.Empty;
|
General.Account.Password ??= string.Empty;
|
||||||
InternalConfig.Login = General.Account.Login;
|
if (!InternalConfig.KeepAccountSettings)
|
||||||
|
InternalConfig.Login = General.Account.Login;
|
||||||
|
|
||||||
General.Server.Host ??= string.Empty;
|
General.Server.Host ??= string.Empty;
|
||||||
|
|
||||||
|
|
@ -404,23 +423,26 @@ namespace MinecraftClient
|
||||||
ConsoleIO.WriteLogLine("[Settings] " + Translations.config_Main_Advanced_language_invaild);
|
ConsoleIO.WriteLogLine("[Settings] " + Translations.config_Main_Advanced_language_invaild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(General.Server.Host))
|
if (!InternalConfig.KeepServerSettings)
|
||||||
{
|
{
|
||||||
string[] sip = General.Server.Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
if (!string.IsNullOrWhiteSpace(General.Server.Host))
|
||||||
General.Server.Host = sip[0];
|
|
||||||
InternalConfig.ServerIP = General.Server.Host;
|
|
||||||
|
|
||||||
if (sip.Length > 1)
|
|
||||||
{
|
{
|
||||||
try { General.Server.Port = Convert.ToUInt16(sip[1]); }
|
string[] sip = General.Server.Host.Split(new[] { ":", ":" }, StringSplitOptions.None);
|
||||||
catch (FormatException) { }
|
General.Server.Host = sip[0];
|
||||||
}
|
InternalConfig.ServerIP = General.Server.Host;
|
||||||
}
|
|
||||||
|
|
||||||
if (General.Server.Port.HasValue)
|
if (sip.Length > 1)
|
||||||
InternalConfig.ServerPort = General.Server.Port.Value;
|
{
|
||||||
else
|
try { General.Server.Port = Convert.ToUInt16(sip[1]); }
|
||||||
SetServerIP(General.Server, true);
|
catch (FormatException) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (General.Server.Port.HasValue)
|
||||||
|
InternalConfig.ServerPort = General.Server.Port.Value;
|
||||||
|
else
|
||||||
|
SetServerIP(General.Server, true);
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < Advanced.BotOwners.Count; ++i)
|
for (int i = 0; i < Advanced.BotOwners.Count; ++i)
|
||||||
Advanced.BotOwners[i] = ToLowerIfNeed(Advanced.BotOwners[i]);
|
Advanced.BotOwners[i] = ToLowerIfNeed(Advanced.BotOwners[i]);
|
||||||
|
|
@ -579,7 +601,8 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
if (AccountList.TryGetValue(accountAlias, out AccountInfoConfig accountInfo))
|
if (AccountList.TryGetValue(accountAlias, out AccountInfoConfig accountInfo))
|
||||||
{
|
{
|
||||||
Settings.Config.Main.General.Account = accountInfo;
|
InternalConfig.Login = accountInfo.Login;
|
||||||
|
InternalConfig.Password = accountInfo.Password;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue