From 98c2b345121550bbc5183f695d4ce0af55ccdebc Mon Sep 17 00:00:00 2001 From: 20kdc Date: Sun, 22 May 2022 02:56:18 +0100 Subject: [PATCH] Redial Button II - Now with magic! (#8237) * Redial Button II - Now with magic! * 15-second timer before redial is allowed --- Content.Client/Entry/EntryPoint.cs | 2 + Content.Client/IoC/ClientContentIoC.cs | 2 + .../ExtendedDisconnectInformationManager.cs | 45 +++++++++++++++++++ Content.Client/Launcher/LauncherConnecting.cs | 28 ++++++++++++ .../Launcher/LauncherConnectingGui.xaml | 4 ++ .../Launcher/LauncherConnectingGui.xaml.cs | 37 +++++++++++++++ .../en-US/launcher/launcher-connecting.ftl | 4 +- 7 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 Content.Client/Launcher/ExtendedDisconnectInformationManager.cs diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 46dd76003d..483f4dc733 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -129,6 +129,7 @@ namespace Content.Client.Entry IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); + IoCManager.Resolve().Initialize(); IoCManager.InjectDependencies(this); @@ -138,6 +139,7 @@ namespace Content.Client.Entry { IoCManager.Resolve().CreateNewMapEntity(MapId.Nullspace); }; + } /// diff --git a/Content.Client/IoC/ClientContentIoC.cs b/Content.Client/IoC/ClientContentIoC.cs index c7f1e95627..06618dd518 100644 --- a/Content.Client/IoC/ClientContentIoC.cs +++ b/Content.Client/IoC/ClientContentIoC.cs @@ -8,6 +8,7 @@ using Content.Client.GhostKick; using Content.Client.HUD; using Content.Client.Info; using Content.Client.Items.Managers; +using Content.Client.Launcher; using Content.Client.Module; using Content.Client.Parallax.Managers; using Content.Client.Preferences; @@ -45,6 +46,7 @@ namespace Content.Client.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + IoCManager.Register(); } } } diff --git a/Content.Client/Launcher/ExtendedDisconnectInformationManager.cs b/Content.Client/Launcher/ExtendedDisconnectInformationManager.cs new file mode 100644 index 0000000000..0fc2eabc32 --- /dev/null +++ b/Content.Client/Launcher/ExtendedDisconnectInformationManager.cs @@ -0,0 +1,45 @@ +using System; +using Robust.Client; +using Robust.Client.UserInterface; +using Robust.Shared.IoC; +using Robust.Shared.Log; +using Robust.Shared.Network; + +namespace Content.Client.Launcher; + +/// +/// So apparently the way that disconnect information is shipped around is really indirect. +/// But honestly, given that content might have additional flags (i.e. hide disconnect button for bans)? +/// This is responsible for collecting any extended disconnect information. +/// +public sealed class ExtendedDisconnectInformationManager +{ + [Dependency] private readonly IClientNetManager _clientNetManager = default!; + + private NetDisconnectedArgs? _lastNetDisconnectedArgs = null; + + public NetDisconnectedArgs? LastNetDisconnectedArgs + { + get => _lastNetDisconnectedArgs; + private set + { + _lastNetDisconnectedArgs = value; + LastNetDisconnectedArgsChanged?.Invoke(value); + } + } + + // BE CAREFUL! + // This may fire at an arbitrary time before or after whatever code that needs it. + public event Action? LastNetDisconnectedArgsChanged; + + public void Initialize() + { + _clientNetManager.Disconnect += OnNetDisconnect; + } + + private void OnNetDisconnect(object? sender, NetDisconnectedArgs args) + { + LastNetDisconnectedArgs = args; + } +} + diff --git a/Content.Client/Launcher/LauncherConnecting.cs b/Content.Client/Launcher/LauncherConnecting.cs index 511a85b1c2..f4ed4b46ae 100644 --- a/Content.Client/Launcher/LauncherConnecting.cs +++ b/Content.Client/Launcher/LauncherConnecting.cs @@ -2,6 +2,7 @@ using System; using Robust.Client; using Robust.Client.UserInterface; using Robust.Shared.IoC; +using Robust.Shared.Log; using Robust.Shared.Network; namespace Content.Client.Launcher @@ -70,6 +71,12 @@ namespace Content.Client.Launcher private void OnConnectFailed(object? _, NetConnectFailArgs args) { + if (args.RedialFlag) + { + // We've just *attempted* to connect and we've been told we need to redial, so do it. + // Result deliberately discarded. + Redial(); + } ConnectFailReason = args.Reason; CurrentPage = Page.ConnectFailed; } @@ -88,6 +95,27 @@ namespace Content.Client.Launcher } } + public bool Redial() + { + try + { + if (_gameController.LaunchState.Ss14Address != null) + { + _gameController.Redial(_gameController.LaunchState.Ss14Address); + return true; + } + else + { + Logger.InfoS("launcher-ui", $"Redial not possible, no Ss14Address"); + } + } + catch (Exception ex) + { + Logger.ErrorS("launcher-ui", $"Redial exception: {ex}"); + } + return false; + } + public void Exit() { _gameController.Shutdown("Exit button pressed"); diff --git a/Content.Client/Launcher/LauncherConnectingGui.xaml b/Content.Client/Launcher/LauncherConnectingGui.xaml index 2d4aa5f1cb..787d35a754 100644 --- a/Content.Client/Launcher/LauncherConnectingGui.xaml +++ b/Content.Client/Launcher/LauncherConnectingGui.xaml @@ -33,6 +33,10 @@