Production ready: hardening, limits, docs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 20:55:39 +02:00
co-authored by Claude Opus 5.5
parent 4a948128e5
commit 7e291d06ea
6 changed files with 63 additions and 4 deletions
+12 -1
View File
@@ -79,7 +79,11 @@ public sealed class WorldState
void ReadPose(BinaryReader r)
{
int id = r.ReadInt32();
if (!Objects.TryGetValue(id, out var pose)) Objects[id] = pose = new ObjectPose();
if (!Objects.TryGetValue(id, out var pose))
{
pose = new ObjectPose(); // bei voller Liste nur mitlesen, nicht speichern
if (Objects.Count < MaxObjects) Objects[id] = pose;
}
for (int k = 0; k < 3; k++) pose.P[k] = r.ReadSingle();
for (int k = 0; k < 4; k++) pose.R[k] = r.ReadSingle();
r.ReadSingle(); r.ReadSingle(); r.ReadSingle(); // Geschwindigkeit wird nicht gespeichert
@@ -113,13 +117,20 @@ public sealed class WorldState
var all = new byte[value.Length + 1];
all[0] = type;
value.CopyTo(all, 1);
if (Vars.Count >= MaxVars && !Vars.ContainsKey(key)) continue;
Vars[key] = Convert.ToBase64String(all);
}
Dirty = true;
}
// Obergrenzen, damit ein fehlerhafter oder manipulierter Client world.json nicht endlos aufbläht
public const int MaxEvents = 50_000;
public const int MaxVars = 50_000;
public const int MaxObjects = 20_000;
public void AddFsmEvent(byte[] payload)
{
if (Events.Count >= MaxEvents) return;
Events.Add(Convert.ToBase64String(payload));
Dirty = true;
}