From dd86b5745a284c88c6f690df6e2866d14d04c4ab Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 21 Sep 2017 17:44:52 +0300 Subject: [PATCH] - The server doesn't disable client-controlled AI characters that are far from all other players. - Clients aren't allowed to flip swimming FishAnimControllers unless the server says so (occasionally caused creatures to flip around constantly because the clients ignore the 1-second "flipping cooldown"). - Moved Character.ReadStatus to the client project. --- .../Source/Characters/CharacterNetworking.cs | 76 ++++++++++++++++++ .../Animation/FishAnimController.cs | 49 ++++++------ .../Source/Characters/Character.cs | 2 + .../Source/Characters/CharacterNetworking.cs | 77 ------------------- 4 files changed, 101 insertions(+), 103 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs index 1b5d1698b..6a2a08c6c 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs @@ -299,5 +299,81 @@ namespace Barotrauma return character; } + + private void ReadStatus(NetBuffer msg) + { + bool isDead = msg.ReadBoolean(); + if (isDead) + { + causeOfDeath = (CauseOfDeath)msg.ReadByte(); + byte severedLimbCount = msg.ReadByte(); + if (!IsDead) + { + if (causeOfDeath == CauseOfDeath.Pressure) + { + Implode(true); + } + else + { + Kill(causeOfDeath, true); + } + } + + for (int i = 0; i < severedLimbCount; i++) + { + int severedJointIndex = msg.ReadByte(); + AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]); + } + } + else + { + this.isDead = false; + + health = msg.ReadRangedSingle(minHealth, maxHealth, 8); + + bool lowOxygen = msg.ReadBoolean(); + if (lowOxygen) + { + Oxygen = msg.ReadRangedSingle(-100.0f, 100.0f, 8); + } + else + { + Oxygen = 100.0f; + } + + bool isBleeding = msg.ReadBoolean(); + if (isBleeding) + { + bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8); + } + else + { + bleeding = 0.0f; + } + + bool stunned = msg.ReadBoolean(); + if (stunned) + { + float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8); + SetStun(newStunTimer, true, true); + } + else + { + SetStun(0.0f, true, true); + } + + bool huskInfected = msg.ReadBoolean(); + if (huskInfected) + { + HuskInfectionState = Math.Max(HuskInfectionState, 0.01f); + } + else + { + HuskInfectionState = 0.0f; + } + + } + } + } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs index ee9714d70..55b23c9b3 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/FishAnimController.cs @@ -120,12 +120,10 @@ namespace Barotrauma UpdateWalkAnim(deltaTime); } - - if (mirror || !inWater) + if (!character.IsRemotePlayer) { - if (!character.IsRemotePlayer) + if (mirror || !inWater) { - //targetDir = (movement.X > 0.0f) ? Direction.Right : Direction.Left; if (targetMovement.X > 0.1f && targetMovement.X > Math.Abs(targetMovement.Y) * 0.5f) { TargetDir = Direction.Right; @@ -135,40 +133,39 @@ namespace Barotrauma TargetDir = Direction.Left; } } - - } - else - { - Limb head = GetLimb(LimbType.Head); - if (head == null) head = GetLimb(LimbType.Torso); - - float rotation = MathUtils.WrapAngleTwoPi(head.Rotation); - rotation = MathHelper.ToDegrees(rotation); - - if (rotation < 0.0f) rotation += 360; - - if (rotation > 20 && rotation < 160) + else { - TargetDir = Direction.Left; - } - else if (rotation > 200 && rotation < 340) - { - TargetDir = Direction.Right; + Limb head = GetLimb(LimbType.Head); + if (head == null) head = GetLimb(LimbType.Torso); + + float rotation = MathUtils.WrapAngleTwoPi(head.Rotation); + rotation = MathHelper.ToDegrees(rotation); + + if (rotation < 0.0f) rotation += 360; + + if (rotation > 20 && rotation < 160) + { + TargetDir = Direction.Left; + } + else if (rotation > 200 && rotation < 340) + { + TargetDir = Direction.Right; + } } } - + if (!flip) return; flipTimer += deltaTime; if (TargetDir != Direction.None && TargetDir != dir) - { - if (flipTimer>1.0f || character.IsRemotePlayer) + { + if (flipTimer > 1.0f || character.IsRemotePlayer) { Flip(); if (mirror || !inWater) Mirror(); flipTimer = 0.0f; - } + } } } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 1bf68ae3b..72193eeea 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1314,7 +1314,9 @@ namespace Barotrauma //disable AI characters that are far away from all clients and the host's character and not controlled by anyone c.Enabled = c == controlled || + c.IsRemotePlayer || CharacterList.Any(c2 => + c != c2 && (c2.IsRemotePlayer || c2 == GameMain.Server.Character) && Vector2.DistanceSquared(c2.WorldPosition, c.WorldPosition) < NetConfig.CharacterIgnoreDistanceSqr); } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs index 8f412f8b7..bd6d8c1c8 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs @@ -527,83 +527,6 @@ namespace Barotrauma } } - private void ReadStatus(NetBuffer msg) - { - if (GameMain.Server != null) - { - DebugConsole.ThrowError("Server attempted to read character status from a networked message"); - return; - } - - bool isDead = msg.ReadBoolean(); - if (isDead) - { - causeOfDeath = (CauseOfDeath)msg.ReadByte(); - byte severedLimbCount = msg.ReadByte(); - if (causeOfDeath == CauseOfDeath.Pressure) - { - Implode(true); - } - else - { - Kill(causeOfDeath, true); - } - for (int i = 0; i < severedLimbCount; i++) - { - int severedJointIndex = msg.ReadByte(); - AnimController.SeverLimbJoint(AnimController.LimbJoints[severedJointIndex]); - } - } - else - { - this.isDead = false; - - health = msg.ReadRangedSingle(minHealth, maxHealth, 8); - - bool lowOxygen = msg.ReadBoolean(); - if (lowOxygen) - { - Oxygen = msg.ReadRangedSingle(-100.0f, 100.0f, 8); - } - else - { - Oxygen = 100.0f; - } - - bool isBleeding = msg.ReadBoolean(); - if (isBleeding) - { - bleeding = msg.ReadRangedSingle(0.0f, 5.0f, 8); - } - else - { - bleeding = 0.0f; - } - - bool stunned = msg.ReadBoolean(); - if (stunned) - { - float newStunTimer = msg.ReadRangedSingle(0.0f, 60.0f, 8); - SetStun(newStunTimer, true, true); - } - else - { - SetStun(0.0f, true, true); - } - - bool huskInfected = msg.ReadBoolean(); - if (huskInfected) - { - HuskInfectionState = Math.Max(HuskInfectionState, 0.01f); - } - else - { - HuskInfectionState = 0.0f; - } - - } - } - public void WriteSpawnData(NetBuffer msg) { if (GameMain.Server == null) return;