mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 12:22:04 +00:00
feat(multiplayer): rotate ranked arenas deterministically
This commit is contained in:
+18
-1
@@ -1,6 +1,9 @@
|
||||
package domain
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type RankedParticipant struct {
|
||||
PlayerID string
|
||||
@@ -25,6 +28,8 @@ var rankedArenas = map[string]RankedArena{
|
||||
"arena_03": {ID: "arena_03", Path: "res://scenes/arena_03.tscn"},
|
||||
}
|
||||
|
||||
var rankedArenaOrder = []string{"arena_01", "arena_02", "arena_03"}
|
||||
|
||||
// DefaultRankedArena supplies a safe server-owned eligibility decision while
|
||||
// the allocator-to-Godot match configuration channel is being completed. A
|
||||
// ranked proposal is never admitted based on a mutable command-line boolean.
|
||||
@@ -32,6 +37,18 @@ func DefaultRankedArena() RankedArena {
|
||||
return rankedArenas["arena_01"]
|
||||
}
|
||||
|
||||
// RankedArenaForProposal chooses a floor-goal arena deterministically from the
|
||||
// proposal identity. The same durable proposal retry therefore cannot change
|
||||
// arena, while independent proposals rotate across the registry without
|
||||
// mutable worker-local counters.
|
||||
func RankedArenaForProposal(proposalID string) RankedArena {
|
||||
if proposalID == "" {
|
||||
return DefaultRankedArena()
|
||||
}
|
||||
digest := sha256.Sum256([]byte(proposalID))
|
||||
return rankedArenas[rankedArenaOrder[int(digest[0])%len(rankedArenaOrder)]]
|
||||
}
|
||||
|
||||
func ValidateRankedAdmission(participants []RankedParticipant, arena RankedArena) error {
|
||||
if len(participants) != 6 || !validRankedArena(arena) {
|
||||
return fmt.Errorf("ranked admission requirements not met")
|
||||
|
||||
Reference in New Issue
Block a user