fix: guard claim-link entries against stale indices and dead groups
This commit is contained in:
@@ -63,14 +63,19 @@ public class ClaimLinkRegistry
|
||||
return null;
|
||||
}
|
||||
|
||||
public void AddEntry(string uid, int groupId, int claimIndex)
|
||||
public bool AddEntry(string uid, int groupId, int claimIndex)
|
||||
{
|
||||
if (ClaimLinkCommandListener.PendingLoads.ContainsKey(uid))
|
||||
return false;
|
||||
if (!Exists(groupId))
|
||||
return false;
|
||||
if (!entries.TryGetValue(uid, out var groups))
|
||||
entries[uid] = groups = new();
|
||||
if (!groups.TryGetValue(groupId, out var claims))
|
||||
groups[groupId] = claims = new();
|
||||
claims.Add(claimIndex);
|
||||
Save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveEntry(string uid, int groupId, int claimIndex)
|
||||
@@ -93,6 +98,7 @@ public class ClaimLinkRegistry
|
||||
if (claims[i] > removedIndex)
|
||||
claims[i]--;
|
||||
}
|
||||
|
||||
Prune();
|
||||
Save();
|
||||
}
|
||||
@@ -119,6 +125,7 @@ public class ClaimLinkRegistry
|
||||
if (i >= 0)
|
||||
claims[i] = newIndex;
|
||||
}
|
||||
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -170,15 +177,15 @@ public class ClaimLinkRegistry
|
||||
{
|
||||
var entryList = new List<ClaimLinkEntrySaveData>();
|
||||
foreach (var (uid, groups) in entries)
|
||||
foreach (var (groupId, claims) in groups)
|
||||
entryList.Add(
|
||||
new ClaimLinkEntrySaveData
|
||||
{
|
||||
OwnerPlayerUid = uid,
|
||||
GroupId = groupId,
|
||||
ClaimIndicies = new(claims),
|
||||
}
|
||||
);
|
||||
foreach (var (groupId, claims) in groups)
|
||||
entryList.Add(
|
||||
new ClaimLinkEntrySaveData
|
||||
{
|
||||
OwnerPlayerUid = uid,
|
||||
GroupId = groupId,
|
||||
ClaimIndicies = new(claims),
|
||||
}
|
||||
);
|
||||
|
||||
saveGame.StoreData(
|
||||
SaveKey,
|
||||
|
||||
Reference in New Issue
Block a user