Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix terrain positions for targets not being serialized for Orders #21021

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion OpenRA.Game/Network/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,18 @@ public static Order Deserialize(World world, BinaryReader r)
else
{
var pos = new WPos(r.ReadInt32(), r.ReadInt32(), r.ReadInt32());
target = Target.FromPos(pos);

var numberOfTerrainPositions = r.ReadInt16();
if (numberOfTerrainPositions == -1)
target = Target.FromPos(pos);
RoosterDragon marked this conversation as resolved.
Show resolved Hide resolved
else
{
var terrainPositions = new WPos[numberOfTerrainPositions];
for (var i = 0; i < numberOfTerrainPositions; i++)
terrainPositions[i] = new WPos(r.ReadInt32(), r.ReadInt32(), r.ReadInt32());

target = Target.FromSerializedTerrainPosition(pos, terrainPositions);
}
}

break;
Expand Down Expand Up @@ -388,6 +399,21 @@ public byte[] Serialize()
w.Write(targetState.Pos.X);
w.Write(targetState.Pos.Y);
w.Write(targetState.Pos.Z);

// Don't send extra data over the network that will be restored by the Target ctor
var terrainPositions = targetState.TerrainPositions.Length;
if (terrainPositions == 1 && targetState.TerrainPositions[0] == targetState.Pos)
w.Write((short)-1);
else
{
w.Write((short)terrainPositions);
foreach (var position in targetState.TerrainPositions)
{
w.Write(position.X);
w.Write(position.Y);
w.Write(position.Z);
}
}
}

break;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/ProtocolVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ public static class ProtocolVersion
// The protocol for server and world orders
// This applies after the handshake has completed, and is provided to support
// alternative server implementations that wish to support multiple versions in parallel
public const int Orders = 20;
public const int Orders = 21;
}
}
5 changes: 3 additions & 2 deletions OpenRA.Game/Traits/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ public override bool Equals(object other)

// Expose internal state for serialization by the orders code *only*
internal static Target FromSerializedActor(Actor a, int generation) { return a != null ? new Target(a, generation) : Invalid; }
internal (TargetType Type, Actor Actor, int Generation, CPos? Cell, SubCell? SubCell, WPos Pos) SerializableState =>
(type, Actor, generation, cell, subCell, terrainCenterPosition);
internal static Target FromSerializedTerrainPosition(WPos centerPosition, WPos[] terrainPositions) { return new Target(centerPosition, terrainPositions); }
internal (TargetType Type, Actor Actor, int Generation, CPos? Cell, SubCell? SubCell, WPos Pos, WPos[] TerrainPositions) SerializableState =>
(type, Actor, generation, cell, subCell, terrainCenterPosition, terrainPositions);
}
}