From e2ae918596029042dbccc110f838ade9f21e3afd Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Mon, 26 Oct 2020 00:10:06 +0100 Subject: [PATCH] Clean up client manager --- src/Impostor.Api/Impostor.Api.csproj | 6 +++--- src/Impostor.Api/Innersloth/TextBox.cs | 10 ++++++++++ .../Impostor.Plugins.Example.csproj | 13 +++++++------ .../Net/Manager/ClientManager.Api.cs | 11 +++++++++++ src/Impostor.Server/Net/Manager/ClientManager.cs | 13 +++---------- 5 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 src/Impostor.Api/Innersloth/TextBox.cs create mode 100644 src/Impostor.Server/Net/Manager/ClientManager.Api.cs diff --git a/src/Impostor.Api/Impostor.Api.csproj b/src/Impostor.Api/Impostor.Api.csproj index d0a90e0..5b31db7 100644 --- a/src/Impostor.Api/Impostor.Api.csproj +++ b/src/Impostor.Api/Impostor.Api.csproj @@ -22,9 +22,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Impostor.Api/Innersloth/TextBox.cs b/src/Impostor.Api/Innersloth/TextBox.cs new file mode 100644 index 0000000..9533d83 --- /dev/null +++ b/src/Impostor.Api/Innersloth/TextBox.cs @@ -0,0 +1,10 @@ +namespace Impostor.Api.Innersloth +{ + public static class TextBox + { + public static bool IsCharAllowed(char i) + { + return i == ' ' || (i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || (i >= '0' && i <= '9') || (i >= 'À' && i <= 'ÿ') || (i >= 'Ѐ' && i <= 'џ') || (i >= 'ㄱ' && i <= 'ㆎ') || (i >= '가' && i <= '힣'); + } + } +} \ No newline at end of file diff --git a/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj b/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj index 582a9e8..0cd6cd5 100644 --- a/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj +++ b/src/Impostor.Plugins.Example/Impostor.Plugins.Example.csproj @@ -1,10 +1,11 @@  - - netstandard2.1 - + + netstandard2.1 + + + + + - - - diff --git a/src/Impostor.Server/Net/Manager/ClientManager.Api.cs b/src/Impostor.Server/Net/Manager/ClientManager.Api.cs new file mode 100644 index 0000000..6cbe5bf --- /dev/null +++ b/src/Impostor.Server/Net/Manager/ClientManager.Api.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Impostor.Api.Net; +using Impostor.Api.Net.Manager; + +namespace Impostor.Server.Net.Manager +{ + internal partial class ClientManager : IClientManager + { + IEnumerable IClientManager.Clients => _clients.Values; + } +} \ 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 5fbe823..96b2f54 100644 --- a/src/Impostor.Server/Net/Manager/ClientManager.cs +++ b/src/Impostor.Server/Net/Manager/ClientManager.cs @@ -15,9 +15,9 @@ using Microsoft.Extensions.Logging; namespace Impostor.Server.Net.Manager { - internal class ClientManager : IClientManager + internal partial class ClientManager { - public static HashSet SupportedVersions { get; } = new HashSet + private static HashSet SupportedVersions { get; } = new HashSet { GameVersion.GetVersion(2020, 09, 07), // 2020.09.07 - 2020.09.22 GameVersion.GetVersion(2020, 10, 08), // 2020.10.08 @@ -37,8 +37,6 @@ namespace Impostor.Server.Net.Manager public IEnumerable Clients => _clients.Values; - IEnumerable IClientManager.Clients => _clients.Values; - public int NextId() { var clientId = Interlocked.Increment(ref _idLast); @@ -55,11 +53,6 @@ namespace Impostor.Server.Net.Manager return clientId; } - private static bool IsCharAllowed(char i) - { - return i == ' ' || (i >= 'A' && i <= 'Z') || (i >= 'a' && i <= 'z') || (i >= '0' && i <= '9') || (i >= 'À' && i <= 'ÿ') || (i >= 'Ѐ' && i <= 'џ') || (i >= 'ㄱ' && i <= 'ㆎ') || (i >= '가' && i <= '힣'); - } - public async ValueTask RegisterConnectionAsync(IHazelConnection connection, string name, int clientVersion) { if (!SupportedVersions.Contains(clientVersion)) @@ -78,7 +71,7 @@ namespace Impostor.Server.Net.Manager return; } - if (string.IsNullOrWhiteSpace(name) || !name.All(IsCharAllowed)) + if (string.IsNullOrWhiteSpace(name) || !name.All(TextBox.IsCharAllowed)) { using var packet = MessageWriter.Get(MessageType.Reliable); Message01JoinGameS2C.SerializeError(packet, false, DisconnectReason.Custom, DisconnectMessages.UsernameIllegalCharacters); -- 2.39.5