mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Login rejections could schedule and execute multiple restarts for one failure while leaving no usable console route during reconnect delays. Changes: - Bind failure and restart work to immutable connection attempts - Coalesce automatic retries while allowing explicit settings replacement until commit - Preserve held bots and offline command routing across failed logins - Add deterministic retry, ownership, and routing regression tests Fixes #3186
91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using System;
|
|
using Brigadier.NET;
|
|
using Brigadier.NET.Builder;
|
|
using MinecraftClient.CommandHandler;
|
|
|
|
namespace MinecraftClient.Commands
|
|
{
|
|
public class Reco : Command
|
|
{
|
|
public override string CmdName { get { return "reco"; } }
|
|
public override string CmdUsage { get { return "reco [account]"; } }
|
|
public override string CmdDesc { get { return Translations.cmd_reco_desc; } }
|
|
|
|
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
|
|
{
|
|
dispatcher.Register(l => l.Literal("help")
|
|
.Then(l => l.Literal(CmdName)
|
|
.Executes(r => GetUsage(r.Source, string.Empty))
|
|
)
|
|
);
|
|
|
|
dispatcher.Register(l => l.Literal(CmdName)
|
|
.Executes(r => DoReconnect(r.Source, string.Empty))
|
|
.Then(l => l.Argument("AccountNick", MccArguments.AccountNick())
|
|
.Executes(r => DoReconnect(r.Source, Arguments.GetString(r, "AccountNick"))))
|
|
.Then(l => l.Literal("_help")
|
|
.Executes(r => GetUsage(r.Source, string.Empty))
|
|
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
|
);
|
|
}
|
|
|
|
private int GetUsage(CmdResult r, string? cmd)
|
|
{
|
|
return r.SetAndReturn(cmd switch
|
|
{
|
|
#pragma warning disable format // @formatter:off
|
|
_ => GetCmdDescTranslated(),
|
|
#pragma warning restore format // @formatter:on
|
|
});
|
|
}
|
|
|
|
private int DoReconnect(CmdResult r, string account)
|
|
{
|
|
RestartSettingsSnapshot previousSettings = Program.CaptureRestartSettings();
|
|
if (!string.IsNullOrWhiteSpace(account))
|
|
{
|
|
account = account.Trim();
|
|
if (!Settings.Config.Main.Advanced.SetAccount(account))
|
|
return r.SetAndReturn(CmdResult.Status.Fail, string.Format(Translations.cmd_connect_unknown, account));
|
|
}
|
|
|
|
if (Program.TryRestart(
|
|
Program.CurrentConnectionAttempt,
|
|
TimeSpan.Zero,
|
|
keepAccountAndServerSettings: true,
|
|
replaceUntilCommit: true))
|
|
{
|
|
return r.SetAndReturn(CmdResult.Status.Done);
|
|
}
|
|
|
|
Program.RestoreRestartSettings(previousSettings);
|
|
return r.SetAndReturn(CmdResult.Status.Fail);
|
|
}
|
|
|
|
internal static string DoReconnect(string command)
|
|
{
|
|
RestartSettingsSnapshot previousSettings = Program.CaptureRestartSettings();
|
|
string[] args = GetArgs(command);
|
|
if (args.Length > 0)
|
|
{
|
|
string account = args[0].Trim();
|
|
if (!Settings.Config.Main.Advanced.SetAccount(account))
|
|
{
|
|
return string.Format(Translations.cmd_connect_unknown, account);
|
|
}
|
|
}
|
|
|
|
if (Program.TryRestart(
|
|
Program.CurrentConnectionAttempt,
|
|
TimeSpan.Zero,
|
|
keepAccountAndServerSettings: true,
|
|
replaceUntilCommit: true))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
Program.RestoreRestartSettings(previousSettings);
|
|
return Translations.general_fail;
|
|
}
|
|
}
|
|
}
|