From 42903a1b533ce99effd3ac2eb731f7240685a73b Mon Sep 17 00:00:00 2001 From: EntenKoeniq <81123713+EntenKoeniq@users.noreply.github.com> Date: Sat, 1 Jan 2022 15:58:14 +0100 Subject: [PATCH] MaxLatency added --- Server/Client.cs | 15 ++++++++++++++- Server/CoopServer.csproj | 2 +- Server/Settings.cs | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Server/Client.cs b/Server/Client.cs index ae79fe2..5781c25 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -8,7 +8,20 @@ namespace CoopServer public class Client { public long NetHandle = 0; - public float Latency = 0.0f; + private float CurrentLatency = 0f; + public float Latency + { + get => CurrentLatency; + internal set + { + CurrentLatency = value; + + if ((value * 1000f) > Server.MainSettings.MaxLatency) + { + Server.MainNetServer.Connections.Find(x => x.RemoteUniqueIdentifier == NetHandle)?.Disconnect($"Too high latency [{value * 1000f}/{(float)Server.MainSettings.MaxLatency}]"); + } + } + } public PlayerData Player; private readonly Dictionary CustomData = new(); private long CallbacksCount = 0; diff --git a/Server/CoopServer.csproj b/Server/CoopServer.csproj index 4f7738b..18e9f4e 100644 --- a/Server/CoopServer.csproj +++ b/Server/CoopServer.csproj @@ -3,7 +3,7 @@ Exe net6.0 - 1.42.0.0001 + 1.43.0.0001 1.0.0.0 https://github.com/GTACOOP-R/GTACoop-R diff --git a/Server/Settings.cs b/Server/Settings.cs index c513918..74418ba 100644 --- a/Server/Settings.cs +++ b/Server/Settings.cs @@ -4,6 +4,7 @@ { public int Port { get; set; } = 4499; public int MaxPlayers { get; set; } = 16; + public int MaxLatency { get; set; } = 300; public string Name { get; set; } = "GTACoop:R server"; public string WelcomeMessage { get; set; } = "Welcome on this server :)"; public string Resource { get; set; } = "";