mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): fence provider allocation results
This commit is contained in:
@@ -50,13 +50,14 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
|
||||
return true, fmt.Errorf("recover provider allocation for match %s: %w", request.MatchID, err)
|
||||
}
|
||||
if found {
|
||||
if err := validateRecoveredAllocation(request, recovered); err != nil {
|
||||
if err := validateProviderAllocation(request, recovered); err != nil {
|
||||
return true, fmt.Errorf("recovered provider allocation for match %s: %w", request.MatchID, err)
|
||||
}
|
||||
if _, err := w.Service.RecordProviderAllocation(ctx, recovered, w.Now()); err != nil {
|
||||
recorded, err := w.Service.RecordProviderAllocation(ctx, recovered, w.Now())
|
||||
if err != nil {
|
||||
return true, fmt.Errorf("record recovered allocation for match %s: %w", request.MatchID, err)
|
||||
}
|
||||
allocation = recovered.Allocation
|
||||
allocation = recorded
|
||||
} else {
|
||||
result, err := w.Service.Allocate(ctx, request, AllocationLabels(request))
|
||||
if err != nil {
|
||||
@@ -78,10 +79,10 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func validateRecoveredAllocation(request domain.AllocationRequest, result agones.AllocatedServer) error {
|
||||
func validateProviderAllocation(request domain.AllocationRequest, result agones.AllocatedServer) error {
|
||||
allocation := result.Allocation
|
||||
if result.Endpoint == "" || allocation.State != domain.ServerAllocated || allocation.AllocationID != request.AllocationID || allocation.MatchID != request.MatchID || allocation.ServerID == "" || allocation.Region != request.Region || allocation.Build != request.Build || allocation.Protocol != request.Protocol || allocation.Transport != request.Transport || allocation.ArenaPath != request.ArenaPath {
|
||||
return fmt.Errorf("recovered allocation does not match request")
|
||||
return fmt.Errorf("provider allocation does not match request")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user