Server doesn't attempt to resend unacked EntityEvents until Connection.AverageRoundTripTime has passed
This commit is contained in:
@@ -48,6 +48,10 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private List<Client> kickVoters;
|
private List<Client> kickVoters;
|
||||||
|
|
||||||
|
//when was a specific entity event last sent to the client
|
||||||
|
// key = event id, value = NetTime.Now when sending
|
||||||
|
public Dictionary<UInt32, float> entityEventLastSent;
|
||||||
|
|
||||||
public bool ReadyToStart;
|
public bool ReadyToStart;
|
||||||
|
|
||||||
private object[] votes;
|
private object[] votes;
|
||||||
@@ -65,6 +69,7 @@ namespace Barotrauma.Networking
|
|||||||
lastRecvChatMsgID = ChatMessage.LastID;
|
lastRecvChatMsgID = ChatMessage.LastID;
|
||||||
|
|
||||||
lastRecvEntitySpawnID = 0;
|
lastRecvEntitySpawnID = 0;
|
||||||
|
lastRecvEntityEventID = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int KickVoteCount
|
public int KickVoteCount
|
||||||
@@ -88,6 +93,8 @@ namespace Barotrauma.Networking
|
|||||||
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
||||||
|
|
||||||
jobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0, 3));
|
jobPreferences = new List<JobPrefab>(JobPrefab.List.GetRange(0, 3));
|
||||||
|
|
||||||
|
entityEventLastSent = new Dictionary<UInt32, float>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsValidName(string name)
|
public static bool IsValidName(string name)
|
||||||
|
|||||||
@@ -1026,6 +1026,7 @@ namespace Barotrauma.Networking
|
|||||||
GameMain.LightManager.LosEnabled = false;
|
GameMain.LightManager.LosEnabled = false;
|
||||||
|
|
||||||
Item.Spawner.Clear();
|
Item.Spawner.Clear();
|
||||||
|
entityEventManager.Clear();
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
messageCount.Clear();
|
messageCount.Clear();
|
||||||
|
|||||||
@@ -26,6 +26,28 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
this.Data = data;
|
this.Data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDuplicate(NetEntityEvent other)
|
||||||
|
{
|
||||||
|
if (other.Entity != this.Entity) return false;
|
||||||
|
|
||||||
|
if (Data != null && other.Data != null)
|
||||||
|
{
|
||||||
|
if (Data.Length == other.Data.Length)
|
||||||
|
{
|
||||||
|
for (int i = 0; i<Data.Length; i++)
|
||||||
|
{
|
||||||
|
if (Data[i] != other.Data[i]) return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Data == other.Data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ServerEntityEvent : NetEntityEvent
|
class ServerEntityEvent : NetEntityEvent
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Barotrauma.Networking
|
|||||||
{
|
{
|
||||||
abstract class NetEntityEventManager
|
abstract class NetEntityEventManager
|
||||||
{
|
{
|
||||||
const int MaxEventsPerWrite = 255;
|
const int MaxEventsPerWrite = 64;
|
||||||
|
|
||||||
public UInt32 LastReceivedEntityEventID
|
public UInt32 LastReceivedEntityEventID
|
||||||
{
|
{
|
||||||
@@ -58,7 +58,7 @@ namespace Barotrauma.Networking
|
|||||||
public void Read(NetIncomingMessage msg, float sendingTime)
|
public void Read(NetIncomingMessage msg, float sendingTime)
|
||||||
{
|
{
|
||||||
UInt32 firstEventID = msg.ReadUInt32();
|
UInt32 firstEventID = msg.ReadUInt32();
|
||||||
byte eventCount = msg.ReadByte();
|
int eventCount = msg.ReadByte();
|
||||||
|
|
||||||
for (int i = 0; i < eventCount; i++)
|
for (int i = 0; i < eventCount; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
var newEvent = new ServerEntityEvent(entity, ID);
|
var newEvent = new ServerEntityEvent(entity, ID);
|
||||||
if (extraData != null) newEvent.SetData(extraData);
|
if (extraData != null) newEvent.SetData(extraData);
|
||||||
|
|
||||||
events.Add(newEvent);
|
events.Add(newEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,10 +44,23 @@ namespace Barotrauma.Networking
|
|||||||
List<NetEntityEvent> eventsToSync = new List<NetEntityEvent>();
|
List<NetEntityEvent> eventsToSync = new List<NetEntityEvent>();
|
||||||
for (int i = events.Count - 1; i >= 0 && events[i].ID > client.lastRecvEntityEventID; i--)
|
for (int i = events.Count - 1; i >= 0 && events[i].ID > client.lastRecvEntityEventID; i--)
|
||||||
{
|
{
|
||||||
|
float lastSent = 0;
|
||||||
|
client.entityEventLastSent.TryGetValue(events[i].ID, out lastSent);
|
||||||
|
|
||||||
|
if (lastSent > NetTime.Now - client.Connection.AverageRoundtripTime)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
eventsToSync.Insert(0, events[i]);
|
eventsToSync.Insert(0, events[i]);
|
||||||
}
|
}
|
||||||
if (eventsToSync.Count == 0) return;
|
if (eventsToSync.Count == 0) return;
|
||||||
|
|
||||||
|
foreach (NetEntityEvent entityEvent in eventsToSync)
|
||||||
|
{
|
||||||
|
client.entityEventLastSent[entityEvent.ID] = (float)NetTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
Write(msg, eventsToSync, client);
|
Write(msg, eventsToSync, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user