From fdb80c85377e672a76e2e676d83f1f59da5f5e52 Mon Sep 17 00:00:00 2001 From: HitPanda <104197232+EnefFlow@users.noreply.github.com> Date: Tue, 23 May 2023 12:31:20 +0300 Subject: [PATCH] [Feat] Socket unjobban command (#78) * Socket unjobban command * fix for CPR system --- .../Body/Systems/RespiratorSystem.cs | 5 +- .../Commands/UtkaUnJobBanCommand.cs | 57 +++++++++++++++++++ .../UtkaIntegration/UtkaCommunication.cs | 21 +++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 Content.Server/UtkaIntegration/Commands/UtkaUnJobBanCommand.cs diff --git a/Content.Server/Body/Systems/RespiratorSystem.cs b/Content.Server/Body/Systems/RespiratorSystem.cs index 9eef980ebf..378ce439fc 100644 --- a/Content.Server/Body/Systems/RespiratorSystem.cs +++ b/Content.Server/Body/Systems/RespiratorSystem.cs @@ -235,10 +235,9 @@ namespace Content.Server.Body.Systems // WD start private void OnHandInteract(EntityUid uid, RespiratorComponent component, InteractHandEvent args) { - if (!CanCPR(uid, component, args.User)) - return; + if (CanCPR(uid, component, args.User)) + DoCPR(uid, component, args.User); - DoCPR(uid, component, args.User); args.Handled = true; } diff --git a/Content.Server/UtkaIntegration/Commands/UtkaUnJobBanCommand.cs b/Content.Server/UtkaIntegration/Commands/UtkaUnJobBanCommand.cs new file mode 100644 index 0000000000..1a1db48ab7 --- /dev/null +++ b/Content.Server/UtkaIntegration/Commands/UtkaUnJobBanCommand.cs @@ -0,0 +1,57 @@ +using Content.Server.Administration; +using Content.Server.Database; + +namespace Content.Server.UtkaIntegration; + +public sealed class UtkaUnJobBanCommand : IUtkaCommand +{ + [Dependency] private UtkaTCPWrapper _utkaSocketWrapper = default!; + + public string Name => "unjobban"; + public Type RequestMessageType => typeof(UtkaUnJobBanRequest); + public async void Execute(UtkaTCPSession session, UtkaBaseMessage baseMessage) + { + if (baseMessage is not UtkaUnJobBanRequest 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 ban = await dbMan.GetServerRoleBanAsync(message.Bid!.Value); + if (ban == null || ban.Unban != null) + { + UtkaSendResponse(false); + return; + } + + var adminData = await dbMan.GetAdminDataForAsync(player); + if (adminData?.AdminRank == null || ban.ServerName != "unknown" && adminData.AdminServer is not (null or "unknown") && adminData.AdminServer != ban.ServerName) + { + UtkaSendResponse(false); + return; + } + + await dbMan.AddServerRoleUnbanAsync(new ServerRoleUnbanDef(message.Bid!.Value, player, DateTimeOffset.Now)); + + UtkaSendResponse(true); + } + + private void UtkaSendResponse(bool unbanned) + { + var utkaResponse = new UtkaUnJobBanResponse() + { + Unbanned = unbanned + }; + + _utkaSocketWrapper.SendMessageToAll(utkaResponse); + } +} diff --git a/Content.Server/UtkaIntegration/UtkaCommunication.cs b/Content.Server/UtkaIntegration/UtkaCommunication.cs index 61be54183e..ca4d3140a4 100644 --- a/Content.Server/UtkaIntegration/UtkaCommunication.cs +++ b/Content.Server/UtkaIntegration/UtkaCommunication.cs @@ -316,3 +316,24 @@ public sealed class UtkaUnbanResponse : UtkaBaseMessage [JsonPropertyName("unbanned")] public bool? Unbanned { get; set; } } + +public sealed class UtkaUnJobBanRequest : UtkaBaseMessage +{ + [JsonPropertyName("command")] + public override string? Command => "unjobban"; + + [JsonPropertyName("a_ckey")] + public string? ACkey { get; set; } + + [JsonPropertyName("bid")] + public int? Bid { get; set; } +} + +public sealed class UtkaUnJobBanResponse : UtkaBaseMessage +{ + [JsonPropertyName("command")] + public override string? Command => "unjobban"; + + [JsonPropertyName("unbanned")] + public bool? Unbanned { get; set; } +}