Re-organize all projects (#4166)
This commit is contained in:
147
Content.Client/Administration/Managers/AdminMenuManager.cs
Normal file
147
Content.Client/Administration/Managers/AdminMenuManager.cs
Normal file
@@ -0,0 +1,147 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.Administration.UI;
|
||||
using Content.Client.HUD;
|
||||
using Content.Shared.Administration.Menu;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Client.Administration.Managers
|
||||
{
|
||||
internal class AdminMenuManager : IAdminMenuManager
|
||||
{
|
||||
[Dependency] private readonly INetManager _netManager = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
[Dependency] private readonly IClientAdminManager _clientAdminManager = default!;
|
||||
[Dependency] private readonly IClientConGroupController _clientConGroupController = default!;
|
||||
|
||||
private AdminMenuWindow? _window;
|
||||
private List<SS14Window> _commandWindows = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<AdminMenuPlayerListRequest>(AdminMenuPlayerListRequest.NAME);
|
||||
_netManager.RegisterNetMessage<AdminMenuPlayerListMessage>(AdminMenuPlayerListMessage.NAME, HandlePlayerListMessage);
|
||||
|
||||
_commandWindows = new List<SS14Window>();
|
||||
// Reset the AdminMenu Window on disconnect
|
||||
_netManager.Disconnect += (_, _) => ResetWindow();
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.OpenAdminMenu,
|
||||
InputCmdHandler.FromDelegate(_ => Toggle()));
|
||||
|
||||
_clientAdminManager.AdminStatusUpdated += () =>
|
||||
{
|
||||
// when status changes, show the top button if we can open admin menu.
|
||||
// if we can't or we lost admin status, close it and hide the button.
|
||||
_gameHud.AdminButtonVisible = CanOpen();
|
||||
if (!_gameHud.AdminButtonVisible)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
};
|
||||
_gameHud.AdminButtonToggled += (open) =>
|
||||
{
|
||||
if (open)
|
||||
{
|
||||
TryOpen();
|
||||
}
|
||||
else
|
||||
{
|
||||
Close();
|
||||
}
|
||||
};
|
||||
_gameHud.AdminButtonVisible = CanOpen();
|
||||
_gameHud.AdminButtonDown = false;
|
||||
}
|
||||
|
||||
private void RequestPlayerList()
|
||||
{
|
||||
var message = _netManager.CreateNetMessage<AdminMenuPlayerListRequest>();
|
||||
|
||||
_netManager.ClientSendMessage(message);
|
||||
}
|
||||
|
||||
private void HandlePlayerListMessage(AdminMenuPlayerListMessage msg)
|
||||
{
|
||||
_window?.RefreshPlayerList(msg.PlayersInfo);
|
||||
}
|
||||
|
||||
public void ResetWindow()
|
||||
{
|
||||
_window?.Close();
|
||||
_window = null;
|
||||
|
||||
foreach (var window in _commandWindows)
|
||||
window?.Dispose();
|
||||
_commandWindows.Clear();
|
||||
}
|
||||
|
||||
public void OpenCommand(SS14Window window)
|
||||
{
|
||||
_commandWindows.Add(window);
|
||||
window.OpenCentered();
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
_window ??= new AdminMenuWindow();
|
||||
_window.OnPlayerListRefresh += RequestPlayerList;
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_window?.Close();
|
||||
|
||||
foreach (var window in _commandWindows)
|
||||
window?.Dispose();
|
||||
_commandWindows.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the player can open the window
|
||||
/// </summary>
|
||||
/// <returns>True if the player is allowed</returns>
|
||||
public bool CanOpen()
|
||||
{
|
||||
return _clientConGroupController.CanAdminMenu();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the player can open the window and tries to open it
|
||||
/// </summary>
|
||||
public void TryOpen()
|
||||
{
|
||||
if (CanOpen())
|
||||
Open();
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
if (_window != null && _window.IsOpen)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
TryOpen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal interface IAdminMenuManager
|
||||
{
|
||||
void Initialize();
|
||||
void Open();
|
||||
void OpenCommand(SS14Window window);
|
||||
bool CanOpen();
|
||||
void TryOpen();
|
||||
void Toggle();
|
||||
}
|
||||
}
|
||||
89
Content.Client/Administration/Managers/ClientAdminManager.cs
Normal file
89
Content.Client/Administration/Managers/ClientAdminManager.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Client.Administration.Managers
|
||||
{
|
||||
public class ClientAdminManager : IClientAdminManager, IClientConGroupImplementation, IPostInjectInit
|
||||
{
|
||||
[Dependency] private readonly IClientNetManager _netMgr = default!;
|
||||
[Dependency] private readonly IClientConGroupController _conGroup = default!;
|
||||
|
||||
private AdminData? _adminData;
|
||||
private readonly HashSet<string> _availableCommands = new();
|
||||
|
||||
public event Action? AdminStatusUpdated;
|
||||
|
||||
public bool IsActive()
|
||||
{
|
||||
return _adminData?.Active ?? false;
|
||||
}
|
||||
|
||||
public bool HasFlag(AdminFlags flag)
|
||||
{
|
||||
return _adminData?.HasFlag(flag) ?? false;
|
||||
}
|
||||
|
||||
public bool CanCommand(string cmdName)
|
||||
{
|
||||
return _availableCommands.Contains(cmdName);
|
||||
}
|
||||
|
||||
public bool CanViewVar()
|
||||
{
|
||||
return _adminData?.CanViewVar() ?? false;
|
||||
}
|
||||
|
||||
public bool CanAdminPlace()
|
||||
{
|
||||
return _adminData?.CanAdminPlace() ?? false;
|
||||
}
|
||||
|
||||
public bool CanScript()
|
||||
{
|
||||
return _adminData?.CanScript() ?? false;
|
||||
}
|
||||
|
||||
public bool CanAdminMenu()
|
||||
{
|
||||
return _adminData?.CanAdminMenu() ?? false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_netMgr.RegisterNetMessage<MsgUpdateAdminStatus>(MsgUpdateAdminStatus.NAME, UpdateMessageRx);
|
||||
}
|
||||
|
||||
private void UpdateMessageRx(MsgUpdateAdminStatus message)
|
||||
{
|
||||
_availableCommands.Clear();
|
||||
_availableCommands.UnionWith(message.AvailableCommands);
|
||||
Logger.DebugS("admin", $"Have {message.AvailableCommands.Length} commands available");
|
||||
|
||||
_adminData = message.Admin;
|
||||
if (_adminData != null)
|
||||
{
|
||||
var flagsText = string.Join("|", AdminFlagsHelper.FlagsToNames(_adminData.Flags));
|
||||
Logger.InfoS("admin", $"Updated admin status: {_adminData.Active}/{_adminData.Title}/{flagsText}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.InfoS("admin", "Updated admin status: Not admin");
|
||||
}
|
||||
|
||||
AdminStatusUpdated?.Invoke();
|
||||
ConGroupUpdated?.Invoke();
|
||||
}
|
||||
|
||||
public event Action? ConGroupUpdated;
|
||||
|
||||
void IPostInjectInit.PostInject()
|
||||
{
|
||||
_conGroup.Implementation = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using Content.Shared.Administration;
|
||||
|
||||
namespace Content.Client.Administration.Managers
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages server admin permissions for the local player.
|
||||
/// </summary>
|
||||
public interface IClientAdminManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Fired when the admin status of the local player changes, such as losing admin privileges.
|
||||
/// </summary>
|
||||
event Action AdminStatusUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the local player is an admin.
|
||||
/// </summary>
|
||||
/// <returns>true if the local player is an admin, false otherwise even if they are deadminned.</returns>
|
||||
bool IsActive();
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether the local player has an admin flag.
|
||||
/// </summary>
|
||||
/// <param name="flag">The flags to check. Multiple flags can be specified, they must all be held.</param>
|
||||
/// <returns>False if the local player is not an admin, inactive, or does not have all the flags specified.</returns>
|
||||
bool HasFlag(AdminFlags flag);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a player can execute a specified console command.
|
||||
/// </summary>
|
||||
bool CanCommand(string cmdName);
|
||||
|
||||
/// <summary>
|
||||
/// Check if the local player can open the VV menu.
|
||||
/// </summary>
|
||||
bool CanViewVar();
|
||||
|
||||
/// <summary>
|
||||
/// Check if the local player can spawn stuff in with the entity/tile spawn panel.
|
||||
/// </summary>
|
||||
bool CanAdminPlace();
|
||||
|
||||
/// <summary>
|
||||
/// Check if the local player can execute server-side C# scripts.
|
||||
/// </summary>
|
||||
bool CanScript();
|
||||
|
||||
/// <summary>
|
||||
/// Check if the local player can open the admin menu.
|
||||
/// </summary>
|
||||
bool CanAdminMenu();
|
||||
|
||||
void Initialize();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user