Skip to content

Commit

Permalink
Another ban notifications fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MilenVolf committed Jul 27, 2023
1 parent 0f18859 commit 5740e63
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
4 changes: 0 additions & 4 deletions Content.Server/Administration/Commands/BanCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using Content.Server.Arumoon.BansNotifications;
using Content.Server.Administration.Managers;
using Content.Server.Administration.Notes;
using Content.Server.Database;
Expand All @@ -26,7 +25,6 @@ public sealed class BanCommand : LocalizedCommands
[Dependency] private readonly IBanManager _bans = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IBansNotificationsSystem _arumoonBans = default!;

public override string Command => "ban";

Expand Down Expand Up @@ -96,10 +94,8 @@ public override async void Execute(IConsoleShell shell, string argStr, string[]

var targetUid = located.UserId;
var targetHWid = located.LastHWId;
var expires = DateTimeOffset.Now + TimeSpan.FromMinutes(minutes);

_bans.CreateServerBan(targetUid, target, player?.UserId, null, targetHWid, minutes, severity, reason);
_arumoonBans.RaiseLocalBanEvent(located.Username, expires, reason);
}

public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Content.Server.Arumoon.BansNotifications;
using Content.Server.Administration.Managers;
using Content.Shared.Administration;
using Content.Shared.CCVar;
Expand All @@ -17,7 +16,6 @@ public sealed class DepartmentBanCommand : IConsoleCommand
[Dependency] private readonly IPlayerLocator _locator = default!;
[Dependency] private readonly IBanManager _banManager = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IBansNotificationsSystem _arumoonBans = default!;

public string Command => "departmentban";
public string Description => Loc.GetString("cmd-departmentban-desc");
Expand Down Expand Up @@ -97,13 +95,10 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args)
// If you are trying to remove the following variable, please don't. It's there because the note system groups role bans by time, reason and banning admin.
// Without it the note list will get needlessly cluttered.
var now = DateTimeOffset.UtcNow;
var expires = DateTimeOffset.Now + TimeSpan.FromMinutes(minutes);
foreach (var job in departmentProto.Roles)
{
_banManager.CreateRoleBan(targetUid, located.Username, shell.Player?.UserId, null, targetHWid, job, minutes, severity, reason, now);
}

_arumoonBans.RaiseLocalDepartmentBanEvent(located.Username, expires, departmentProto, reason);
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
Expand Down
12 changes: 0 additions & 12 deletions Content.Server/Administration/Commands/RoleBanCommand.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
using System.Linq;
using System.Text;
using Content.Server.Arumoon.BansNotifications;
using Content.Server.Administration.Managers;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Database;
using Content.Shared.Roles;
using Robust.Shared.Configuration;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;

namespace Content.Server.Administration.Commands;

[AdminCommand(AdminFlags.Ban)]
public sealed class RoleBanCommand : IConsoleCommand
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IPlayerLocator _locator = default!;
[Dependency] private readonly IBanManager _bans = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IBansNotificationsSystem _arumoonBans = default!;

public string Command => "roleban";
public string Description => Loc.GetString("cmd-roleban-desc");
Expand Down Expand Up @@ -80,11 +75,6 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args)
shell.WriteLine(Help);
return;
}

if (!_protoManager.TryIndex(job, out JobPrototype? jobPrototype))
{
return;
}

var located = await _locator.LookupIdByNameOrIdAsync(target);
if (located == null)
Expand All @@ -95,10 +85,8 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args)

var targetUid = located.UserId;
var targetHWid = located.LastHWId;
var expires = DateTimeOffset.Now + TimeSpan.FromMinutes(minutes);

_bans.CreateRoleBan(targetUid, located.Username, shell.Player?.UserId, null, targetHWid, job, minutes, severity, reason, DateTimeOffset.UtcNow);
_arumoonBans.RaiseLocalJobBanEvent(located.Username, expires, jobPrototype, reason);
}

public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
Expand Down
8 changes: 7 additions & 1 deletion Content.Server/Administration/Managers/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Content.Server.Arumoon.BansNotifications;
using Content.Server.Chat.Managers;
using Content.Server.Database;
using Content.Server.GameTicking;
Expand Down Expand Up @@ -29,6 +30,7 @@ public sealed class BanManager : IBanManager, IPostInjectInit
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly INetManager _netManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly IBansNotificationsSystem _arumoonBans = default!;

private ISawmill _sawmill = default!;

Expand Down Expand Up @@ -167,6 +169,8 @@ public async void CreateServerBan(NetUserId? target, string? targetUsername, Net
// If they are, kick them
var message = banDef.FormatBanMessage(_cfg, _localizationManager);
targetPlayer.ConnectedClient.Disconnect(message);

_arumoonBans.RaiseLocalBanEvent(targetUsername ?? "null", expires, reason);
}
#endregion

Expand All @@ -175,7 +179,7 @@ public async void CreateServerBan(NetUserId? target, string? targetUsername, Net
// Removing it will clutter the note list. Please also make sure that department bans are applied to roles with the same DateTimeOffset.
public async void CreateRoleBan(NetUserId? target, string? targetUsername, NetUserId? banningAdmin, (IPAddress, int)? addressRange, ImmutableArray<byte>? hwid, string role, uint? minutes, NoteSeverity severity, string reason, DateTimeOffset timeOfBan)
{
if (!_prototypeManager.TryIndex(role, out JobPrototype? _))
if (!_prototypeManager.TryIndex(role, out JobPrototype? jobPrototype))
{
throw new ArgumentException($"Invalid role '{role}'", nameof(role));
}
Expand Down Expand Up @@ -219,6 +223,8 @@ public async void CreateRoleBan(NetUserId? target, string? targetUsername, NetUs
{
SendRoleBans(target.Value);
}

_arumoonBans.RaiseLocalJobBanEvent(targetUsername ?? "null", expires, jobPrototype, reason);
}

public HashSet<string>? GetJobBans(NetUserId playerUserId)
Expand Down

0 comments on commit 5740e63

Please sign in to comment.