From 8aaf75e38120059c97e18046d4cfe4d533678e14 Mon Sep 17 00:00:00 2001 From: miniduikboot Date: Sun, 28 Aug 2022 17:32:29 +0200 Subject: [PATCH] Make version mixing configurable --- src/Impostor.Server/Config/CompatibilityConfig.cs | 9 +++++++++ src/Impostor.Server/Net/Manager/GameManager.cs | 6 ++++-- src/Impostor.Server/Net/State/Game.Incoming.cs | 3 ++- src/Impostor.Server/Net/State/Game.cs | 7 ++++++- src/Impostor.Server/Program.cs | 1 + 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/Impostor.Server/Config/CompatibilityConfig.cs diff --git a/src/Impostor.Server/Config/CompatibilityConfig.cs b/src/Impostor.Server/Config/CompatibilityConfig.cs new file mode 100644 index 0000000..72098a6 --- /dev/null +++ b/src/Impostor.Server/Config/CompatibilityConfig.cs @@ -0,0 +1,9 @@ +namespace Impostor.Server.Config +{ + public class CompatibilityConfig + { + public const string Section = "Compatibility"; + + public bool AllowVersionMixing { get; set; } = false; + } +} diff --git a/src/Impostor.Server/Net/Manager/GameManager.cs b/src/Impostor.Server/Net/Manager/GameManager.cs index aa22873..f567f61 100644 --- a/src/Impostor.Server/Net/Manager/GameManager.cs +++ b/src/Impostor.Server/Net/Manager/GameManager.cs @@ -26,11 +26,12 @@ namespace Impostor.Server.Net.Manager private readonly INodeLocator _nodeLocator; private readonly IPEndPoint _publicIp; private readonly ConcurrentDictionary _games; + private readonly CompatibilityConfig _compatibilityConfig; private readonly IServiceProvider _serviceProvider; private readonly IEventManager _eventManager; private readonly IGameCodeFactory _gameCodeFactory; - public GameManager(ILogger logger, IOptions config, INodeLocator nodeLocator, IServiceProvider serviceProvider, IEventManager eventManager, IGameCodeFactory gameCodeFactory) + public GameManager(ILogger logger, IOptions config, INodeLocator nodeLocator, IServiceProvider serviceProvider, IEventManager eventManager, IGameCodeFactory gameCodeFactory, IOptions compatibilityConfig) { _logger = logger; _nodeLocator = nodeLocator; @@ -39,6 +40,7 @@ namespace Impostor.Server.Net.Manager _gameCodeFactory = gameCodeFactory; _publicIp = new IPEndPoint(IPAddress.Parse(config.Value.ResolvePublicIp()), config.Value.PublicPort); _games = new ConcurrentDictionary(); + _compatibilityConfig = compatibilityConfig.Value; } IEnumerable IGameManager.Games => _games.Select(kv => kv.Value); @@ -60,7 +62,7 @@ namespace Impostor.Server.Net.Manager x.Value.IsPublic && x.Value.GameState == GameStates.NotStarted && x.Value.PlayerCount < x.Value.Options.MaxPlayers && - x.Value.Host?.Client.GameVersion == gameVersion)) + (_compatibilityConfig.AllowVersionMixing == true || x.Value.Host?.Client.GameVersion == gameVersion))) { // Check for options. if (!map.HasFlag((MapFlags)(1 << (byte)game.Options.Map))) diff --git a/src/Impostor.Server/Net/State/Game.Incoming.cs b/src/Impostor.Server/Net/State/Game.Incoming.cs index af841af..176740d 100644 --- a/src/Impostor.Server/Net/State/Game.Incoming.cs +++ b/src/Impostor.Server/Net/State/Game.Incoming.cs @@ -154,7 +154,8 @@ namespace Impostor.Server.Net.State var player = client.Player; // Check if the player is running the same version as the host - if (this.Host != null && client.GameVersion != this.Host.Client.GameVersion) + if (_compatibilityConfig.AllowVersionMixing == false && + this.Host != null && client.GameVersion != this.Host.Client.GameVersion) { if (client.GameVersion < this.Host.Client.GameVersion) { diff --git a/src/Impostor.Server/Net/State/Game.cs b/src/Impostor.Server/Net/State/Game.cs index ab6d1e9..5da19d4 100644 --- a/src/Impostor.Server/Net/State/Game.cs +++ b/src/Impostor.Server/Net/State/Game.cs @@ -12,9 +12,11 @@ using Impostor.Api.Innersloth; using Impostor.Api.Net; using Impostor.Api.Net.Messages; using Impostor.Api.Net.Messages.S2C; +using Impostor.Server.Config; using Impostor.Server.Events; using Impostor.Server.Net.Manager; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Impostor.Server.Net.State { @@ -27,6 +29,7 @@ namespace Impostor.Server.Net.State private readonly ConcurrentDictionary _players; private readonly HashSet _bannedIps; private readonly IEventManager _eventManager; + private readonly CompatibilityConfig _compatibilityConfig; public Game( ILogger logger, @@ -36,7 +39,8 @@ namespace Impostor.Server.Net.State GameCode code, GameOptionsData options, ClientManager clientManager, - IEventManager eventManager) + IEventManager eventManager, + IOptions compatibilityConfig) { _logger = logger; _serviceProvider = serviceProvider; @@ -52,6 +56,7 @@ namespace Impostor.Server.Net.State Options = options; _clientManager = clientManager; _eventManager = eventManager; + _compatibilityConfig = compatibilityConfig.Value; Items = new ConcurrentDictionary(); } diff --git a/src/Impostor.Server/Program.cs b/src/Impostor.Server/Program.cs index 219620b..1c575dd 100644 --- a/src/Impostor.Server/Program.cs +++ b/src/Impostor.Server/Program.cs @@ -103,6 +103,7 @@ namespace Impostor.Server services.Configure(host.Configuration.GetSection(DebugConfig.Section)); services.Configure(host.Configuration.GetSection(AntiCheatConfig.Section)); + services.Configure(host.Configuration.GetSection(CompatibilityConfig.Section)); services.Configure(host.Configuration.GetSection(ServerConfig.Section)); services.Configure(host.Configuration.GetSection(ServerRedirectorConfig.Section)); -- 2.39.5