feat: sanity-check claim save/free against tracked ordering state

This commit is contained in:
2026-07-18 11:47:52 +02:00
parent de2026d239
commit 94b6723456
2 changed files with 50 additions and 2 deletions
+15
View File
@@ -66,4 +66,19 @@ public class ClaimLinkModSystem : ModSystem
claim = null; claim = null;
return false; return false;
} }
internal static bool TryResolveClaimIndex(string ownerPlayerUid, LandClaim target, out int claimIndex)
{
foreach ((int index, LandClaim c) in EnumerateOwnedClaims(ownerPlayerUid))
{
if (ReferenceEquals(c, target))
{
claimIndex = index;
return true;
}
}
claimIndex = -1;
return false;
}
} }
+35 -2
View File
@@ -110,7 +110,26 @@ public class ClaimLinkCommandListener : ICommandHookListener
PendingLoads.Remove(caller.Player.PlayerUID); PendingLoads.Remove(caller.Player.PlayerUID);
} }
private static void Free(Caller caller, CmdArgs args, TextCommandResult? result) { } private static void Free(Caller caller, CmdArgs args, TextCommandResult? result)
{
if (result == null || result.Status != EnumCommandStatus.Success || caller.Player == null)
return;
string uid = caller.Player.PlayerUID;
int? claimIndex = args.PopInt();
if (claimIndex == null)
return;
if (args.PopWord() != "confirm")
return;
ClaimLink? link = ClaimLinkModSystem.Registry.FindLinkContaining(uid, (int)claimIndex);
ClaimLinkModSystem.Logger.Notification(
link != null
? $"claimlink: freed claim {claimIndex} for {uid} was linked to group {link.GroupId}"
: $"claimlink: freed claim {claimIndex} for {uid} was not linked"
);
}
private static void Info(Caller caller, CmdArgs args, TextCommandResult? result) { } private static void Info(Caller caller, CmdArgs args, TextCommandResult? result) { }
@@ -148,7 +167,21 @@ public class ClaimLinkCommandListener : ICommandHookListener
private static void ClaimFullHeight(Caller caller, CmdArgs args, TextCommandResult? result) { } private static void ClaimFullHeight(Caller caller, CmdArgs args, TextCommandResult? result) { }
private static void ClaimSave(Caller caller, CmdArgs args, TextCommandResult? result) { } private static void ClaimSave(Caller caller, CmdArgs args, TextCommandResult? result)
{
if (result == null || result.Status != EnumCommandStatus.Success || caller.Player == null)
return;
string uid = caller.Player.PlayerUID;
int? claimIndex = args.PopInt();
if (PendingLoads.TryGetValue(uid, out int pendingIndex) && claimIndex != pendingIndex)
ClaimLinkModSystem.Logger.Error(
$"claimlink: claim save index mismatch for {uid}: pending={pendingIndex} saved={claimIndex}"
);
PendingLoads.Remove(uid);
}
private static void ClaimDownload(Caller caller, CmdArgs args, TextCommandResult? result) { } private static void ClaimDownload(Caller caller, CmdArgs args, TextCommandResult? result) { }