Fixed clients being unable to toggle doors when they've predicted the state of the door and waiting for a confirmation from the server, reading a position update for an item with no body doesn't throw an exception

This commit is contained in:
Regalis
2017-05-10 21:19:10 +03:00
parent ad90cf804d
commit 1d3da3e70b
2 changed files with 22 additions and 38 deletions

View File

@@ -488,26 +488,27 @@ namespace Barotrauma.Items.Components
{
if (isStuck) return;
bool wasOpen = isOpen;
bool wasOpen = predictedState == null ? isOpen : predictedState.Value;
if (connection.Name == "toggle")
{
SetState(!isOpen, false, true);
SetState(!wasOpen, false, true);
}
else if (connection.Name == "set_state")
{
SetState(signal != "0", false, true);
}
if (sender != null && wasOpen != isOpen)
bool newState = predictedState == null ? isOpen : predictedState.Value;
if (sender != null && wasOpen != newState)
{
GameServer.Log(sender.Name + (isOpen ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction);
GameServer.Log(sender.Name + (newState ? " opened " : " closed ") + item.Name, ServerLog.MessageType.ItemInteraction);
}
}
public void SetState(bool open, bool isNetworkMessage, bool sendNetworkMessage = false)
{
if (isStuck || isOpen == open) return;
if (isStuck || (predictedState == null && isOpen == open) || (predictedState != null && isOpen == predictedState.Value)) return;
if (GameMain.Client != null && !isNetworkMessage)
{

View File

@@ -2133,21 +2133,27 @@ namespace Barotrauma
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
{
Vector2 newPosition = new Vector2(
msg.ReadFloat(),
msg.ReadFloat());
float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
body.FarseerBody.Awake = msg.ReadBoolean();
Vector2 newPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat());
float newRotation = msg.ReadRangedSingle(0.0f, MathHelper.TwoPi, 7);
bool awake = msg.ReadBoolean();
Vector2 newVelocity = Vector2.Zero;
if (body.FarseerBody.Awake)
if (awake)
{
newVelocity = new Vector2(
msg.ReadRangedSingle(-MaxVel, MaxVel, 12),
msg.ReadRangedSingle(-MaxVel, MaxVel, 12));
}
if (body == null)
{
DebugConsole.ThrowError("Received a position update for an item with no physics body ("+Name+")");
return;
}
body.FarseerBody.Awake = awake;
if (body.FarseerBody.Awake)
{
if ((newVelocity - body.LinearVelocity).Length() > 8.0f) body.LinearVelocity = newVelocity;
}
else
@@ -2159,29 +2165,6 @@ namespace Barotrauma
{
body.SetTransform(newPosition,newRotation);
}
//DebugConsole.NewMessage("Received item pos, t: "+sendingTime+ " ("+Name+")", Color.LightGreen);
/*//already interpolating with more up-to-date data -> ignore
if (MemPos.Count > 1 && MemPos[0].Timestamp > sendingTime)
{
return;
}
int index = 0;
while (index < MemPos.Count && sendingTime > MemPos[index].Timestamp)
{
index++;
}
//position with the same timestamp already in the buffer (duplicate packet?)
// -> no need to add again
if (index < MemPos.Count && sendingTime == MemPos[index].Timestamp)
{
return;
}
MemPos.Insert(index, new PosInfo(newTargetPosition, Direction.None, sendingTime));*/
}
public static void Load(XElement element, Submarine submarine)