Removed Fill/ReadNetworkData

These functions needed to be replaced because they rely heavily on reliability.

Instead, new functions called (Write/Read)Data(Server/Client) will be added. 

Separating client and server code into completely separate functions will help ensure that proper security checks are performed.
This commit is contained in:
juanjp600
2016-08-29 20:02:46 -03:00
parent a00ceb5b9f
commit af220dbc2a
28 changed files with 29 additions and 2297 deletions
+1 -54
View File
@@ -378,60 +378,7 @@ namespace Barotrauma
body.ApplyTorque(torque);
}
public void FillNetworkData(NetBuffer message)
{
message.Write(body.Position.X);
message.Write(body.Position.Y);
message.Write(body.LinearVelocity.X);
message.Write(body.LinearVelocity.Y);
message.Write(body.Rotation);
message.Write(body.AngularVelocity);
LastSentPosition = body.Position;
}
public void ReadNetworkData(NetIncomingMessage message, float sendingTime)
{
if (sendingTime < lastNetworkUpdateTime) return;
Vector2 newTargetPos = Vector2.Zero;
Vector2 newTargetVel = Vector2.Zero;
float newTargetRotation = 0.0f, newTargetAngularVel = 0.0f;
try
{
newTargetPos = new Vector2(message.ReadFloat(), message.ReadFloat());
newTargetVel = new Vector2(message.ReadFloat(), message.ReadFloat());
newTargetRotation = message.ReadFloat();
newTargetAngularVel = message.ReadFloat();
}
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("invalid network message", e);
#endif
return;
}
if (!MathUtils.IsValid(newTargetPos) || !MathUtils.IsValid(newTargetVel) ||
!MathUtils.IsValid(newTargetRotation) || !MathUtils.IsValid(newTargetAngularVel))
return;
targetPosition = newTargetPos;
LinearVelocity = newTargetVel;
targetRotation = newTargetRotation;
AngularVelocity = newTargetAngularVel;
lastNetworkUpdateTime = sendingTime;
}
public void Remove()
{
list.Remove(this);