ExtendedDisconnectInformationManager.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using Robust.Client;
  3. using Robust.Client.UserInterface;
  4. using Robust.Shared.IoC;
  5. using Robust.Shared.Log;
  6. using Robust.Shared.Network;
  7. namespace Content.Client.Launcher;
  8. /// <summary>
  9. /// So apparently the way that disconnect information is shipped around is really indirect.
  10. /// But honestly, given that content might have additional flags (i.e. hide disconnect button for bans)?
  11. /// This is responsible for collecting any extended disconnect information.
  12. /// </summary>
  13. public sealed class ExtendedDisconnectInformationManager
  14. {
  15. [Dependency] private readonly IClientNetManager _clientNetManager = default!;
  16. private NetDisconnectedArgs? _lastNetDisconnectedArgs = null;
  17. public NetDisconnectedArgs? LastNetDisconnectedArgs
  18. {
  19. get => _lastNetDisconnectedArgs;
  20. private set
  21. {
  22. _lastNetDisconnectedArgs = value;
  23. LastNetDisconnectedArgsChanged?.Invoke(value);
  24. }
  25. }
  26. // BE CAREFUL!
  27. // This may fire at an arbitrary time before or after whatever code that needs it.
  28. public event Action<NetDisconnectedArgs?>? LastNetDisconnectedArgsChanged;
  29. public void Initialize()
  30. {
  31. _clientNetManager.Disconnect += OnNetDisconnect;
  32. }
  33. private void OnNetDisconnect(object? sender, NetDisconnectedArgs args)
  34. {
  35. LastNetDisconnectedArgs = args;
  36. }
  37. }