mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-20 01:46:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff49e895ec | ||
|
|
0e9fb4b41c | ||
|
|
4f00bf1ee7 | ||
|
|
a519c0daed | ||
|
|
1f98102e5a | ||
|
|
93fdc83ce7 | ||
|
|
e29552ca28 | ||
|
|
8eee7f888f | ||
|
|
a77e4e17c2 | ||
|
|
9ebf5cd8e9 | ||
|
|
4ffca69714 | ||
|
|
dede1c5b09 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<LangVersion>11</LangVersion>
|
||||
<VersionPrefix>1.8.1</VersionPrefix>
|
||||
<VersionPrefix>1.8.3</VersionPrefix>
|
||||
<VersionSuffix>dev</VersionSuffix>
|
||||
<EnforceCodeStyleInBuild Condition="$(MSBuildProjectName)!='Hazel'">true</EnforceCodeStyleInBuild>
|
||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Impostor.Api.Config
|
||||
{
|
||||
public class TimeoutConfig
|
||||
{
|
||||
public const string Section = "Timeout";
|
||||
|
||||
public int SpawnTimeout { get; set; } = 2500;
|
||||
|
||||
public int ConnectionTimeout { get; set; } = 2500;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Impostor.Server
|
||||
{
|
||||
internal static class Constants
|
||||
{
|
||||
public const int SpawnTimeout = 2500;
|
||||
public const int ConnectionTimeout = 2500;
|
||||
}
|
||||
}
|
||||
@@ -513,36 +513,40 @@ namespace Impostor.Server.Net.Inner.Objects
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!RequestedPlayerName.Any())
|
||||
if (RequestedPlayerName.Any())
|
||||
{
|
||||
_logger.LogWarning($"Client sent {nameof(RpcCalls.SetName)} for a player that didn't request it");
|
||||
return false;
|
||||
}
|
||||
var expected = RequestedPlayerName.Dequeue();
|
||||
|
||||
var expected = RequestedPlayerName.Dequeue();
|
||||
|
||||
if (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.PlayerName == expected))
|
||||
{
|
||||
var i = 1;
|
||||
while (true)
|
||||
if (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.PlayerName == expected))
|
||||
{
|
||||
var text = expected + " " + i;
|
||||
|
||||
if (Game.Players.All(x => x.Character == null || x.Character == this || x.Character.PlayerInfo.PlayerName != text))
|
||||
var i = 1;
|
||||
while (true)
|
||||
{
|
||||
expected = text;
|
||||
break;
|
||||
}
|
||||
var text = expected + " " + i;
|
||||
|
||||
i++;
|
||||
if (Game.Players.All(x => x.Character == null || x.Character == this || x.Character.PlayerInfo.PlayerName != text))
|
||||
{
|
||||
expected = text;
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (name != expected)
|
||||
{
|
||||
_logger.LogWarning($"Client sent {nameof(RpcCalls.SetName)} with incorrect name");
|
||||
await SetNameAsync(expected);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (name != expected)
|
||||
else
|
||||
{
|
||||
_logger.LogWarning($"Client sent {nameof(RpcCalls.SetName)} with incorrect name");
|
||||
await SetNameAsync(expected);
|
||||
return false;
|
||||
if (await sender.Client.ReportCheatAsync(RpcCalls.SetName, $"Client sent {nameof(RpcCalls.SetName)} for a player that didn't request it"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ namespace Impostor.Server.Net.Manager
|
||||
GameVersion.GetVersion(2022, 11, 1), // 2022.12.8
|
||||
GameVersion.GetVersion(2022, 11, 9), // 2022.12.14
|
||||
GameVersion.GetVersion(2022, 12, 2), // 2023.2.28
|
||||
GameVersion.GetVersion(2023, 1, 11), // 2023.3.28s
|
||||
GameVersion.GetVersion(2023, 3, 13), // 2023.3.28a
|
||||
GameVersion.GetVersion(2023, 4, 21), // 2023.6.13
|
||||
};
|
||||
|
||||
private readonly ILogger<ClientManager> _logger;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Net;
|
||||
@@ -13,11 +13,13 @@ namespace Impostor.Server.Net.State
|
||||
{
|
||||
private readonly ILogger<ClientPlayer> _logger;
|
||||
private readonly Timer _spawnTimeout;
|
||||
private readonly int _spawnTimeoutTime;
|
||||
|
||||
public ClientPlayer(ILogger<ClientPlayer> logger, ClientBase client, Game game)
|
||||
public ClientPlayer(ILogger<ClientPlayer> logger, ClientBase client, Game game, int timeOutTime)
|
||||
{
|
||||
_logger = logger;
|
||||
_spawnTimeout = new Timer(RunSpawnTimeout!, null, -1, -1);
|
||||
_spawnTimeoutTime = timeOutTime;
|
||||
|
||||
Game = game;
|
||||
Client = client;
|
||||
@@ -41,7 +43,7 @@ namespace Impostor.Server.Net.State
|
||||
|
||||
public void InitializeSpawnTimeout()
|
||||
{
|
||||
_spawnTimeout.Change(Constants.SpawnTimeout, -1);
|
||||
_spawnTimeout.Change(_spawnTimeoutTime, -1);
|
||||
}
|
||||
|
||||
public void DisableSpawnTimeout()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api.Games;
|
||||
@@ -166,14 +166,6 @@ namespace Impostor.Server.Net.State
|
||||
}
|
||||
}
|
||||
|
||||
// Check if;
|
||||
// - The player is already in this game.
|
||||
// - The game is full.
|
||||
if (player?.Game != this && _players.Count >= Options.MaxPlayers)
|
||||
{
|
||||
return GameJoinResult.FromError(GameJoinError.GameFull);
|
||||
}
|
||||
|
||||
if (GameState == GameStates.Starting || GameState == GameStates.Started)
|
||||
{
|
||||
return GameJoinResult.FromError(GameJoinError.GameStarted);
|
||||
@@ -184,11 +176,19 @@ namespace Impostor.Server.Net.State
|
||||
return GameJoinResult.FromError(GameJoinError.GameDestroyed);
|
||||
}
|
||||
|
||||
// Check if;
|
||||
// - The player is already in this game.
|
||||
// - The game is full.
|
||||
if (player?.Game != this && _players.Count >= Options.MaxPlayers)
|
||||
{
|
||||
return GameJoinResult.FromError(GameJoinError.GameFull);
|
||||
}
|
||||
|
||||
var isNew = false;
|
||||
|
||||
if (player == null || player.Game != this)
|
||||
{
|
||||
var clientPlayer = new ClientPlayer(_serviceProvider.GetRequiredService<ILogger<ClientPlayer>>(), client, this);
|
||||
var clientPlayer = new ClientPlayer(_serviceProvider.GetRequiredService<ILogger<ClientPlayer>>(), client, this, _timeoutConfig.SpawnTimeout);
|
||||
|
||||
if (!_clientManager.Validate(client))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Impostor.Api;
|
||||
using Impostor.Api.Innersloth;
|
||||
@@ -76,7 +76,7 @@ namespace Impostor.Server.Net.State
|
||||
// Player can refuse to be kicked and keep the connection open, check for this.
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(Constants.ConnectionTimeout);
|
||||
await Task.Delay(_timeoutConfig.ConnectionTimeout);
|
||||
|
||||
if (player.Client.Connection.IsConnected && player.Client.Connection is HazelConnection hazel)
|
||||
{
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Impostor.Server.Net.State
|
||||
private readonly HashSet<IPAddress> _bannedIps;
|
||||
private readonly IEventManager _eventManager;
|
||||
private readonly CompatibilityConfig _compatibilityConfig;
|
||||
private readonly TimeoutConfig _timeoutConfig;
|
||||
|
||||
public Game(
|
||||
ILogger<Game> logger,
|
||||
@@ -41,7 +42,8 @@ namespace Impostor.Server.Net.State
|
||||
GameFilterOptions filterOptions,
|
||||
ClientManager clientManager,
|
||||
IEventManager eventManager,
|
||||
IOptions<CompatibilityConfig> compatibilityConfig)
|
||||
IOptions<CompatibilityConfig> compatibilityConfig,
|
||||
IOptions<TimeoutConfig> timeoutConfig)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
@@ -59,6 +61,7 @@ namespace Impostor.Server.Net.State
|
||||
_clientManager = clientManager;
|
||||
_eventManager = eventManager;
|
||||
_compatibilityConfig = compatibilityConfig.Value;
|
||||
_timeoutConfig = timeoutConfig.Value;
|
||||
Items = new ConcurrentDictionary<object, object>();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@@ -99,6 +99,7 @@ namespace Impostor.Server
|
||||
services.Configure<AntiCheatConfig>(host.Configuration.GetSection(AntiCheatConfig.Section));
|
||||
services.Configure<CompatibilityConfig>(host.Configuration.GetSection(CompatibilityConfig.Section));
|
||||
services.Configure<ServerConfig>(host.Configuration.GetSection(ServerConfig.Section));
|
||||
services.Configure<TimeoutConfig>(host.Configuration.GetSection(TimeoutConfig.Section));
|
||||
|
||||
services.AddSingleton<ClientManager>();
|
||||
services.AddSingleton<IClientManager>(p => p.GetRequiredService<ClientManager>());
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
"Enabled": true,
|
||||
"BanIpFromGame": true
|
||||
},
|
||||
"Timeout": {
|
||||
"SpawnTimeout": 2500,
|
||||
"ConnectionTimeout": 2500
|
||||
},
|
||||
"Compatibility": {
|
||||
"AllowFutureGameVersions": false,
|
||||
"AllowVersionMixing": false
|
||||
|
||||
Reference in new issue
Block a user