From 84121674b11514218f7e008ff7ae9f8f931218b8 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 30 Mar 2019 21:44:37 +0200 Subject: [PATCH] (050a72bf3) Server resets remote character inputs if no inputs have been received in the past 0.5 seconds. Previously the server would assume the inputs hadn't changed from the last known ones, which works well when there are brief networking hiccups that cause the server to run out of inputs for a few frames, but if it takes longer, we don't want to keep the character firing a welding tool or whatever else they were doing until the kill disconnect timer kicks in. --- .../Source/Characters/CharacterNetworking.cs | 1 - .../Source/Characters/CharacterNetworking.cs | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs index c53b261fa..5753c1c97 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs @@ -3,7 +3,6 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using System; using System.Linq; -using System.Collections.Generic; namespace Barotrauma { diff --git a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs index 95f9d1e53..d9831f872 100644 --- a/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaServer/Source/Characters/CharacterNetworking.cs @@ -15,6 +15,8 @@ namespace Barotrauma private bool networkUpdateSent; + private double LastInputTime; + public float GetPositionUpdateInterval(Client recipient) { if (!Enabled) { return 1000.0f; } @@ -61,6 +63,15 @@ namespace Barotrauma else if (memInput.Count == 0) { AnimController.Frozen = true; + if (Timing.TotalTime > LastInputTime + 0.5) + { + //no inputs have been received in 0.5 seconds, reset input + //(if there's a temporary network hiccup that prevents us from receiving inputs, we assume the inputs haven't changed, + //but if it takes too long, for example due to a client crashing/disconnecting, we don't want to keep the character + //firing a welding tool or whatever else they were doing until the kill disconnect timer kicks in) + prevDequeuedInput = dequeuedInput = + dequeuedInput.HasFlag(InputNetFlags.FacingLeft) ? InputNetFlags.FacingLeft : InputNetFlags.None; + } } else { @@ -190,6 +201,7 @@ namespace Barotrauma networkUpdateID = (ushort)(networkUpdateID - i) }; memInput.Insert(i, newMem); + LastInputTime = Timing.TotalTime; } }