]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Ban message improvements (#14731)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sun, 19 Mar 2023 00:55:12 +0000 (01:55 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Mar 2023 00:55:12 +0000 (19:55 -0500)
Server config now provide appeals forum link, game admins won't need to type it out manually anymore.
Add warning about trying to ban evade.
Cleaned up code a bit.

Content.Server/Administration/Commands/BanCommand.cs
Content.Server/Connection/ConnectionManager.cs
Content.Server/Database/ServerBanDef.cs
Content.Shared/CCVar/CCVars.cs
Resources/ConfigPresets/WizardsDen/wizardsDen.toml
Resources/Locale/en-US/connection-messages.ftl

index b6102f7f1d1d045a2f78502f4f05e3f691661591..eeeb34e54c007f03fc59bdb9d1e3747c37ede7e6 100644 (file)
@@ -5,19 +5,20 @@ using System.Text;
 using Content.Server.Database;
 using Content.Shared.Administration;
 using Robust.Server.Player;
+using Robust.Shared.Configuration;
 using Robust.Shared.Console;
 
 
 namespace Content.Server.Administration.Commands
 {
     [AdminCommand(AdminFlags.Ban)]
-    public sealed class BanCommand : IConsoleCommand
+    public sealed class BanCommand : LocalizedCommands
     {
-        public string Command => "ban";
-        public string Description => Loc.GetString("cmd-ban-desc");
-        public string Help => Loc.GetString("cmd-ban-help", ("Command", Command));
+        [Dependency] private readonly IConfigurationManager _cfg = default!;
 
-        public async void Execute(IConsoleShell shell, string argStr, string[] args)
+        public override string Command => "ban";
+
+        public override async void Execute(IConsoleShell shell, string argStr, string[] args)
         {
             var player = shell.Player as IPlayerSession;
             var plyMgr = IoCManager.Resolve<IPlayerManager>();
@@ -54,7 +55,7 @@ namespace Content.Server.Administration.Commands
             var located = await locator.LookupIdByNameOrIdAsync(target);
             if (located == null)
             {
-                shell.WriteError(Loc.GetString("cmd-ban-player"));
+                shell.WriteError(LocalizationManager.GetString("cmd-ban-player"));
                 return;
             }
 
@@ -64,7 +65,7 @@ namespace Content.Server.Administration.Commands
 
             if (player != null && player.UserId == targetUid)
             {
-                shell.WriteLine(Loc.GetString("cmd-ban-self"));
+                shell.WriteLine(LocalizationManager.GetString("cmd-ban-self"));
                 return;
             }
 
@@ -100,43 +101,42 @@ namespace Content.Server.Administration.Commands
 
             var response = new StringBuilder($"Banned {target} with reason \"{reason}\"");
 
-            response.Append(expires == null ?
-                " permanently."
-                : $" until {expires}");
+            response.Append(expires == null ? " permanently." : $" until {expires}");
 
             shell.WriteLine(response.ToString());
 
             if (plyMgr.TryGetSessionById(targetUid, out var targetPlayer))
             {
-                targetPlayer.ConnectedClient.Disconnect(banDef.DisconnectMessage);
+                var message = banDef.FormatBanMessage(_cfg, LocalizationManager);
+                targetPlayer.ConnectedClient.Disconnect(message);
             }
         }
 
-        public CompletionResult GetCompletion(IConsoleShell shell, string[] args)
+        public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
         {
             if (args.Length == 1)
             {
                 var playerMgr = IoCManager.Resolve<IPlayerManager>();
                 var options = playerMgr.ServerSessions.Select(c => c.Name).OrderBy(c => c).ToArray();
-                return CompletionResult.FromHintOptions(options, Loc.GetString("cmd-ban-hint"));
+                return CompletionResult.FromHintOptions(options, LocalizationManager.GetString("cmd-ban-hint"));
             }
 
             if (args.Length == 2)
-                return CompletionResult.FromHint(Loc.GetString("cmd-ban-hint-reason"));
+                return CompletionResult.FromHint(LocalizationManager.GetString("cmd-ban-hint-reason"));
 
             if (args.Length == 3)
             {
                 var durations = new CompletionOption[]
                 {
-                    new("0", Loc.GetString("cmd-ban-hint-duration-1")),
-                    new("1440", Loc.GetString("cmd-ban-hint-duration-2")),
-                    new("4320", Loc.GetString("cmd-ban-hint-duration-3")),
-                    new("10080", Loc.GetString("cmd-ban-hint-duration-4")),
-                    new("20160", Loc.GetString("cmd-ban-hint-duration-5")),
-                    new("43800", Loc.GetString("cmd-ban-hint-duration-6")),
+                    new("0", LocalizationManager.GetString("cmd-ban-hint-duration-1")),
+                    new("1440", LocalizationManager.GetString("cmd-ban-hint-duration-2")),
+                    new("4320", LocalizationManager.GetString("cmd-ban-hint-duration-3")),
+                    new("10080", LocalizationManager.GetString("cmd-ban-hint-duration-4")),
+                    new("20160", LocalizationManager.GetString("cmd-ban-hint-duration-5")),
+                    new("43800", LocalizationManager.GetString("cmd-ban-hint-duration-6")),
                 };
 
-                return CompletionResult.FromHintOptions(durations, Loc.GetString("cmd-ban-hint-duration"));
+                return CompletionResult.FromHintOptions(durations, LocalizationManager.GetString("cmd-ban-hint-duration"));
             }
 
             return CompletionResult.Empty;
index febdb56e326de72359723d4cd55382a552f09872..43ba601f777635b44213c61c10976dc4dff43a0a 100644 (file)
@@ -28,6 +28,7 @@ namespace Content.Server.Connection
         [Dependency] private readonly IServerNetManager _netMgr = default!;
         [Dependency] private readonly IServerDbManager _db = default!;
         [Dependency] private readonly IConfigurationManager _cfg = default!;
+        [Dependency] private readonly ILocalizationManager _loc = default!;
 
         public void Initialize()
         {
@@ -147,7 +148,8 @@ namespace Content.Server.Connection
             if (bans.Count > 0)
             {
                 var firstBan = bans[0];
-                return (ConnectionDenyReason.Ban, firstBan.DisconnectMessage, bans);
+                var message = firstBan.FormatBanMessage(_cfg, _loc);
+                return (ConnectionDenyReason.Ban, message, bans);
             }
 
             if (_cfg.GetCVar(CCVars.WhitelistEnabled))
index 755365ca45aad3de6f352d6abf7b5907656e113f..d5bc677184e8fbfcc791c223b423a0ddbe4f3baa 100644 (file)
@@ -1,5 +1,7 @@
 using System.Collections.Immutable;
 using System.Net;
+using Content.Shared.CCVar;
+using Robust.Shared.Configuration;
 using Robust.Shared.Network;
 
 
@@ -52,19 +54,30 @@ namespace Content.Server.Database
             Unban = unban;
         }
 
-        public string DisconnectMessage
+        public string FormatBanMessage(IConfigurationManager cfg, ILocalizationManager loc)
         {
-            get {
-                var expires = Loc.GetString("ban-banned-permanent");
-                if (this.ExpirationTime is { } expireTime)
-                {
-                    var duration = expireTime - this.BanTime;
-                    var utc = expireTime.ToUniversalTime();
-                    expires = Loc.GetString("ban-expires", ("duration", duration.TotalMinutes.ToString("N0")), ("time", utc.ToString("f")));
-                }
-                var details = Loc.GetString("ban-banned-1") + "\n" + Loc.GetString("ban-banned-2", ("reason", this.Reason)) + "\n" + expires;
-                return details;
+            string expires;
+            if (ExpirationTime is { } expireTime)
+            {
+                var duration = expireTime - BanTime;
+                var utc = expireTime.ToUniversalTime();
+                expires = loc.GetString("ban-expires", ("duration", duration.TotalMinutes.ToString("N0")), ("time", utc.ToString("f")));
+            }
+            else
+            {
+                var appeal = cfg.GetCVar(CCVars.InfoLinksAppeal);
+                if (!string.IsNullOrWhiteSpace(appeal))
+                    expires = loc.GetString("ban-banned-permanent-appeal", ("link", appeal));
+                else
+                    expires = loc.GetString("ban-banned-permanent");
             }
+
+            return $"""
+                   {loc.GetString("ban-banned-1")}
+                   {loc.GetString("ban-banned-2", ("reason", Reason))}
+                   {expires}
+                   {loc.GetString("ban-banned-3")}
+                   """;
         }
     }
 }
index 708796067de04103fafa05dba2fc1b01c455ddb4..38018ed84b64bd50d23c5ebb048c6dfbd94f3bca 100644 (file)
@@ -1475,6 +1475,12 @@ namespace Content.Shared.CCVar
         public static readonly CVarDef<string> InfoLinksBugReport =
             CVarDef.Create("infolinks.bug_report", "", CVar.SERVER | CVar.REPLICATED);
 
+        /// <summary>
+        /// Link to site handling ban appeals. Shown in ban disconnect messages.
+        /// </summary>
+        public static readonly CVarDef<string> InfoLinksAppeal =
+            CVarDef.Create("infolinks.appeal", "", CVar.SERVER | CVar.REPLICATED);
+
         /*
          * CONFIG
          */
index d8709f0e9dc0dfac9dd5e2ead405e89c745a9249..3e3d7ef8e4b4ef7e3ac878843817c71829f16169 100644 (file)
@@ -14,6 +14,7 @@ github     = "https://github.com/space-wizards/space-station-14"
 patreon    = "https://www.patreon.com/spacestation14"
 website    = "https://spacestation14.io"
 wiki       = "https://wiki.spacestation14.io"
+appeal     = "https://appeal.ss14.io"
 
 [net]
 max_connections = 1024
index 5d2768fdc1dcadf88c1a8843cd9ef5e555b111ff..2755cf789a5190a688762a5c579e5bcb21f0af6b 100644 (file)
@@ -25,10 +25,12 @@ command-whitelistremove-not-found = Unable to find '{$username}'
 command-kicknonwhitelisted-description = Kicks all non-whitelisted players from the server.
 command-kicknonwhitelisted-help = kicknonwhitelisted
 
-ban-banned-permanent = This ban is appeal only.
+ban-banned-permanent = This ban will only be removed via appeal.
+ban-banned-permanent-appeal = This ban will only be removed via appeal. You can appeal at {$link}
 ban-expires = This ban is for {$duration} minutes and will expire at {$time} UTC.
 ban-banned-1 = You, or another user of this computer or connection, are banned from playing here.
 ban-banned-2 = The ban reason is: "{$reason}"
+ban-banned-3 = Attempts to circumvent this ban such as creating a new account will be logged.
 
 soft-player-cap-full = The server is full!
 panic-bunker-account-denied = This server is in panic bunker mode. New connections are not being accepted at this time. Try again later