mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): centralize arena path validation
This commit is contained in:
@@ -137,7 +137,7 @@ func (a *Allocator) PublishAssignment(allocationID string, manifest AllocationMa
|
||||
}
|
||||
|
||||
func validateAllocationRequest(request AllocationRequest) error {
|
||||
if request.AllocationID == "" || request.MatchID == "" || request.Region == "" || request.Build == "" || request.Protocol <= 0 || (request.Transport != "enet" && request.Transport != "steam_sdr") {
|
||||
if request.AllocationID == "" || request.MatchID == "" || request.Region == "" || request.Build == "" || request.Protocol <= 0 || (request.Transport != "enet" && request.Transport != "steam_sdr") || (request.ArenaPath != "" && !IsRankedArenaPath(request.ArenaPath)) {
|
||||
return ErrAllocationInput
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -53,6 +53,19 @@ func TestAllocatorRejectsInvalidServerAndNoCompatibleCapacity(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllocatorRejectsUnregisteredArenaPath(t *testing.T) {
|
||||
a, err := NewAllocator([]ReadyServer{{ServerID: "server-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet", State: ServerReady}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, path := range []string{"res://scenes/arena_01_elevated.tscn", "res://forged.tscn"} {
|
||||
request := AllocationRequest{AllocationID: "allocation-" + path, MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, ArenaPath: path, Transport: "enet"}
|
||||
if _, err := a.Allocate(request, time.Unix(1000, 0)); !errors.Is(err, ErrAllocationInput) {
|
||||
t.Fatalf("arena path %q returned %v, want ErrAllocationInput", path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllocatorConcurrentClaimsCannotDoubleAllocateOneServer(t *testing.T) {
|
||||
a, _ := NewAllocator([]ReadyServer{{ServerID: "server-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet", State: ServerReady}})
|
||||
requests := []AllocationRequest{
|
||||
|
||||
@@ -140,7 +140,7 @@ func RecordProviderAllocation(ctx context.Context, db *sql.DB, allocation domain
|
||||
}
|
||||
|
||||
func validAllocationInput(db *sql.DB, request domain.AllocationRequest, now time.Time) bool {
|
||||
return db != nil && request.AllocationID != "" && request.MatchID != "" && (request.Region == "EU" || request.Region == "NA") && request.Build != "" && request.Protocol > 0 && (request.Transport == "enet" || request.Transport == "steam_sdr") && !now.IsZero()
|
||||
return db != nil && request.AllocationID != "" && request.MatchID != "" && (request.Region == "EU" || request.Region == "NA") && request.Build != "" && request.Protocol > 0 && (request.Transport == "enet" || request.Transport == "steam_sdr") && (request.ArenaPath == "" || domain.IsRankedArenaPath(request.ArenaPath)) && !now.IsZero()
|
||||
}
|
||||
|
||||
func allocationRequestDigest(request domain.AllocationRequest) [32]byte {
|
||||
|
||||
Reference in New Issue
Block a user