]> git.deb.at Git - rhonda/impostor.git/commitdiff
Fix cheating disconnect message
authorjs6pak <me@6pak.dev>
Thu, 22 Aug 2024 21:37:51 +0000 (23:37 +0200)
committerjs6pak <me@6pak.dev>
Sat, 24 Aug 2024 14:51:51 +0000 (16:51 +0200)
DisconnectReason.Hacking has been broken in base game for a long time so replace it with a custom message.
Also add a random support code for easier debugging in case of false positives.

src/Impostor.Server/Net/Client.cs

index 8579037306b874df9af6cbdb13b90bbd9bd01cf8..dfbc990656a844a95123f79ac55536c79267a6db 100644 (file)
@@ -82,14 +82,22 @@ namespace Impostor.Server.Net
                 return false;
             }
 
-            _logger.LogWarning("Client {Name} ({Id}) was caught cheating: [{Context}-{Category}] {Message}", Name, Id, context.Name, category, message);
+            var supportCode = Random.Shared.Next(0, 999_999).ToString("000-000");
+
+            _logger.LogWarning("Client {Name} ({Id}) was caught cheating: [{SupportCode}] [{Context}-{Category}] {Message}", Name, Id, supportCode, context.Name, category, message);
 
             if (_antiCheatConfig.BanIpFromGame)
             {
                 Player?.Game.BanIp(Connection.EndPoint.Address);
             }
 
-            await DisconnectAsync(DisconnectReason.Hacking, context.Name + ": " + message);
+            var disconnectMessage =
+                $"""
+                 You have been caught cheating and were {(_antiCheatConfig.BanIpFromGame ? "banned" : "kicked")} from the lobby.
+                 For questions, contact your server admin and share the following code: {supportCode}.
+                 """;
+
+            await DisconnectAsync(DisconnectReason.Custom, disconnectMessage);
 
             return true;
         }