mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-15 21:22:05 +00:00
fix: enforce matchmaking compatibility boundaries
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user