Fixed "trying to read past the buffer size" errors caused by item updates sent by clients, midround syncing timeout period is calculated based on the number of events the client needs to receive

This commit is contained in:
Regalis
2017-03-11 12:49:08 +02:00
parent a1342fdc45
commit c851770386
3 changed files with 15 additions and 6 deletions
+2 -1
View File
@@ -1812,12 +1812,13 @@ namespace Barotrauma
break; break;
case NetEntityEvent.Type.ApplyStatusEffect: case NetEntityEvent.Type.ApplyStatusEffect:
//no further data needed, the server applies the effect //no further data needed, the server applies the effect
//on the character of the client who sent the message //on the character of the client who sent the message
break; break;
case NetEntityEvent.Type.ChangeProperty: case NetEntityEvent.Type.ChangeProperty:
WritePropertyChange(msg, extraData); WritePropertyChange(msg, extraData);
break; break;
} }
msg.WritePadBits();
} }
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c) public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
@@ -61,6 +61,11 @@ namespace Barotrauma.Networking
get { return entityEventManager; } get { return entityEventManager; }
} }
public TimeSpan UpdateInterval
{
get { return updateInterval; }
}
public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10) public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10)
{ {
name = name.Replace(":", ""); name = name.Replace(":", "");
@@ -2,8 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Barotrauma.Networking namespace Barotrauma.Networking
{ {
@@ -252,9 +250,12 @@ namespace Barotrauma.Networking
{ {
if (uniqueEvents.Count > 0) if (uniqueEvents.Count > 0)
{ {
double midRoundSyncTimeOut = uniqueEvents.Count / MaxEventsPerWrite * server.UpdateInterval.TotalSeconds;
midRoundSyncTimeOut = Math.Max(5.0f, midRoundSyncTimeOut * 1.5f);
client.UnreceivedEntityEventCount = (UInt16)uniqueEvents.Count; client.UnreceivedEntityEventCount = (UInt16)uniqueEvents.Count;
client.NeedsMidRoundSync = true; client.NeedsMidRoundSync = true;
client.MidRoundSyncTimeOut = Timing.TotalTime + 10.0; client.MidRoundSyncTimeOut = Timing.TotalTime + midRoundSyncTimeOut;
} }
else else
{ {
@@ -293,11 +294,13 @@ namespace Barotrauma.Networking
msg.Position += msgLength * 8; msg.Position += msgLength * 8;
} }
else else
{ {
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Green);
UInt16 characterStateID = msg.ReadUInt16(); UInt16 characterStateID = msg.ReadUInt16();
NetBuffer buffer = new NetBuffer(); NetBuffer buffer = new NetBuffer();
buffer.Write(msg.ReadBytes(msgLength-2)); buffer.Write(msg.ReadBytes(msgLength - 2));
BufferEvent(new BufferedEvent(sender, sender.Character, characterStateID, entity, buffer)); BufferEvent(new BufferedEvent(sender, sender.Character, characterStateID, entity, buffer));
sender.lastSentEntityEventID++; sender.lastSentEntityEventID++;