Store job/shop values and vehicle switch states for late joiners (2.9.2)
WorldVars and VehicleControls were only relayed; players joining later only got them with the next save pull. They are now stored in world.json (cleared with a new save) and appended to the world snapshot (old clients ignore it). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,11 @@ try
|
||||
Check(relay != null, "Object states are relayed to Bob");
|
||||
alice.Send(MsgType.VarSync, Wire.Build(w => { w.Write(2); w.Write(42); w.Write((byte)1); w.Write(3.5f); w.Write(43); w.Write((byte)3); w.Write(true); }));
|
||||
await bob.WaitFor(MsgType.VarSync);
|
||||
// Jobs/Laden und Schalter (Licht an, Motor läuft) werden gespeichert, damit später Beitretende sie haben
|
||||
alice.Send(MsgType.WorldVars, Wire.Build(w => { w.Write(2); w.Write(7); w.Write((byte)2); w.Write(5); w.Write(8); w.Write((byte)3); w.Write(true); }));
|
||||
await bob.WaitFor(MsgType.WorldVars);
|
||||
alice.Send(MsgType.VehicleControls, Wire.Build(w => { w.Write(1); w.Write(99); w.Write("Lights"); }));
|
||||
await bob.WaitFor(MsgType.VehicleControls);
|
||||
var carol = await TestClient.Join("Carol", 0, null);
|
||||
carol.Send(MsgType.Ready, Array.Empty<byte>());
|
||||
var snap2 = Snapshot.Parse(await carol.WaitFor(MsgType.WorldSnapshot));
|
||||
@@ -76,6 +81,8 @@ try
|
||||
Check(!snap2.ObjectIds.Contains(333), "Pose far below the map is rejected");
|
||||
Check(!snap2.ObjectIds.Contains(444), "Invalid quaternion is rejected");
|
||||
Check(snap2.Vars == 2, "Vehicle values are stored and sent to new players (" + snap2.Vars + ")");
|
||||
Check(snap2.JobVars == 2 && snap2.Controls.TryGetValue(99, out string lightState) && lightState == "Lights",
|
||||
"Job/shop values and switch states (lights, engine) are stored for players joining later");
|
||||
|
||||
Console.WriteLine("== Server full");
|
||||
var eve = await TestClient.Join("Eve", 0, null);
|
||||
@@ -583,6 +590,8 @@ sealed class Snapshot
|
||||
public List<int> Destroyed = new();
|
||||
public Dictionary<string, float> Needs = new();
|
||||
public int Vars = -1;
|
||||
public int JobVars = -1;
|
||||
public Dictionary<int, string> Controls = new();
|
||||
|
||||
public static Snapshot Parse(byte[] data)
|
||||
{
|
||||
@@ -612,6 +621,10 @@ sealed class Snapshot
|
||||
int needs = r.ReadInt32();
|
||||
for (int i = 0; i < needs; i++) s.Needs[r.ReadString()] = r.ReadSingle();
|
||||
}
|
||||
s.JobVars = r.ReadInt32();
|
||||
for (int i = 0; i < s.JobVars; i++) { r.ReadInt32(); byte t = r.ReadByte(); r.ReadBytes(t == 3 ? 1 : 4); }
|
||||
int controls = r.ReadInt32();
|
||||
for (int i = 0; i < controls; i++) { int key = r.ReadInt32(); s.Controls[key] = r.ReadString(); }
|
||||
s.Ok = r.BaseStream.Position == r.BaseStream.Length;
|
||||
s.Info = $"{objects} objects, {events} events, money {money}, {doors} doors, {s.Vars} vars";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user