Add ban list window (#12574)
This commit is contained in:
15
Content.Client/Administration/UI/BanList/BanListControl.xaml
Normal file
15
Content.Client/Administration/UI/BanList/BanListControl.xaml
Normal file
@@ -0,0 +1,15 @@
|
||||
<controls:BanListControl
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.Administration.UI.BanList"
|
||||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<graphics:StyleBoxFlat BackgroundColor="#25252A"/>
|
||||
</PanelContainer.PanelOverride>
|
||||
<ScrollContainer>
|
||||
<BoxContainer Name="Bans" Access="Public" Orientation="Vertical">
|
||||
<controls:BanListHeader Name="BansHeader"/>
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</PanelContainer>
|
||||
</controls:BanListControl>
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Linq;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
using Content.Shared.Administration.BanList;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BanListControl : Control
|
||||
{
|
||||
private BanListIdsPopup? _popup;
|
||||
|
||||
public BanListControl()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void SetBans(List<SharedServerBan> bans)
|
||||
{
|
||||
foreach (var control in Bans.Children.ToArray()[1..])
|
||||
{
|
||||
control.Orphan();
|
||||
}
|
||||
|
||||
foreach (var ban in bans)
|
||||
{
|
||||
Bans.AddChild(new HSeparator());
|
||||
|
||||
var line = new BanListLine(ban);
|
||||
line.OnIdsClicked += LineIdsClicked;
|
||||
|
||||
Bans.AddChild(line);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClosePopup()
|
||||
{
|
||||
_popup?.Close();
|
||||
_popup = null;
|
||||
}
|
||||
|
||||
private bool LineIdsClicked(BanListLine line)
|
||||
{
|
||||
ClosePopup();
|
||||
|
||||
var ban = line.Ban;
|
||||
var ip = ban.Address == null
|
||||
? string.Empty
|
||||
: Loc.GetString("ban-list-ip", ("ip", ban.Address.Value.address));
|
||||
var hwid = ban.HWId == null ? string.Empty : Loc.GetString("ban-list-hwid", ("hwid", ban.HWId));
|
||||
var guid = ban.UserId == null ? string.Empty : Loc.GetString("ban-list-guid", ("guid", ban.UserId.Value.ToString()));
|
||||
|
||||
_popup = new BanListIdsPopup(ip, hwid, guid);
|
||||
|
||||
var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, (1, 1));
|
||||
_popup.Open(box);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (_popup != null)
|
||||
{
|
||||
UserInterfaceManager.PopupRoot.RemoveChild(_popup);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Content.Client/Administration/UI/BanList/BanListEui.cs
Normal file
34
Content.Client/Administration/UI/BanList/BanListEui.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Administration.BanList;
|
||||
using Content.Shared.Eui;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
public sealed class BanListEui : BaseEui
|
||||
{
|
||||
public BanListEui()
|
||||
{
|
||||
BanWindow = new BanListWindow();
|
||||
BanControl = BanWindow.BanList;
|
||||
}
|
||||
|
||||
private BanListWindow BanWindow { get; }
|
||||
|
||||
private BanListControl BanControl { get; }
|
||||
|
||||
public override void HandleState(EuiStateBase state)
|
||||
{
|
||||
if (state is not BanListEuiState s)
|
||||
return;
|
||||
|
||||
BanWindow.SetTitlePlayer(s.BanListPlayerName);
|
||||
|
||||
s.Bans.Sort((a, b) => a.BanTime.CompareTo(b.BanTime));
|
||||
BanControl.SetBans(s.Bans);
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
BanWindow.OpenCentered();
|
||||
}
|
||||
}
|
||||
31
Content.Client/Administration/UI/BanList/BanListHeader.xaml
Normal file
31
Content.Client/Administration/UI/BanList/BanListHeader.xaml
Normal file
@@ -0,0 +1,31 @@
|
||||
<ContainerButton
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
|
||||
<PanelContainer Name="BackgroundPanel" Access="Public">
|
||||
<BoxContainer
|
||||
Orientation="Horizontal"
|
||||
HorizontalExpand="True"
|
||||
SeparationOverride="4">
|
||||
<Label Text="{Loc ban-list-header-ids}"
|
||||
SizeFlagsStretchRatio="1"
|
||||
HorizontalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Text="{Loc ban-list-header-reason}"
|
||||
SizeFlagsStretchRatio="6"
|
||||
HorizontalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Text="{Loc ban-list-header-time}"
|
||||
SizeFlagsStretchRatio="2"
|
||||
HorizontalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Text="{Loc ban-list-header-expires}"
|
||||
SizeFlagsStretchRatio="4"
|
||||
HorizontalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Text="{Loc ban-list-header-banning-admin}"
|
||||
SizeFlagsStretchRatio="2"
|
||||
HorizontalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</ContainerButton>
|
||||
@@ -0,0 +1,14 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BanListHeader : ContainerButton
|
||||
{
|
||||
public BanListHeader()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Popup xmlns="https://spacestation14.io"
|
||||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<graphics:StyleBoxFlat BackgroundColor="#25252A"/>
|
||||
</PanelContainer.PanelOverride>
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<Label Name="IP" HorizontalExpand="True"/>
|
||||
<Label Name="HWId" HorizontalExpand="True"/>
|
||||
<Label Name="GUID" HorizontalExpand="True"/>
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
</Popup>
|
||||
@@ -0,0 +1,20 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BanListIdsPopup : Popup
|
||||
{
|
||||
public BanListIdsPopup(string? ip, string? hwid, string? guid)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
IP.Text = ip;
|
||||
HWId.Text = hwid;
|
||||
GUID.Text = guid;
|
||||
|
||||
UserInterfaceManager.ModalRoot.AddChild(this);
|
||||
}
|
||||
}
|
||||
38
Content.Client/Administration/UI/BanList/BanListLine.xaml
Normal file
38
Content.Client/Administration/UI/BanList/BanListLine.xaml
Normal file
@@ -0,0 +1,38 @@
|
||||
<BoxContainer
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
|
||||
Orientation="Horizontal"
|
||||
HorizontalExpand="True"
|
||||
SeparationOverride="4">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
SizeFlagsStretchRatio="1"
|
||||
HorizontalExpand="True"
|
||||
RectClipContent="True">
|
||||
<Label Name="IdsHidden"
|
||||
Text="{Loc 'ban-list-hidden'}"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
MouseFilter="Pass"/>
|
||||
</BoxContainer>
|
||||
<cc:VSeparator/>
|
||||
<Label Name="Reason"
|
||||
SizeFlagsStretchRatio="6"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Name="BanTime"
|
||||
SizeFlagsStretchRatio="2"
|
||||
HorizontalExpand="True"
|
||||
ClipText="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Name="Expires"
|
||||
SizeFlagsStretchRatio="4"
|
||||
HorizontalExpand="True"
|
||||
ClipText="True"/>
|
||||
<cc:VSeparator/>
|
||||
<Label Name="BanningAdmin"
|
||||
SizeFlagsStretchRatio="2"
|
||||
HorizontalExpand="True"
|
||||
ClipText="True"/>
|
||||
<cc:VSeparator/>
|
||||
</BoxContainer>
|
||||
70
Content.Client/Administration/UI/BanList/BanListLine.xaml.cs
Normal file
70
Content.Client/Administration/UI/BanList/BanListLine.xaml.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Content.Shared.Administration.BanList;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Input;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BanListLine : BoxContainer
|
||||
{
|
||||
public readonly SharedServerBan Ban;
|
||||
|
||||
public event Func<BanListLine, bool>? OnIdsClicked;
|
||||
|
||||
public BanListLine(SharedServerBan ban)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Ban = ban;
|
||||
|
||||
IdsHidden.OnKeyBindDown += IdsKeyBindDown;
|
||||
|
||||
Reason.Text = ban.Reason;
|
||||
BanTime.Text = FormatDate(ban.BanTime);
|
||||
Expires.Text = ban.ExpirationTime == null
|
||||
? Loc.GetString("ban-list-permanent")
|
||||
: FormatDate(ban.ExpirationTime.Value);
|
||||
|
||||
if (ban.Unban is { } unban)
|
||||
{
|
||||
var unbanned = Loc.GetString("ban-list-unbanned", ("date", FormatDate(unban.UnbanTime)));
|
||||
var unbannedBy = unban.UnbanningAdmin == null
|
||||
? string.Empty
|
||||
: $"\n{Loc.GetString("ban-list-unbanned-by", ("unbanner", unban.UnbanningAdmin))}";
|
||||
|
||||
Expires.Text += $"\n{unbanned}{unbannedBy}";
|
||||
}
|
||||
|
||||
BanningAdmin.Text = ban.BanningAdminName;
|
||||
}
|
||||
|
||||
private static string FormatDate(DateTimeOffset date)
|
||||
{
|
||||
return date.ToString("MM/dd/yyyy h:mm tt");
|
||||
}
|
||||
|
||||
private void IdsKeyBindDown(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIRightClick &&
|
||||
args.Function != EngineKeyFunctions.UIClick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (OnIdsClicked?.Invoke(this) == true)
|
||||
{
|
||||
args.Handle();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
IdsHidden.OnKeyBindDown -= IdsKeyBindDown;
|
||||
OnIdsClicked = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<controls:BanListWindow
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:controls="clr-namespace:Content.Client.Administration.UI.BanList"
|
||||
SetSize="1400 400">
|
||||
<controls:BanListControl Name="BanList" Access="Public"/>
|
||||
</controls:BanListWindow>
|
||||
@@ -0,0 +1,19 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Administration.UI.BanList;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class BanListWindow : DefaultWindow
|
||||
{
|
||||
public BanListWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
}
|
||||
|
||||
public void SetTitlePlayer(string playerName)
|
||||
{
|
||||
Title = Loc.GetString("ban-list-title", ("player", playerName));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2">
|
||||
<BoxContainer Access="Public" Name="BwoinkArea" VerticalExpand="True" />
|
||||
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" />
|
||||
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" />
|
||||
<Button Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" />
|
||||
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" />
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#nullable enable
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Administration.Systems;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
using Content.Client.Administration.UI.Tabs.AdminTab;
|
||||
using Content.Client.Stylesheets;
|
||||
@@ -62,7 +60,7 @@ namespace Content.Client.Administration.UI
|
||||
sb.Append('●');
|
||||
else
|
||||
sb.Append(info.ActiveThisRound ? '○' : '·');
|
||||
|
||||
|
||||
sb.Append(' ');
|
||||
if (_adminAHelpHelper.TryGetChannel(info.SessionId, out var panel) && panel.Unread > 0)
|
||||
{
|
||||
@@ -106,6 +104,12 @@ namespace Content.Client.Administration.UI
|
||||
return bch!.LastMessage.CompareTo(ach!.LastMessage);
|
||||
};
|
||||
|
||||
Bans.OnPressed += _ =>
|
||||
{
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"banlist \"{_currentPlayer.SessionId}\"");
|
||||
};
|
||||
|
||||
Notes.OnPressed += _ =>
|
||||
{
|
||||
if (_currentPlayer is not null)
|
||||
@@ -170,6 +174,9 @@ namespace Content.Client.Administration.UI
|
||||
|
||||
private void FixButtons()
|
||||
{
|
||||
Bans.Visible = _adminManager.HasFlag(AdminFlags.Ban);
|
||||
Bans.Disabled = !Bans.Visible;
|
||||
|
||||
Notes.Visible = _adminManager.HasFlag(AdminFlags.ViewNotes);
|
||||
Notes.Disabled = !Notes.Visible;
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace Content.Client.Administration.UI.Notes;
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class AdminNotesControl : Control
|
||||
{
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
|
||||
public event Action<int, string>? OnNoteChanged;
|
||||
public event Action<string>? OnNewNoteEntered;
|
||||
public event Action<int>? OnNoteDeleted;
|
||||
@@ -53,7 +51,7 @@ public sealed partial class AdminNotesControl : Control
|
||||
OnNoteChanged?.Invoke(input.Id, text);
|
||||
}
|
||||
|
||||
private bool NoteRightClicked(AdminNotesLine line)
|
||||
private bool NoteClicked(AdminNotesLine line)
|
||||
{
|
||||
ClosePopup();
|
||||
|
||||
@@ -69,7 +67,7 @@ public sealed partial class AdminNotesControl : Control
|
||||
};
|
||||
_popup.OnDeletePressed += noteId => OnNoteDeleted?.Invoke(noteId);
|
||||
|
||||
var box = UIBox2.FromDimensions(_ui.MousePositionScaled.Position, (1, 1));
|
||||
var box = UIBox2.FromDimensions(UserInterfaceManager.MousePositionScaled.Position, (1, 1));
|
||||
_popup.Open(box);
|
||||
|
||||
return true;
|
||||
@@ -102,7 +100,7 @@ public sealed partial class AdminNotesControl : Control
|
||||
|
||||
input = new AdminNotesLine(note);
|
||||
input.OnSubmitted += NoteSubmitted;
|
||||
input.OnRightClicked += NoteRightClicked;
|
||||
input.OnClicked += NoteClicked;
|
||||
Notes.AddChild(input);
|
||||
Inputs[note.Id] = input;
|
||||
}
|
||||
@@ -136,7 +134,7 @@ public sealed partial class AdminNotesControl : Control
|
||||
|
||||
if (_popup != null)
|
||||
{
|
||||
_ui.PopupRoot.RemoveChild(_popup);
|
||||
UserInterfaceManager.PopupRoot.RemoveChild(_popup);
|
||||
}
|
||||
|
||||
OnNoteChanged = null;
|
||||
|
||||
@@ -30,7 +30,7 @@ public sealed partial class AdminNotesLine : BoxContainer
|
||||
public string EditText => _edit?.Text ?? OriginalMessage;
|
||||
|
||||
public event Action<AdminNotesLine>? OnSubmitted;
|
||||
public event Func<AdminNotesLine, bool>? OnRightClicked;
|
||||
public event Func<AdminNotesLine, bool>? OnClicked;
|
||||
|
||||
private void AddLabel()
|
||||
{
|
||||
@@ -92,7 +92,7 @@ public sealed partial class AdminNotesLine : BoxContainer
|
||||
return;
|
||||
}
|
||||
|
||||
if (OnRightClicked?.Invoke(this) == true)
|
||||
if (OnClicked?.Invoke(this) == true)
|
||||
{
|
||||
args.Handle();
|
||||
}
|
||||
@@ -137,6 +137,6 @@ public sealed partial class AdminNotesLine : BoxContainer
|
||||
}
|
||||
|
||||
OnSubmitted = null;
|
||||
OnRightClicked = null;
|
||||
OnClicked = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<Popup xmlns="https://spacestation14.io"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
|
||||
<PanelContainer>
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#25252A"/>
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
<cc:CommandButton Command="announceui" Text="{Loc admin-player-actions-window-announce}"/>
|
||||
<cc:UICommandButton Command="callshuttle" Text="{Loc admin-player-actions-window-shuttle}" WindowType="{x:Type at:AdminShuttleWindow}"/>
|
||||
<cc:CommandButton Command="adminlogs" Text="{Loc admin-player-actions-window-admin-logs}"/>
|
||||
<cc:CommandButton Command="adminnotes" Text="{Loc admin-player-actions-window-admin-notes}"/>
|
||||
</GridContainer>
|
||||
</BoxContainer>
|
||||
</Control>
|
||||
|
||||
95
Content.Server/Administration/BanList/BanListEui.cs
Normal file
95
Content.Server/Administration/BanList/BanListEui.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Database;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Administration.BanList;
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Server.Administration.BanList;
|
||||
|
||||
public sealed class BanListEui : BaseEui
|
||||
{
|
||||
[Dependency] private readonly IAdminManager _admins = default!;
|
||||
[Dependency] private readonly IPlayerLocator _playerLocator = default!;
|
||||
[Dependency] private readonly IServerDbManager _db = default!;
|
||||
|
||||
public BanListEui()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
private Guid BanListPlayer { get; set; }
|
||||
private string BanListPlayerName { get; set; } = string.Empty;
|
||||
private List<SharedServerBan> Bans { get; set; } = new();
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
base.Opened();
|
||||
|
||||
_admins.OnPermsChanged += OnPermsChanged;
|
||||
}
|
||||
|
||||
public override EuiStateBase GetNewState()
|
||||
{
|
||||
return new BanListEuiState(BanListPlayerName, Bans);
|
||||
}
|
||||
|
||||
private void OnPermsChanged(AdminPermsChangedEventArgs args)
|
||||
{
|
||||
if (args.Player == Player && !_admins.HasAdminFlag(Player, AdminFlags.Ban))
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
StateDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadFromDb()
|
||||
{
|
||||
Bans.Clear();
|
||||
|
||||
var userId = new NetUserId(BanListPlayer);
|
||||
BanListPlayerName = (await _playerLocator.LookupIdAsync(userId))?.Username ??
|
||||
string.Empty;
|
||||
|
||||
foreach (var ban in await _db.GetServerBansAsync(null, userId, null))
|
||||
{
|
||||
SharedServerUnban? unban = null;
|
||||
if (ban.Unban is { } unbanDef)
|
||||
{
|
||||
var unbanningAdmin = unbanDef.UnbanningAdmin == null
|
||||
? null
|
||||
: (await _playerLocator.LookupIdAsync(unbanDef.UnbanningAdmin.Value))?.Username;
|
||||
unban = new SharedServerUnban(unbanningAdmin, ban.Unban.UnbanTime.UtcDateTime);
|
||||
}
|
||||
|
||||
Bans.Add(new SharedServerBan(
|
||||
ban.Id,
|
||||
ban.UserId,
|
||||
ban.Address is { } address
|
||||
? (address.address.ToString(), address.cidrMask)
|
||||
: null,
|
||||
ban.HWId == null ? null : Convert.ToBase64String(ban.HWId.Value.AsSpan()),
|
||||
ban.BanTime.UtcDateTime,
|
||||
ban.ExpirationTime?.UtcDateTime,
|
||||
ban.Reason,
|
||||
ban.BanningAdmin == null
|
||||
? null
|
||||
: (await _playerLocator.LookupIdAsync(ban.BanningAdmin.Value))?.Username,
|
||||
unban
|
||||
));
|
||||
}
|
||||
|
||||
StateDirty();
|
||||
}
|
||||
|
||||
public async Task ChangeBanListPlayer(Guid banListPlayer)
|
||||
{
|
||||
BanListPlayer = banListPlayer;
|
||||
await LoadFromDb();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System.Text;
|
||||
using Content.Server.Database;
|
||||
using Content.Server.Administration.BanList;
|
||||
using Content.Server.EUI;
|
||||
using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
@@ -11,77 +10,44 @@ namespace Content.Server.Administration.Commands
|
||||
public sealed class BanListCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "banlist";
|
||||
public string Description => "Lists somebody's bans";
|
||||
public string Help => "Usage: <name or user ID>";
|
||||
public string Description => "Opens the ban list panel.";
|
||||
public string Help => $"Usage: {Command} <userid or username>";
|
||||
|
||||
public async void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
if (shell.Player is not IPlayerSession player)
|
||||
{
|
||||
shell.WriteLine($"Invalid amount of args. {Help}");
|
||||
shell.WriteError("This does not work from the server console.");
|
||||
return;
|
||||
}
|
||||
|
||||
var plyMgr = IoCManager.Resolve<IPlayerManager>();
|
||||
var dbMan = IoCManager.Resolve<IServerDbManager>();
|
||||
Guid banListPlayer;
|
||||
|
||||
var target = args[0];
|
||||
NetUserId targetUid;
|
||||
switch (args.Length)
|
||||
{
|
||||
case 1 when Guid.TryParse(args[0], out banListPlayer):
|
||||
break;
|
||||
case 1:
|
||||
var locator = IoCManager.Resolve<IPlayerLocator>();
|
||||
var dbGuid = await locator.LookupIdByNameAsync(args[0]);
|
||||
|
||||
if (plyMgr.TryGetSessionByUsername(target, out var targetSession))
|
||||
{
|
||||
targetUid = targetSession.UserId;
|
||||
}
|
||||
else if (Guid.TryParse(target, out var targetGuid))
|
||||
{
|
||||
targetUid = new NetUserId(targetGuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
shell.WriteLine("Unable to find user with that name.");
|
||||
return;
|
||||
if (dbGuid == null)
|
||||
{
|
||||
shell.WriteError($"Unable to find {args[0]} netuserid");
|
||||
return;
|
||||
}
|
||||
|
||||
banListPlayer = dbGuid.UserId;
|
||||
break;
|
||||
default:
|
||||
shell.WriteError($"Invalid arguments.\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
var bans = await dbMan.GetServerBansAsync(null, targetUid, null);
|
||||
|
||||
if (bans.Count == 0)
|
||||
{
|
||||
shell.WriteLine("That user has no bans in their record.");
|
||||
return;
|
||||
}
|
||||
|
||||
var bansString = new StringBuilder("Bans in record:\n");
|
||||
|
||||
foreach (var ban in bans)
|
||||
{
|
||||
bansString
|
||||
.Append("Ban ID: ")
|
||||
.Append(ban.Id)
|
||||
.Append("\n")
|
||||
.Append("Banned in ")
|
||||
.Append(ban.BanTime);
|
||||
|
||||
if (ban.ExpirationTime == null)
|
||||
{
|
||||
bansString.Append(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
bansString
|
||||
.Append(" until ")
|
||||
.Append(ban.ExpirationTime.Value)
|
||||
.Append(".");
|
||||
}
|
||||
|
||||
bansString.Append("\n");
|
||||
|
||||
bansString
|
||||
.Append("Reason: ")
|
||||
.Append(ban.Reason)
|
||||
.Append("\n\n");
|
||||
}
|
||||
|
||||
shell.WriteLine(bansString.ToString());
|
||||
var euis = IoCManager.Resolve<EuiManager>();
|
||||
var ui = new BanListEui();
|
||||
euis.OpenEui(ui, player);
|
||||
await ui.ChangeBanListPlayer(banListPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using Content.Shared.Administration;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Ban)]
|
||||
@@ -27,7 +26,7 @@ namespace Content.Server.Administration.Commands
|
||||
|
||||
if (!int.TryParse(args[0], out var banId))
|
||||
{
|
||||
shell.WriteLine($"Unable to parse {args[1]} as a ban id integer.\n{Help}");
|
||||
shell.WriteLine($"Unable to parse {args[0]} as a ban id integer.\n{Help}");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
17
Content.Shared/Administration/BanList/BanListEuiState.cs
Normal file
17
Content.Shared/Administration/BanList/BanListEuiState.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Content.Shared.Eui;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Administration.BanList;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BanListEuiState : EuiStateBase
|
||||
{
|
||||
public BanListEuiState(string banListPlayerName, List<SharedServerBan> bans)
|
||||
{
|
||||
BanListPlayerName = banListPlayerName;
|
||||
Bans = bans;
|
||||
}
|
||||
|
||||
public string BanListPlayerName { get; }
|
||||
public List<SharedServerBan> Bans { get; }
|
||||
}
|
||||
17
Content.Shared/Administration/BanList/SharedServerBan.cs
Normal file
17
Content.Shared/Administration/BanList/SharedServerBan.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Robust.Shared.Network;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Administration.BanList;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed record SharedServerBan(
|
||||
int? Id,
|
||||
NetUserId? UserId,
|
||||
(string address, int cidrMask)? Address,
|
||||
string? HWId,
|
||||
DateTime BanTime,
|
||||
DateTime? ExpirationTime,
|
||||
string Reason,
|
||||
string? BanningAdminName,
|
||||
SharedServerUnban? Unban
|
||||
);
|
||||
@@ -0,0 +1,9 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Administration.BanList;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed record SharedServerUnban(
|
||||
string? UnbanningAdmin,
|
||||
DateTime UnbanTime
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
admin-player-actions-bans = Ban List
|
||||
admin-player-actions-notes = Notes
|
||||
admin-player-actions-kick = Kick
|
||||
admin-player-actions-ban = Ban
|
||||
|
||||
15
Resources/Locale/en-US/administration/ui/ban-list.ftl
Normal file
15
Resources/Locale/en-US/administration/ui/ban-list.ftl
Normal file
@@ -0,0 +1,15 @@
|
||||
# UI
|
||||
ban-list-header-ids = Ids
|
||||
ban-list-header-reason = Reason
|
||||
ban-list-header-time = Ban time
|
||||
ban-list-header-expires = Expires
|
||||
ban-list-header-banning-admin = Banning admin
|
||||
|
||||
ban-list-title = Bans for {$player}
|
||||
ban-list-hidden = Hidden
|
||||
ban-list-ip = IP: {$ip}
|
||||
ban-list-hwid = HWID: {$hwid}
|
||||
ban-list-guid = GUID: {$guid}
|
||||
ban-list-permanent = PERMANENT
|
||||
ban-list-unbanned = Unbanned: {$date}
|
||||
ban-list-unbanned-by = By {$unbanner}
|
||||
Reference in New Issue
Block a user