]> git.deb.at Git - rhonda/impostor.git/commitdiff
Add username check
authorAeonLucid <aeonlucid@gmail.com>
Sun, 18 Oct 2020 02:21:52 +0000 (04:21 +0200)
committerAeonLucid <aeonlucid@gmail.com>
Sun, 18 Oct 2020 02:21:52 +0000 (04:21 +0200)
src/Impostor.Server/Data/DisconnectMessages.cs
src/Impostor.Server/Net/Manager/ClientManager.cs
src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs

index 50dc00f5a47738bb86c1b31f3d71924e3c4a2d7d..fd5b48e08c1226fea46b97cc64a068445271533f 100644 (file)
@@ -11,5 +11,7 @@
 
         public const string NotImplemented = "Game listing has not been implemented in Impostor yet for servers " +
                                              "running in server redirection mode.";
+
+        public const string UsernameLength = "Your username is too long, please make it shorter.";
     }
 }
\ No newline at end of file
index 04189afdf48350d5da99255785e8824f63a643b8..bd2233d282199332e8fd282da1cc657006a9fe81 100644 (file)
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
+using Impostor.Server.Data;
 using Impostor.Server.Net.Factories;
 using Impostor.Server.Net.Messages;
 using Impostor.Shared.Innersloth;
@@ -48,6 +49,14 @@ namespace Impostor.Server.Net.Manager
 
         public async ValueTask RegisterConnectionAsync(IConnection connection, string name, int clientVersion)
         {
+            if (name.Length > 10)
+            {
+                using var packet = connection.CreateMessage(MessageType.Reliable);
+                Message01JoinGame.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.UsernameLength);
+                await packet.SendAsync();
+                return;
+            }
+
             if (!SupportedVersions.Contains(clientVersion))
             {
                 using var packet = connection.CreateMessage(MessageType.Reliable);
index f3f9b665f81c4c1a13736333472bc9e16e06e996..e2705b44eb650e84711b987c429f234578053bdb 100644 (file)
@@ -3,7 +3,6 @@
     public enum DisconnectReason
     {
         ExitGame = 0,
-        Destroy = 16,
         // The game you tried to join is full.
         // Check with the host to see if you can join next round.
         GameFull = 1,
         // You can rejoin if the room hasn't started
         // You were kicked
         Kicked = 7,
-        // Server refused username: %USERNAME%
-        InvalidName = 9,
         // You were banned for hacking.
         // Please stop.
         Hacking = 10,
+        Destroy = 16,
         // You disconnected from the host.
         // If this happens often, check your WiFi strength.
         //