Server reads CHARACTER_INPUT messages even if the client isn't allowed to move (but ignores the inputs), otherwise it would fail to read the rest of the packet

This commit is contained in:
Regalis
2017-01-06 18:19:51 +02:00
parent 2a7ef5dd84
commit 65d64af041
4 changed files with 26 additions and 19 deletions
@@ -59,7 +59,7 @@ namespace Barotrauma
ColliderIndex = Crouching ? 1 : 0; ColliderIndex = Crouching ? 1 : 0;
if (!Crouching && ColliderIndex == 1) Crouching = true; if (!Crouching && ColliderIndex == 1) Crouching = true;
if (!character.AllowMovement) if (!character.AllowInput)
{ {
levitatingCollider = false; levitatingCollider = false;
Collider.FarseerBody.FixedRotation = false; Collider.FarseerBody.FixedRotation = false;
@@ -925,7 +925,7 @@ namespace Barotrauma
target.AnimController.IgnorePlatforms = IgnorePlatforms; target.AnimController.IgnorePlatforms = IgnorePlatforms;
if (!target.AllowMovement) if (!target.AllowInput)
{ {
target.AnimController.TargetMovement = TargetMovement; target.AnimController.TargetMovement = TargetMovement;
} }
@@ -1223,7 +1223,7 @@ namespace Barotrauma
} }
if (character != GameMain.NetworkMember.Character || !character.AllowMovement) if (character != GameMain.NetworkMember.Character || !character.AllowInput)
{ {
//use simple interpolation for other players' characters and characters that can't move //use simple interpolation for other players' characters and characters that can't move
if (character.MemPos.Count > 0) if (character.MemPos.Count > 0)
@@ -1233,7 +1233,7 @@ namespace Barotrauma
//unconscious/dead characters can't correct their position using AnimController movement //unconscious/dead characters can't correct their position using AnimController movement
// -> we need to correct it manually // -> we need to correct it manually
if (!character.AllowMovement) if (!character.AllowInput)
{ {
Collider.LinearVelocity = overrideTargetMovement; Collider.LinearVelocity = overrideTargetMovement;
MainLimb.pullJoint.WorldAnchorB = Collider.SimPosition; MainLimb.pullJoint.WorldAnchorB = Collider.SimPosition;
+20 -13
View File
@@ -211,7 +211,7 @@ namespace Barotrauma
} }
} }
public bool AllowMovement public bool AllowInput
{ {
get { return !IsUnconscious && Stun <= 0.0f && !isDead; } get { return !IsUnconscious && Stun <= 0.0f && !isDead; }
} }
@@ -1016,6 +1016,8 @@ namespace Barotrauma
public bool CanAccessInventory(Inventory inventory) public bool CanAccessInventory(Inventory inventory)
{ {
if (!AllowInput || LockHands) return false;
if (inventory.Owner is Character && inventory.Owner != this) if (inventory.Owner is Character && inventory.Owner != this)
{ {
var owner = (Character)inventory.Owner; var owner = (Character)inventory.Owner;
@@ -1036,6 +1038,8 @@ namespace Barotrauma
public bool CanAccessItem(Item item) public bool CanAccessItem(Item item)
{ {
if (!AllowInput || LockHands) return false;
if (item.ParentInventory != null) if (item.ParentInventory != null)
{ {
return CanAccessInventory(item.ParentInventory); return CanAccessInventory(item.ParentInventory);
@@ -1336,12 +1340,11 @@ namespace Barotrauma
if (this != Character.Controlled) if (this != Character.Controlled)
{ {
if (GameMain.Server != null && !(this is AICharacter) && AllowMovement) if (GameMain.Server != null && !(this is AICharacter) && AllowInput)
{ {
if (memInput.Count == 0) if (memInput.Count == 0)
{ {
if (AllowInput) AnimController.Frozen = true;
if (AllowMovement) AnimController.Frozen = true;
return; return;
} }
@@ -2020,15 +2023,19 @@ namespace Barotrauma
{ {
InputNetFlags newInput = (InputNetFlags)msg.ReadRangedInteger(0, (int)InputNetFlags.MaxVal); InputNetFlags newInput = (InputNetFlags)msg.ReadRangedInteger(0, (int)InputNetFlags.MaxVal);
Vector2 newMousePos = Position; Vector2 newMousePos = Position;
if (newInput.HasFlag(InputNetFlags.Select) || newInput.HasFlag(InputNetFlags.Aim))
if (AllowInput)
{ {
newMousePos.X = msg.ReadSingle(); if (newInput.HasFlag(InputNetFlags.Select) || newInput.HasFlag(InputNetFlags.Aim))
newMousePos.Y = msg.ReadSingle(); {
} newMousePos.X = msg.ReadSingle();
if ((i < ((long)networkUpdateID - (long)LastNetworkUpdateID)) && (i < 60)) newMousePos.Y = msg.ReadSingle();
{ }
memInput.Insert(i, newInput); if ((i < ((long)networkUpdateID - (long)LastNetworkUpdateID)) && (i < 60))
memMousePos.Insert(i, newMousePos); {
memInput.Insert(i, newInput);
memMousePos.Insert(i, newMousePos);
}
} }
} }
@@ -2200,7 +2207,7 @@ namespace Barotrauma
var posInfo = new PosInfo(pos, facingRight ? Direction.Right : Direction.Left, networkUpdateID, sendingTime); var posInfo = new PosInfo(pos, facingRight ? Direction.Right : Direction.Left, networkUpdateID, sendingTime);
int index = 0; int index = 0;
if (GameMain.NetworkMember.Character == this && AllowMovement) if (GameMain.NetworkMember.Character == this && AllowInput)
{ {
while (index < memPos.Count && posInfo.ID > memPos[index].ID) while (index < memPos.Count && posInfo.ID > memPos[index].ID)
index++; index++;
+1 -1
View File
@@ -632,7 +632,7 @@ namespace Barotrauma.Networking
ChatMessage.ServerRead(inc, c); ChatMessage.ServerRead(inc, c);
break; break;
case ClientNetObject.CHARACTER_INPUT: case ClientNetObject.CHARACTER_INPUT:
if (c.Character != null && !c.Character.IsDead && !c.Character.IsUnconscious) if (c.Character != null)
{ {
c.Character.ServerRead(objHeader, inc, c); c.Character.ServerRead(objHeader, inc, c);
} }