From 078fb026addea718fa2ec80d8a124bb9a1ceb7f7 Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Sun, 18 Oct 2020 04:21:52 +0200 Subject: [PATCH] Add username check --- src/Impostor.Server/Data/DisconnectMessages.cs | 2 ++ src/Impostor.Server/Net/Manager/ClientManager.cs | 9 +++++++++ src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs | 4 +--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Impostor.Server/Data/DisconnectMessages.cs b/src/Impostor.Server/Data/DisconnectMessages.cs index 50dc00f..fd5b48e 100644 --- a/src/Impostor.Server/Data/DisconnectMessages.cs +++ b/src/Impostor.Server/Data/DisconnectMessages.cs @@ -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 diff --git a/src/Impostor.Server/Net/Manager/ClientManager.cs b/src/Impostor.Server/Net/Manager/ClientManager.cs index 04189af..bd2233d 100644 --- a/src/Impostor.Server/Net/Manager/ClientManager.cs +++ b/src/Impostor.Server/Net/Manager/ClientManager.cs @@ -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); diff --git a/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs b/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs index f3f9b66..e2705b4 100644 --- a/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs +++ b/src/Impostor.Shared/Innersloth/Data/DisconnectReason.cs @@ -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, @@ -31,11 +30,10 @@ // 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. // -- 2.39.5