Fixed incorrect msg lengths in CHARACTER_POSITION messages (+ calculating the length automatically)

This commit is contained in:
Regalis
2017-01-07 16:11:50 +02:00
parent 7dc474dab4
commit 6364915353
+18 -17
View File
@@ -2067,18 +2067,16 @@ namespace Barotrauma
{ {
msg.Write(ID); msg.Write(ID);
NetBuffer tempBuffer = new NetBuffer();
if (this == c.Character) if (this == c.Character)
{ {
//length of the message tempBuffer.Write(true);
msg.Write((byte)(4+4+4)); tempBuffer.Write((UInt32)(LastNetworkUpdateID - memInput.Count - 1));
msg.Write(true);
msg.Write((UInt32)(LastNetworkUpdateID - memInput.Count - 1));
} }
else else
{ {
//length of the message tempBuffer.Write(false);
msg.Write((byte)(4+4+1 + 1 + 1));
msg.Write(false);
bool aiming = false; bool aiming = false;
bool use = false; bool use = false;
@@ -2096,17 +2094,17 @@ namespace Barotrauma
networkUpdateSent = true; networkUpdateSent = true;
} }
msg.Write(aiming); tempBuffer.Write(aiming);
msg.Write(use); tempBuffer.Write(use);
if (selectedCharacter != null || selectedConstruction != null) if (selectedCharacter != null || selectedConstruction != null)
{ {
msg.Write(true); tempBuffer.Write(true);
msg.Write(selectedCharacter != null ? selectedCharacter.ID : selectedConstruction.ID); tempBuffer.Write(selectedCharacter != null ? selectedCharacter.ID : selectedConstruction.ID);
} }
else else
{ {
msg.Write(false); tempBuffer.Write(false);
} }
if (aiming) if (aiming)
@@ -2114,15 +2112,18 @@ namespace Barotrauma
//TODO: write this with less accuracy? //TODO: write this with less accuracy?
msg.Write(cursorPosition.X); tempBuffer.Write(cursorPosition.X);
msg.Write(cursorPosition.Y); tempBuffer.Write(cursorPosition.Y);
} }
msg.Write(AnimController.TargetDir == Direction.Right); tempBuffer.Write(AnimController.TargetDir == Direction.Right);
} }
msg.Write(SimPosition.X); tempBuffer.Write(SimPosition.X);
msg.Write(SimPosition.Y); tempBuffer.Write(SimPosition.Y);
msg.Write((byte)tempBuffer.LengthBytes);
msg.Write(tempBuffer);
msg.WritePadBits(); msg.WritePadBits();
} }