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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user