Skip to content

Commit

Permalink
Disable ability to change primary allocation ; Don't create allocatio…
Browse files Browse the repository at this point in the history
…n with automatic allocation ; Use allocations in order with automatic allocation ; Respect automatic allocation ports range
  • Loading branch information
Raraph84 committed Aug 6, 2024
1 parent 0e84c7a commit 85e8dc5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions app/Services/Allocations/FindAssignableAllocationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,27 @@ public function handle(Server $server): Allocation
throw new AutoAllocationNotEnabledException();
}

// Attempt to find a given available allocation for a server. If one cannot be found
// we will fall back to attempting to create a new allocation that can be used for the
// server.
$start = config('pterodactyl.client_features.allocations.range_start', null);
$end = config('pterodactyl.client_features.allocations.range_end', null);

if (!$start || !$end) {
throw new AutoAllocationNotEnabledException();
}

/** @var \Pterodactyl\Models\Allocation|null $allocation */
$allocation = $server->node->allocations()
->where('ip', $server->allocation->ip)
->where('port', '>=', $start)
->where('port', '<=', $end)
->whereNull('server_id')
->inRandomOrder()
//->inRandomOrder()
->first();

$allocation = $allocation ?? $this->createNewAllocation($server);
//$allocation = $allocation ?? $this->createNewAllocation($server);

if (!$allocation) {
throw new NoAutoAllocationSpaceAvailableException();
}

$allocation->update(['server_id' => $server->id]);

Expand Down
2 changes: 1 addition & 1 deletion routes/api-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
Route::get('/allocations', [Client\Servers\NetworkAllocationController::class, 'index']);
Route::post('/allocations', [Client\Servers\NetworkAllocationController::class, 'store']);
Route::post('/allocations/{allocation}', [Client\Servers\NetworkAllocationController::class, 'update']);
Route::post('/allocations/{allocation}/primary', [Client\Servers\NetworkAllocationController::class, 'setPrimary']);
//Route::post('/allocations/{allocation}/primary', [Client\Servers\NetworkAllocationController::class, 'setPrimary']);
Route::delete('/allocations/{allocation}', [Client\Servers\NetworkAllocationController::class, 'delete']);
});

Expand Down

0 comments on commit 85e8dc5

Please sign in to comment.