From: AeonLucid Date: Sun, 25 Oct 2020 22:13:09 +0000 (+0100) Subject: Make ban for cheating configurable X-Git-Tag: v1.2.2~74^2~6 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=93394e7e770368f3d158ee039bdd02e18cf0cda3;p=rhonda%2Fimpostor.git Make ban for cheating configurable --- diff --git a/docs/Server-configuration.md b/docs/Server-configuration.md index 12c5a5a..1205d06 100644 --- a/docs/Server-configuration.md +++ b/docs/Server-configuration.md @@ -17,6 +17,7 @@ Server:PublicIp=127.0.0.1 Server:PublicPort=22023 Server:ListenIp=0.0.0.0 Server:listenPort=22023 +AntiCheat:BanIpFromGame=true ServerRedirector:Enabled=false ServerRedirector:Master=true ServerRedirector:Locator:Redis=127.0.0.1.6379 @@ -36,6 +37,7 @@ IMPOSTOR_Server__PublicIp=127.0.0.1 IMPOSTOR_Server__PublicPort=22023 IMPOSTOR_Server__ListenIp=0.0.0.0 IMPOSTOR_Server__listenPort=22023 +IMPOSTOR_AntiCheat__BanIpFromGame=true IMPOSTOR_ServerRedirector__Enabled=false IMPOSTOR_ServerRedirector__Master=true IMPOSTOR_ServerRedirector__Locator__Redis=127.0.0.1.6379 diff --git a/src/Impostor.Server/Config/AntiCheatConfig.cs b/src/Impostor.Server/Config/AntiCheatConfig.cs new file mode 100644 index 0000000..f4807e7 --- /dev/null +++ b/src/Impostor.Server/Config/AntiCheatConfig.cs @@ -0,0 +1,9 @@ +namespace Impostor.Server.Config +{ + public class AntiCheatConfig + { + public const string Section = "AntiCheat"; + + public bool BanIpFromGame { get; set; } = true; + } +} \ No newline at end of file diff --git a/src/Impostor.Server/Config/DebugConfig.cs b/src/Impostor.Server/Config/DebugConfig.cs index 1758366..630d1b4 100644 --- a/src/Impostor.Server/Config/DebugConfig.cs +++ b/src/Impostor.Server/Config/DebugConfig.cs @@ -5,6 +5,7 @@ public const string Section = "Debug"; public bool GameRecorderEnabled { get; set; } + public string GameRecorderPath { get; set; } } } \ No newline at end of file diff --git a/src/Impostor.Server/Net/Client.cs b/src/Impostor.Server/Net/Client.cs index b6fe4f0..189ae4d 100644 --- a/src/Impostor.Server/Net/Client.cs +++ b/src/Impostor.Server/Net/Client.cs @@ -9,21 +9,25 @@ using Impostor.Api.Net.Messages.C2S; using Impostor.Api.Net.Messages.S2C; using Impostor.Hazel; using Impostor.Server.Config; +using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Manager; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Impostor.Server.Net { internal class Client : ClientBase { private readonly ILogger _logger; + private readonly AntiCheatConfig _antiCheatConfig; private readonly ClientManager _clientManager; private readonly GameManager _gameManager; - public Client(ILogger logger, ClientManager clientManager, GameManager gameManager, string name, IHazelConnection connection) + public Client(ILogger logger, IOptions antiCheatOptions, ClientManager clientManager, GameManager gameManager, string name, IHazelConnection connection) : base(name, connection) { _logger = logger; + _antiCheatConfig = antiCheatOptions.Value; _clientManager = clientManager; _gameManager = gameManager; } @@ -172,7 +176,10 @@ namespace Impostor.Server.Net } catch (ImpostorCheatException e) { - Player.Game.BanIp(Connection.EndPoint.Address); + if (_antiCheatConfig.BanIpFromGame) + { + Player.Game.BanIp(Connection.EndPoint.Address); + } await DisconnectAsync(DisconnectReason.Hacking, e.Message); } diff --git a/src/Impostor.Server/Program.cs b/src/Impostor.Server/Program.cs index 54c4969..f699e73 100644 --- a/src/Impostor.Server/Program.cs +++ b/src/Impostor.Server/Program.cs @@ -92,6 +92,7 @@ namespace Impostor.Server .Get() ?? new ServerRedirectorConfig(); services.Configure(host.Configuration.GetSection(DebugConfig.Section)); + services.Configure(host.Configuration.GetSection(AntiCheatConfig.Section)); services.Configure(host.Configuration.GetSection(ServerConfig.Section)); services.Configure(host.Configuration.GetSection(ServerRedirectorConfig.Section)); diff --git a/src/Impostor.Server/Recorder/ClientRecorder.cs b/src/Impostor.Server/Recorder/ClientRecorder.cs index 90d644f..94b320e 100644 --- a/src/Impostor.Server/Recorder/ClientRecorder.cs +++ b/src/Impostor.Server/Recorder/ClientRecorder.cs @@ -1,9 +1,11 @@ using System.Threading.Tasks; using Impostor.Api.Net.Messages; +using Impostor.Server.Config; using Impostor.Server.Net; using Impostor.Server.Net.Hazel; using Impostor.Server.Net.Manager; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; namespace Impostor.Server.Recorder { @@ -14,8 +16,8 @@ namespace Impostor.Server.Recorder private bool _createdGame; private bool _recordAfter; - public ClientRecorder(ILogger logger, ClientManager clientManager, GameManager gameManager, string name, HazelConnection connection, PacketRecorder recorder) - : base(logger, clientManager, gameManager, name, connection) + public ClientRecorder(ILogger logger, IOptions antiCheatOptions, ClientManager clientManager, GameManager gameManager, string name, HazelConnection connection, PacketRecorder recorder) + : base(logger, antiCheatOptions, clientManager, gameManager, name, connection) { _recorder = recorder; _isFirst = true; diff --git a/src/Impostor.Server/config-full.json b/src/Impostor.Server/config-full.json index e509ca0..dfee1bc 100644 --- a/src/Impostor.Server/config-full.json +++ b/src/Impostor.Server/config-full.json @@ -5,6 +5,9 @@ "ListenIp": "0.0.0.0", "ListenPort": 22023 }, + "AntiCheat": { + "BanIpFromGame": true + }, "ServerRedirector": { "Enabled": false, "Master": true, diff --git a/src/Impostor.Server/config.json b/src/Impostor.Server/config.json index 4745696..d477c74 100644 --- a/src/Impostor.Server/config.json +++ b/src/Impostor.Server/config.json @@ -5,8 +5,7 @@ "ListenIp": "0.0.0.0", "ListenPort": 22023 }, - "Debug": { - "GameRecorderEnabled": false, - "GameRecorderPath": "" + "AntiCheat": { + "BanIpFromGame": true } } \ No newline at end of file