fix: enforce matchmaking compatibility boundaries

This commit is contained in:
Josh Creek
2026-08-31 22:04:57 +01:00
parent b1314074a8
commit b47c7dc3fa
3 changed files with 49 additions and 2 deletions
+18 -1
View File
@@ -92,7 +92,7 @@ func SelectCandidates(anchor Candidate, candidates []Candidate, size int, now ti
seen := map[string]bool{}
seenPlayers := map[string]bool{}
add := func(candidate Candidate) {
if validCandidate(candidate) && !seen[candidate.TicketID] && !seenPlayers[candidate.PlayerID] {
if validCandidate(candidate) && compatibleMetadata(anchor, candidate) && !seen[candidate.TicketID] && !seenPlayers[candidate.PlayerID] {
seen[candidate.TicketID] = true
seenPlayers[candidate.PlayerID] = true
pool = append(pool, candidate)
@@ -139,6 +139,23 @@ func SelectCandidates(anchor Candidate, candidates []Candidate, size int, now ti
return best, nil
}
// compatibleMetadata prevents a queue projection from crossing playlist or
// protocol/build boundaries. Empty anchor metadata is retained for older
// direct/community callers; once the queue has selected a compatibility
// contract, every participant must carry the exact same values.
func compatibleMetadata(anchor, candidate Candidate) bool {
if anchor.Playlist != "" && candidate.Playlist != anchor.Playlist {
return false
}
if anchor.ClientBuild != "" && candidate.ClientBuild != anchor.ClientBuild {
return false
}
if anchor.ProtocolVersion > 0 && candidate.ProtocolVersion != anchor.ProtocolVersion {
return false
}
return true
}
func validCandidate(candidate Candidate) bool {
if candidate.TicketID == "" || candidate.PlayerID == "" || candidate.EnqueuedAt.IsZero() || math.IsNaN(candidate.Rating) || math.IsInf(candidate.Rating, 0) {
return false