mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
# Description Cleaned up Logger obsolete compiler warnings in non robust code. Should probably be changed to a ISawmill reference in classes to avoid repeated lookups in heavy logging logic. --- # Changelog 🆑 - tweak: Logger to Logger.GetSawmill("name"); --------- Co-authored-by: ilmenwe <no@mail.com> (cherry picked from commit 2e8ffd971716d38dc6d5a520bebdf88b743045a3)
143 lines
4.4 KiB
C#
143 lines
4.4 KiB
C#
using System;
|
|
using Robust.Client;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Log;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Client.Launcher
|
|
{
|
|
public sealed class LauncherConnecting : Robust.Client.State.State
|
|
{
|
|
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
|
[Dependency] private readonly IClientNetManager _clientNetManager = default!;
|
|
[Dependency] private readonly IGameController _gameController = default!;
|
|
[Dependency] private readonly IBaseClient _baseClient = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
private LauncherConnectingGui? _control;
|
|
|
|
private Page _currentPage;
|
|
private string? _connectFailReason;
|
|
|
|
public string? Address => _gameController.LaunchState.Ss14Address ?? _gameController.LaunchState.ConnectAddress;
|
|
|
|
public string? ConnectFailReason
|
|
{
|
|
get => _connectFailReason;
|
|
private set
|
|
{
|
|
_connectFailReason = value;
|
|
ConnectFailReasonChanged?.Invoke(value);
|
|
}
|
|
}
|
|
|
|
public string? LastDisconnectReason => _baseClient.LastDisconnectReason;
|
|
|
|
public Page CurrentPage
|
|
{
|
|
get => _currentPage;
|
|
private set
|
|
{
|
|
_currentPage = value;
|
|
PageChanged?.Invoke(value);
|
|
}
|
|
}
|
|
|
|
public ClientConnectionState ConnectionState => _clientNetManager.ClientConnectState;
|
|
|
|
public event Action<Page>? PageChanged;
|
|
public event Action<string?>? ConnectFailReasonChanged;
|
|
public event Action<ClientConnectionState>? ConnectionStateChanged;
|
|
|
|
protected override void Startup()
|
|
{
|
|
_control = new LauncherConnectingGui(this, _random, _prototypeManager, _cfg);
|
|
|
|
_userInterfaceManager.StateRoot.AddChild(_control);
|
|
|
|
_clientNetManager.ConnectFailed += OnConnectFailed;
|
|
_clientNetManager.ClientConnectStateChanged += OnConnectStateChanged;
|
|
|
|
CurrentPage = Page.Connecting;
|
|
}
|
|
|
|
protected override void Shutdown()
|
|
{
|
|
_control?.Dispose();
|
|
|
|
_clientNetManager.ConnectFailed -= OnConnectFailed;
|
|
_clientNetManager.ClientConnectStateChanged -= OnConnectStateChanged;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private void OnConnectStateChanged(ClientConnectionState state)
|
|
{
|
|
ConnectionStateChanged?.Invoke(state);
|
|
}
|
|
|
|
public void RetryConnect()
|
|
{
|
|
if (_gameController.LaunchState.ConnectEndpoint != null)
|
|
{
|
|
_baseClient.ConnectToServer(_gameController.LaunchState.ConnectEndpoint);
|
|
CurrentPage = Page.Connecting;
|
|
}
|
|
}
|
|
|
|
public bool Redial()
|
|
{
|
|
try
|
|
{
|
|
if (_gameController.LaunchState.Ss14Address != null)
|
|
{
|
|
_gameController.Redial(_gameController.LaunchState.Ss14Address);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Logger.GetSawmill("launcher-ui").Info($"Redial not possible, no Ss14Address");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.GetSawmill("launcher-ui").Error($"Redial exception: {ex}");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Exit()
|
|
{
|
|
_gameController.Shutdown("Exit button pressed");
|
|
}
|
|
|
|
public void SetDisconnected()
|
|
{
|
|
CurrentPage = Page.Disconnected;
|
|
}
|
|
|
|
public enum Page : byte
|
|
{
|
|
Connecting,
|
|
ConnectFailed,
|
|
Disconnected,
|
|
}
|
|
}
|
|
}
|