From: miniduikboot Date: Sun, 28 Aug 2022 15:43:33 +0000 (+0200) Subject: Add unsupported option to allow future versions X-Git-Tag: v1.7.2~3 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=7a89e963ddb89bb5379ff37cfccf3fe5108b3150;p=rhonda%2Fimpostor.git Add unsupported option to allow future versions --- diff --git a/src/Impostor.Server/Config/CompatibilityConfig.cs b/src/Impostor.Server/Config/CompatibilityConfig.cs index 72098a6..d9fea81 100644 --- a/src/Impostor.Server/Config/CompatibilityConfig.cs +++ b/src/Impostor.Server/Config/CompatibilityConfig.cs @@ -4,6 +4,8 @@ namespace Impostor.Server.Config { public const string Section = "Compatibility"; + public bool AllowFutureGameVersions { get; set; } = false; + public bool AllowVersionMixing { get; set; } = false; } } diff --git a/src/Impostor.Server/Net/Manager/ClientManager.cs b/src/Impostor.Server/Net/Manager/ClientManager.cs index 21b6ca3..34001de 100644 --- a/src/Impostor.Server/Net/Manager/ClientManager.cs +++ b/src/Impostor.Server/Net/Manager/ClientManager.cs @@ -13,6 +13,7 @@ using Impostor.Server.Config; using Impostor.Server.Events.Client; using Impostor.Server.Net.Factories; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Impostor.Server.Net.Manager { @@ -32,15 +33,17 @@ namespace Impostor.Server.Net.Manager private readonly ILogger _logger; private readonly IEventManager _eventManager; private readonly ConcurrentDictionary _clients; + private readonly CompatibilityConfig _compatibilityConfig; private readonly IClientFactory _clientFactory; private int _idLast; - public ClientManager(ILogger logger, IEventManager eventManager, IClientFactory clientFactory) + public ClientManager(ILogger logger, IEventManager eventManager, IClientFactory clientFactory, IOptions compatibilityConfig) { _logger = logger; _eventManager = eventManager; _clientFactory = clientFactory; _clients = new ConcurrentDictionary(); + _compatibilityConfig = compatibilityConfig.Value; } private enum VersionCompareResult @@ -72,7 +75,12 @@ namespace Impostor.Server.Net.Manager public async ValueTask RegisterConnectionAsync(IHazelConnection connection, string name, int clientVersion, Language language, QuickChatModes chatMode, PlatformSpecificData? platformSpecificData) { var versionCompare = CompareVersion(clientVersion); - if (versionCompare != VersionCompareResult.Compatible || platformSpecificData == null) + if (versionCompare == VersionCompareResult.ServerTooOld && _compatibilityConfig.AllowFutureGameVersions && platformSpecificData != null) + { + GameVersion.ParseVersion(clientVersion, out var year, out var month, out var day, out var revision); + _logger.LogWarning("Client connected using future version: {clientVersion} ({version}). Unsupported, continue at your own risk.", clientVersion, $"{year}.{month}.{day}{(revision == 0 ? string.Empty : "." + revision)}"); + } + else if (versionCompare != VersionCompareResult.Compatible || platformSpecificData == null) { GameVersion.ParseVersion(clientVersion, out var year, out var month, out var day, out var revision); _logger.LogTrace("Client connected using unsupported version: {clientVersion} ({version})", clientVersion, $"{year}.{month}.{day}{(revision == 0 ? string.Empty : "." + revision)}");