diff --git a/.vs/Subsurface_Solution/v14/.suo b/.vs/Subsurface_Solution/v14/.suo new file mode 100644 index 000000000..69b1e8619 Binary files /dev/null and b/.vs/Subsurface_Solution/v14/.suo differ diff --git a/Report20151010-1429.vspx b/Report20151010-1429.vspx new file mode 100644 index 000000000..57f40c253 Binary files /dev/null and b/Report20151010-1429.vspx differ diff --git a/Report20151010-1451.vspx b/Report20151010-1451.vspx new file mode 100644 index 000000000..d578c0c9c Binary files /dev/null and b/Report20151010-1451.vspx differ diff --git a/Subsurface/Source/Characters/AI/EnemyAIController.cs b/Subsurface/Source/Characters/AI/EnemyAIController.cs index 1e75e725e..58b4242eb 100644 --- a/Subsurface/Source/Characters/AI/EnemyAIController.cs +++ b/Subsurface/Source/Characters/AI/EnemyAIController.cs @@ -518,8 +518,8 @@ namespace Barotrauma if (wallAttack) { - message.Write(wallAttackPos.X); - message.Write(wallAttackPos.Y); + message.WriteRangedSingle(wallAttackPos.X, -50.0f, 50.0f, 10); + message.WriteRangedSingle(wallAttackPos.Y, -50.0f, 50.0f, 10); } //message.Write(Velocity.X); @@ -559,7 +559,9 @@ namespace Barotrauma if (wallAttack) { - newWallAttackPos = new Vector2(message.ReadFloat(), message.ReadFloat()); + newWallAttackPos = new Vector2( + message.ReadRangedSingle(-50.0f, 50.0f, 10), + message.ReadRangedSingle(-50.0f, 50.0f, 10)); } //newVelocity = new Vector2(message.ReadFloat(), message.ReadFloat()); diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs index 30f24bc05..57f0d9e38 100644 --- a/Subsurface/Source/Characters/AICharacter.cs +++ b/Subsurface/Source/Characters/AICharacter.cs @@ -95,8 +95,11 @@ namespace Barotrauma { if (limb.ignoreCollisions) continue; - message.Write(limb.body.SimPosition.X); - message.Write(limb.body.SimPosition.Y); + if (limb.SimPosition.Length() > NetConfig.AllowedRagdollDistance) return false; + + message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16); + message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16); + message.Write(limb.body.Rotation); i++; @@ -111,14 +114,14 @@ namespace Barotrauma message.Write((float)NetTime.Now); message.Write(AnimController.TargetDir == Direction.Right); - message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.X, -10.0f, 10.0f), -10.0f, 10.0f, 16); - message.WriteRangedSingle(MathHelper.Clamp(AnimController.TargetMovement.Y, -10.0f, 10.0f), -10.0f, 10.0f, 16); + message.WriteRangedSingle(AnimController.TargetMovement.X, -1.0f, 1.0f, 8); + message.WriteRangedSingle(AnimController.TargetMovement.Y, -1.0f, 1.0f, 8); - message.Write(AnimController.RefLimb.SimPosition.X); - message.Write(AnimController.RefLimb.SimPosition.Y); + message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16); + message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.AllowedRagdollDistance, NetConfig.AllowedRagdollDistance, 16); - message.Write(AnimController.RefLimb.LinearVelocity.X); - message.Write(AnimController.RefLimb.LinearVelocity.Y); + //message.Write(AnimController.RefLimb.LinearVelocity.X); + //message.Write(AnimController.RefLimb.LinearVelocity.Y); return true; } @@ -144,9 +147,9 @@ namespace Barotrauma try { - limbPos.X = message.ReadFloat(); - limbPos.Y = message.ReadFloat(); - + limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + rotation = message.ReadFloat(); } catch @@ -190,14 +193,14 @@ namespace Barotrauma try { targetDir = message.ReadBoolean(); - targetMovement.X = message.ReadRangedSingle(-10.0f, 10.0f, 16); - targetMovement.Y = message.ReadRangedSingle(-10.0f, 10.0f, 16); + targetMovement.X = message.ReadRangedSingle(-1.0f, 1.0f, 8); + targetMovement.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8); - pos.X = message.ReadFloat(); - pos.Y = message.ReadFloat(); + pos.X = message.ReadRangedSingle(-1.0f, 1.0f, 8); + pos.Y = message.ReadRangedSingle(-1.0f, 1.0f, 8); - vel.X = message.ReadFloat(); - vel.Y = message.ReadFloat(); + //vel.X = message.ReadFloat(); + //vel.Y = message.ReadFloat(); } catch (Exception e) diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 276d52317..654d8610c 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -1157,11 +1157,14 @@ namespace Barotrauma if (inventory == null) return false; return inventory.FillNetworkData(NetworkEventType.InventoryUpdate, message, data); case NetworkEventType.ImportantEntityUpdate: + int i = 0; foreach (Limb limb in AnimController.Limbs) { - message.Write(limb.body.SimPosition.X); - message.Write(limb.body.SimPosition.Y); + if (limb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; + + message.WriteRangedSingle(limb.body.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + message.WriteRangedSingle(limb.body.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); //message.Write(limb.body.LinearVelocity.X); //message.Write(limb.body.LinearVelocity.Y); @@ -1175,7 +1178,6 @@ namespace Barotrauma message.Write((byte)((health/maxHealth)*255.0f)); message.Write((byte)(MathHelper.Clamp(oxygen * 2.55f, 0.0f, 255.0f))); - return true; case NetworkEventType.EntityUpdate: var hasInputs = @@ -1206,16 +1208,20 @@ namespace Barotrauma if (secondaryHeld) { - message.Write(cursorPosition.X); - message.Write(cursorPosition.Y); + Vector2 relativeCursorPosition = cursorPosition - Position; + + message.WriteRangedSingle(relativeCursorPosition.X, -2000.0f, 2000.0f, 8); + message.WriteRangedSingle(relativeCursorPosition.Y, -2000.0f, 2000.0f, 8); } else { message.Write(AnimController.Dir > 0.0f); } - message.Write(AnimController.RefLimb.SimPosition.X); - message.Write(AnimController.RefLimb.SimPosition.Y); + if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return true; + + message.WriteRangedSingle(AnimController.RefLimb.SimPosition.X, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + message.WriteRangedSingle(AnimController.RefLimb.SimPosition.Y, -NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); return true; default: @@ -1298,9 +1304,9 @@ namespace Barotrauma try { - limbPos.X = message.ReadFloat(); - limbPos.Y = message.ReadFloat(); - + limbPos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + limbPos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + rotation = message.ReadFloat(); } catch @@ -1335,7 +1341,7 @@ namespace Barotrauma return; case NetworkEventType.EntityUpdate: float sendingTime = 0.0f; - Vector2 cursorPos = Vector2.Zero; + Vector2 relativeCursorPos = Vector2.Zero; bool actionKeyState, secondaryKeyState; bool leftKeyState, rightKeyState, upKeyState, downKeyState; @@ -1390,29 +1396,38 @@ namespace Barotrauma { if (secondaryKeyState) { - cursorPos = new Vector2( - message.ReadFloat(), - message.ReadFloat()); + relativeCursorPos = new Vector2( + message.ReadRangedSingle(-2000.0f, 2000.0f, 8), + message.ReadRangedSingle(-2000.0f, 2000.0f, 8)); } else { dir = message.ReadBoolean() ? 1.0f : -1.0f; } - - pos.X = message.ReadFloat(); - pos.Y = message.ReadFloat(); - } catch { #if DEBUG - DebugConsole.ThrowError("Failed to read netowkrevent for "+this.ToString()); + DebugConsole.ThrowError("Failed to read networkevent for "+this.ToString()); #endif return; } + try + { + pos.X = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + pos.Y = message.ReadRangedSingle(-NetConfig.CharacterIgnoreDistance, NetConfig.CharacterIgnoreDistance, 16); + } + + catch + { + //failed to read position, character may be further than NetConfig.CharacterIgnoreDistance + pos = SimPosition; + } + if (secondaryKeyState) { - cursorPosition = MathUtils.IsValid(cursorPos) ? cursorPos : Vector2.Zero; + cursorPosition = MathUtils.IsValid(relativeCursorPos) ? + ConvertUnits.ToDisplayUnits(pos)+relativeCursorPos : Vector2.Zero; } else { diff --git a/Subsurface/Source/Items/Components/Machines/Pump.cs b/Subsurface/Source/Items/Components/Machines/Pump.cs index 2efdeb34d..7535a9068 100644 --- a/Subsurface/Source/Items/Components/Machines/Pump.cs +++ b/Subsurface/Source/Items/Components/Machines/Pump.cs @@ -168,8 +168,9 @@ namespace Barotrauma.Items.Components public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) { - message.Write(Convert.ToByte(flowPercentage+100)); + message.WriteRangedInteger(-10,10,(int)(flowPercentage/10.0f)); message.Write(IsActive); + message.WritePadBits(); } public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) @@ -179,7 +180,7 @@ namespace Barotrauma.Items.Components try { - newFlow = (float)(message.ReadByte()-100); + newFlow = message.ReadRangedInteger(-10,10)*10.0f; newActive = message.ReadBoolean(); } diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index d34334680..5bc195f42 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -427,7 +427,7 @@ namespace Barotrauma.Items.Components { message.Write(autoTemp); message.WriteRangedSingle(temperature, 0.0f, 10000.0f, 16); - message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 16); + message.WriteRangedSingle(shutDownTemp, 0.0f, 10000.0f, 7); message.WriteRangedSingle(coolingRate, 0.0f, 100.0f, 8); message.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8); @@ -443,7 +443,8 @@ namespace Barotrauma.Items.Components { newAutoTemp = message.ReadBoolean(); newTemperature = message.ReadRangedSingle(0.0f, 10000.0f, 16); - newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 16); + newShutDownTemp = message.ReadRangedSingle(0.0f, 10000.0f, 7); + newShutDownTemp = MathUtils.Round(newShutDownTemp, 100.0f); newCoolingRate = message.ReadRangedSingle(0.0f, 100.0f, 8); newFissionRate = message.ReadRangedSingle(0.0f, 100.0f, 8); diff --git a/Subsurface/Source/Items/Components/Power/PowerContainer.cs b/Subsurface/Source/Items/Components/Power/PowerContainer.cs index 12f5bebf5..393f3e60a 100644 --- a/Subsurface/Source/Items/Components/Power/PowerContainer.cs +++ b/Subsurface/Source/Items/Components/Power/PowerContainer.cs @@ -198,23 +198,25 @@ namespace Barotrauma.Items.Components public override void FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message) { - message.Write((byte)((int)(rechargeSpeed/maxRechargeSpeed*255.0f))); - message.Write(charge); + message.WriteRangedSingle(MathHelper.Clamp(rechargeSpeed/MaxRechargeSpeed, 0.0f, 1.0f), 0.0f, 1.0f, 8); + message.WriteRangedSingle(MathHelper.Clamp(charge/capacity,0.0f, 1.0f), 0.0f, 1.0f, 8); } public override void ReadNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetIncomingMessage message) { - byte newRechargeSpeed = 0; + float newRechargeSpeed = 0f; float newCharge = 0.0f; try { - newRechargeSpeed = message.ReadByte(); - newCharge = message.ReadFloat(); + newRechargeSpeed = message.ReadRangedSingle(0.0f, 1.0f, 8); + newRechargeSpeed *= MaxRechargeSpeed; + newCharge = message.ReadRangedSingle(0.0f, 1.0f, 8); + newCharge *= capacity; } catch { } - RechargeSpeed = (newRechargeSpeed/255.0f)*maxRechargeSpeed; + RechargeSpeed = newRechargeSpeed; Charge = newCharge; } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index b3a3e42f0..5f586dbbd 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -471,8 +471,8 @@ namespace Barotrauma } public override bool FillNetworkData(Networking.NetworkEventType type, Lidgren.Network.NetOutgoingMessage message, object data) - { - message.Write(volume); + { + message.WriteRangedSingle(MathHelper.Clamp(volume/FullVolume, 0.0f, 1.5f), 0.0f, 1.5f, 6); return true; } @@ -483,7 +483,7 @@ namespace Barotrauma try { - newVolume = message.ReadFloat(); + float newPercentage = message.ReadRangedSingle(0.0f, 1.5f, 6); } catch diff --git a/Subsurface/Source/Map/Structure.cs b/Subsurface/Source/Map/Structure.cs index c5b16eb73..e0c2a21a7 100644 --- a/Subsurface/Source/Map/Structure.cs +++ b/Subsurface/Source/Map/Structure.cs @@ -653,7 +653,7 @@ namespace Barotrauma message.Write((float)NetTime.Now); message.Write(byteIndex); - message.Write(sections[sectionIndex].damage); + message.WriteRangedSingle(sections[sectionIndex].damage/Health, 0.0f, 1.0f, 8); return true; } @@ -668,7 +668,7 @@ namespace Barotrauma { updateTime = message.ReadFloat(); sectionIndex = message.ReadByte(); - damage = message.ReadFloat(); + damage = message.ReadRangedSingle(0.0f, 1.0f, 8) * Health; } catch { diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index ef86135e9..f44d800a6 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -314,7 +314,7 @@ namespace Barotrauma.Networking { if (c as AICharacter == null) continue; - if (c.SimPosition.Length() > 100.0f) continue; + if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; c.CreateUpdateNetworkEvent(false); } diff --git a/Subsurface/Source/Networking/NetConfig.cs b/Subsurface/Source/Networking/NetConfig.cs index a0a59ea7d..969eaa0ca 100644 --- a/Subsurface/Source/Networking/NetConfig.cs +++ b/Subsurface/Source/Networking/NetConfig.cs @@ -14,6 +14,10 @@ namespace Barotrauma.Networking public static string MasterServerUrl = GameMain.Config.MasterServerUrl; + //if a character is further than this from the sub, the server will ignore it + //(in sim units) + public const float CharacterIgnoreDistance = 100.0f; + //if a ragdoll is further than this from the correct position, teleport it there //(in sim units) public const float ResetRagdollDistance = 2.0f; diff --git a/UpgradeLog.htm b/UpgradeLog.htm new file mode 100644 index 000000000..c8914030b Binary files /dev/null and b/UpgradeLog.htm differ diff --git a/UpgradeLog2.htm b/UpgradeLog2.htm new file mode 100644 index 000000000..c8914030b Binary files /dev/null and b/UpgradeLog2.htm differ