]> git.deb.at Git - rhonda/impostor.git/commitdiff
Make version mixing configurable
authorminiduikboot <mini@duikbo.at>
Sun, 28 Aug 2022 15:32:29 +0000 (17:32 +0200)
committerminiduikboot <mini@duikbo.at>
Mon, 29 Aug 2022 18:57:16 +0000 (20:57 +0200)
src/Impostor.Server/Config/CompatibilityConfig.cs [new file with mode: 0644]
src/Impostor.Server/Net/Manager/GameManager.cs
src/Impostor.Server/Net/State/Game.Incoming.cs
src/Impostor.Server/Net/State/Game.cs
src/Impostor.Server/Program.cs

diff --git a/src/Impostor.Server/Config/CompatibilityConfig.cs b/src/Impostor.Server/Config/CompatibilityConfig.cs
new file mode 100644 (file)
index 0000000..72098a6
--- /dev/null
@@ -0,0 +1,9 @@
+namespace Impostor.Server.Config
+{
+    public class CompatibilityConfig
+    {
+        public const string Section = "Compatibility";
+
+        public bool AllowVersionMixing { get; set; } = false;
+    }
+}
index aa22873ea67e4f29448f2eaaebeed9c6cd2a528d..f567f615a6e421f14dbf2edff4d10c279707087d 100644 (file)
@@ -26,11 +26,12 @@ namespace Impostor.Server.Net.Manager
         private readonly INodeLocator _nodeLocator;
         private readonly IPEndPoint _publicIp;
         private readonly ConcurrentDictionary<int, Game> _games;
+        private readonly CompatibilityConfig _compatibilityConfig;
         private readonly IServiceProvider _serviceProvider;
         private readonly IEventManager _eventManager;
         private readonly IGameCodeFactory _gameCodeFactory;
 
-        public GameManager(ILogger<GameManager> logger, IOptions<ServerConfig> config, INodeLocator nodeLocator, IServiceProvider serviceProvider, IEventManager eventManager, IGameCodeFactory gameCodeFactory)
+        public GameManager(ILogger<GameManager> logger, IOptions<ServerConfig> config, INodeLocator nodeLocator, IServiceProvider serviceProvider, IEventManager eventManager, IGameCodeFactory gameCodeFactory, IOptions<CompatibilityConfig> 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<int, Game>();
+            _compatibilityConfig = compatibilityConfig.Value;
         }
 
         IEnumerable<IGame> 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)))
index af841af0f947b6054fe1684833e67469c6f1b9d1..176740df91ed21719eaa1cca3d2569bef499132c 100644 (file)
@@ -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)
                 {
index ab6d1e99189af46bf430838077100e1089fb02f8..5da19d4a251ddd3e47faa03f08a016456d21514d 100644 (file)
@@ -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<int, ClientPlayer> _players;
         private readonly HashSet<IPAddress> _bannedIps;
         private readonly IEventManager _eventManager;
+        private readonly CompatibilityConfig _compatibilityConfig;
 
         public Game(
             ILogger<Game> logger,
@@ -36,7 +39,8 @@ namespace Impostor.Server.Net.State
             GameCode code,
             GameOptionsData options,
             ClientManager clientManager,
-            IEventManager eventManager)
+            IEventManager eventManager,
+            IOptions<CompatibilityConfig> 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<object, object>();
         }
 
index 219620b01faeb69f3d0445c8715b134d707ae562..1c575dd7cae7bccde7e2c63e92cf8da7876cc741 100644 (file)
@@ -103,6 +103,7 @@ namespace Impostor.Server
 
                     services.Configure<DebugConfig>(host.Configuration.GetSection(DebugConfig.Section));
                     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<ServerRedirectorConfig>(host.Configuration.GetSection(ServerRedirectorConfig.Section));