Clients can't set the condition of an item unless the server says so, fixed low item condition being rounded down to zero when writing into a network msg

This commit is contained in:
Regalis
2017-03-21 17:31:22 +02:00
parent ec31e86350
commit dcd566f2dc
+6 -3
View File
@@ -181,6 +181,7 @@ namespace Barotrauma
get { return condition; } get { return condition; }
set set
{ {
if (GameMain.Client != null) return;
if (!MathUtils.IsValid(value)) return; if (!MathUtils.IsValid(value)) return;
float prev = condition; float prev = condition;
@@ -1722,11 +1723,13 @@ namespace Barotrauma
ownInventory.ServerWrite(msg, c, extraData); ownInventory.ServerWrite(msg, c, extraData);
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
msg.WriteRangedSingle(condition, 0.0f, 100.0f, 8); //clamp above 0.5f if condition > 0.0f
//to prevent condition from being rounded down to 0.0 even if the item is not broken
msg.WriteRangedSingle(condition > 0.0f ? Math.Max(condition, 0.5f) : 0.0f, 0.0f, 100.0f, 8);
if (condition <= 0.0f && FixRequirements.Count > 0) if (condition <= 0.0f && FixRequirements.Count > 0)
{ {
for (int i = 0; i<FixRequirements.Count; i++) for (int i = 0; i < FixRequirements.Count; i++)
msg.Write(FixRequirements[i].Fixed); msg.Write(FixRequirements[i].Fixed);
} }
break; break;
@@ -1761,7 +1764,7 @@ namespace Barotrauma
ownInventory.ClientRead(type, msg, sendingTime); ownInventory.ClientRead(type, msg, sendingTime);
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
Condition = msg.ReadRangedSingle(0.0f, 100.0f, 8); condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
if (FixRequirements.Count > 0) if (FixRequirements.Count > 0)
{ {