(8b3cd3de5) Fixed clients never removing network events the server has already received (!), don't create a new client event if there's already an identical event waiting to be sent

This commit is contained in:
Joonas Rikkonen
2019-04-11 18:23:17 +03:00
parent 90086375a4
commit 2af78d096e
3 changed files with 21 additions and 7 deletions
@@ -57,10 +57,20 @@ namespace Barotrauma.Networking
return; return;
} }
var newEvent = new ClientEntityEvent(entity, (UInt16)(ID + 1))
{
CharacterStateID = GameMain.Client.Character.LastNetworkUpdateID
};
if (extraData != null) { newEvent.SetData(extraData); }
for (int i = events.Count - 1; i >= 0; i--)
{
//we already have an identical event that's waiting to be sent
// -> no need to add a new one
if (!events[i].Sent && events[i].IsDuplicate(newEvent)) return;
}
ID++; ID++;
var newEvent = new ClientEntityEvent(entity, ID);
newEvent.CharacterStateID = GameMain.Client.Character.LastNetworkUpdateID;
if (extraData != null) newEvent.SetData(extraData);
events.Add(newEvent); events.Add(newEvent);
} }
@@ -79,7 +89,10 @@ namespace Barotrauma.Networking
startIndex--; startIndex--;
} }
for (int i = startIndex; i < events.Count; i++) //remove events the server has already received
events.RemoveRange(0, startIndex);
for (int i = 0; i < events.Count; i++)
{ {
//find the first event that hasn't been sent in roundtriptime or at all //find the first event that hasn't been sent in roundtriptime or at all
eventLastSent.TryGetValue(events[i].ID, out float lastSent); eventLastSent.TryGetValue(events[i].ID, out float lastSent);
@@ -232,6 +245,7 @@ namespace Barotrauma.Networking
if (clientEvent == null) return; if (clientEvent == null) return;
clientEvent.Write(buffer); clientEvent.Write(buffer);
clientEvent.Sent = true;
} }
protected void ReadEvent(NetIncomingMessage buffer, IServerSerializable entity, float sendingTime) protected void ReadEvent(NetIncomingMessage buffer, IServerSerializable entity, float sendingTime)
@@ -10,9 +10,7 @@ namespace Barotrauma.Networking
class ServerEntityEvent : NetEntityEvent class ServerEntityEvent : NetEntityEvent
{ {
private IServerSerializable serializable; private IServerSerializable serializable;
public bool Sent;
#if DEBUG #if DEBUG
public string StackTrace; public string StackTrace;
#endif #endif
@@ -25,6 +25,8 @@ namespace Barotrauma.Networking
//(the index of an itemcomponent for example) //(the index of an itemcomponent for example)
protected object[] Data; protected object[] Data;
public bool Sent;
protected NetEntityEvent(INetSerializable entity, UInt16 id) protected NetEntityEvent(INetSerializable entity, UInt16 id)
{ {
this.ID = id; this.ID = id;