From d1f7fb8fb864e6bb6b13df143688283ee977f6ed Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Fri, 24 Jun 2022 16:15:13 +0200 Subject: [PATCH] Serialize the actor generation for network orders --- OpenRA.Game/Network/Order.cs | 7 +++++-- OpenRA.Game/Server/ProtocolVersion.cs | 2 +- OpenRA.Game/Traits/Target.cs | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs index 2f4049c0dd..e5c81c9b86 100644 --- a/OpenRA.Game/Network/Order.cs +++ b/OpenRA.Game/Network/Order.cs @@ -118,8 +118,10 @@ namespace OpenRA { case TargetType.Actor: { - if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor)) - target = Target.FromActor(targetActor); + var actorID = r.ReadUInt32(); + var actorGeneration = r.ReadInt32(); + if (world != null && TryGetActorFromUInt(world, actorID, out var targetActor)) + target = Target.FromSerializedActor(targetActor, actorGeneration); break; } @@ -367,6 +369,7 @@ namespace OpenRA { case TargetType.Actor: w.Write(UIntFromActor(Target.SerializableActor)); + w.Write(Target.SerializableGeneration); break; case TargetType.FrozenActor: w.Write(Target.FrozenActor.Viewer.PlayerActor.ActorID); diff --git a/OpenRA.Game/Server/ProtocolVersion.cs b/OpenRA.Game/Server/ProtocolVersion.cs index 927eaa9214..99e6c9109f 100644 --- a/OpenRA.Game/Server/ProtocolVersion.cs +++ b/OpenRA.Game/Server/ProtocolVersion.cs @@ -77,6 +77,6 @@ namespace OpenRA.Server // 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 = 19; + public const int Orders = 20; } } diff --git a/OpenRA.Game/Traits/Target.cs b/OpenRA.Game/Traits/Target.cs index 60984c3fe5..61a8952eb4 100644 --- a/OpenRA.Game/Traits/Target.cs +++ b/OpenRA.Game/Traits/Target.cs @@ -56,11 +56,11 @@ namespace OpenRA.Traits generation = 0; } - Target(Actor a) + Target(Actor a, int generation) { type = TargetType.Actor; actor = a; - generation = a.Generation; + this.generation = generation; terrainCenterPosition = WPos.Zero; terrainPositions = null; @@ -85,7 +85,7 @@ namespace OpenRA.Traits public static Target FromPos(WPos p) { return new Target(p); } public static Target FromTargetPositions(in Target t) { return new Target(t.CenterPosition, t.Positions.ToArray()); } public static Target FromCell(World w, CPos c, SubCell subCell = SubCell.FullCell) { return new Target(w, c, subCell); } - public static Target FromActor(Actor a) { return a != null ? new Target(a) : Invalid; } + public static Target FromActor(Actor a) { return a != null ? new Target(a, a.Generation) : Invalid; } public static Target FromFrozenActor(FrozenActor fa) { return new Target(fa); } public Actor Actor => actor; @@ -225,8 +225,10 @@ namespace OpenRA.Traits } // 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 SerializableType => type; internal Actor SerializableActor => actor; + internal int SerializableGeneration => generation; internal CPos? SerializableCell => cell; internal SubCell? SerializableSubCell => subCell; internal WPos SerializablePos => terrainCenterPosition;