From 70318752bc9b70e0b963ed6ad04be27cd1fa30d2 Mon Sep 17 00:00:00 2001 From: HitPanda <104197232+EnefFlow@users.noreply.github.com> Date: Tue, 16 May 2023 15:33:15 +0300 Subject: [PATCH] [Feature] Socket ahelp tweak + unban command (#67) * pm event no_admins + entity * unban command --- .../Administration/Systems/BwoinkSystem.cs | 15 +++++- .../Commands/UtkaBanCommand.cs | 1 - .../Commands/UtkaUnbanCommand.cs | 51 +++++++++++++++++++ .../UtkaIntegration/UtkaCommunication.cs | 27 ++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 Content.Server/UtkaIntegration/Commands/UtkaUnbanCommand.cs diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 15ce037c7d..090a68dab5 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -634,12 +634,25 @@ namespace Content.Server.Administration.Systems private void UtkaSendAhelpPm(string message, string ckey, string sender) { + var adminManager = IoCManager.Resolve(); + var admins = adminManager.ActiveAdmins.Any(); + + var entity = ckey; + _playerManager.TryGetSessionByUsername(ckey, out var session); + if (session?.AttachedEntity != null) + { + var meta = MetaData((EntityUid) session.AttachedEntity); + entity = meta.EntityName; + } + var utkaAhelpEvent = new UtkaAhelpPmEvent() { Message = message, Ckey = ckey, Sender = sender, - Rid = Get().RoundId + Rid = Get().RoundId, + NoAdmins = !admins, + Entity = entity }; _utkaSockets.SendMessageToAll(utkaAhelpEvent); diff --git a/Content.Server/UtkaIntegration/Commands/UtkaBanCommand.cs b/Content.Server/UtkaIntegration/Commands/UtkaBanCommand.cs index 607068544f..d824016d3d 100644 --- a/Content.Server/UtkaIntegration/Commands/UtkaBanCommand.cs +++ b/Content.Server/UtkaIntegration/Commands/UtkaBanCommand.cs @@ -27,7 +27,6 @@ public sealed class UtkaBanCommand : IUtkaCommand var dbMan = IoCManager.Resolve(); IoCManager.InjectDependencies(this); - //_playerManager.TryGetSessionByUsername(message.ACkey!, out var player); var locatedPlayer = await locator.LookupIdByNameOrIdAsync(message.ACkey!); if (locatedPlayer == null) { diff --git a/Content.Server/UtkaIntegration/Commands/UtkaUnbanCommand.cs b/Content.Server/UtkaIntegration/Commands/UtkaUnbanCommand.cs new file mode 100644 index 0000000000..3d2476f1f6 --- /dev/null +++ b/Content.Server/UtkaIntegration/Commands/UtkaUnbanCommand.cs @@ -0,0 +1,51 @@ +using Content.Server.Administration; +using Content.Server.Database; + +namespace Content.Server.UtkaIntegration; + +public sealed class UtkaUnbanCommand : IUtkaCommand +{ + [Dependency] private UtkaTCPWrapper _utkaSocketWrapper = default!; + + public string Name => "unban"; + public Type RequestMessageType => typeof(UtkaUnbanRequest); + public async void Execute(UtkaTCPSession session, UtkaBaseMessage baseMessage) + { + if (baseMessage is not UtkaUnbanRequest message) return; + + var dbMan = IoCManager.Resolve(); + var locator = IoCManager.Resolve(); + IoCManager.InjectDependencies(this); + + var located = await locator.LookupIdByNameOrIdAsync(message.ACkey!); + if (located == null) + { + UtkaSendResponse(false); + return; + } + var player = located.UserId; + + var banId = (int) message.Bid!; + var ban = await dbMan.GetServerBanAsync(banId); + + if (ban == null || ban.Unban != null) + { + UtkaSendResponse(false); + return; + } + + await dbMan.AddServerUnbanAsync(new ServerUnbanDef(banId, player, DateTimeOffset.Now)); + + UtkaSendResponse(true); + } + + private void UtkaSendResponse(bool unbanned) + { + var utkaResponse = new UtkaUnbanResponse() + { + Unbanned = unbanned + }; + + _utkaSocketWrapper.SendMessageToAll(utkaResponse); + } +} diff --git a/Content.Server/UtkaIntegration/UtkaCommunication.cs b/Content.Server/UtkaIntegration/UtkaCommunication.cs index 5fb2515de4..61be54183e 100644 --- a/Content.Server/UtkaIntegration/UtkaCommunication.cs +++ b/Content.Server/UtkaIntegration/UtkaCommunication.cs @@ -187,6 +187,12 @@ public sealed class UtkaAhelpPmEvent : UtkaBaseMessage [JsonPropertyName("rid")] public int? Rid { get; set; } + + [JsonPropertyName("no_admins")] + public bool? NoAdmins { get; set; } + + [JsonPropertyName("entity")] + public string? Entity { get; set; } } public sealed class UtkaBannedEvent : UtkaBaseMessage @@ -289,3 +295,24 @@ public sealed class UtkaRestartRoundResponse : UtkaBaseMessage [JsonPropertyName("restarted")] public bool? Restarted { get; set; } } + +public sealed class UtkaUnbanRequest : UtkaBaseMessage +{ + [JsonPropertyName("command")] + public override string? Command => "unban"; + + [JsonPropertyName("a_ckey")] + public string? ACkey { get; set; } + + [JsonPropertyName("bid")] + public int? Bid { get; set; } +} + +public sealed class UtkaUnbanResponse : UtkaBaseMessage +{ + [JsonPropertyName("command")] + public override string? Command => "unban"; + + [JsonPropertyName("unbanned")] + public bool? Unbanned { get; set; } +}