Clean up client manager

This commit is contained in:
AeonLucid committed 2020-10-26 00:10:06 +01:00
1 parent c6b5390844
commit e2ae918596
5 files changed
+34 -19

No files matched your search

+3 -3
View File
@@ -22,9 +22,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-rc.1.20451.14"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0-rc.1.20451.14"/>
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0-rc.1.20451.14" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0-rc.1.20451.14" />
<PackageReference Include="Nullable" Version="1.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+10
View File
@@ -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 <= '힣');
}
}
}
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Impostor.Api\Impostor.Api.csproj"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Impostor.Api\Impostor.Api.csproj" />
</ItemGroup>
</Project>
@@ -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<IClient> IClientManager.Clients => _clients.Values;
}
}
@@ -15,9 +15,9 @@ using Microsoft.Extensions.Logging;
namespace Impostor.Server.Net.Manager
{
internal class ClientManager : IClientManager
internal partial class ClientManager
{
public static HashSet<int> SupportedVersions { get; } = new HashSet<int>
private static HashSet<int> SupportedVersions { get; } = new HashSet<int>
{
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<ClientBase> Clients => _clients.Values;
IEnumerable<IClient> 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);