Skip to content

Commit fb33824

Browse files
committed
Added admin controls.
Removed the note in the server settings that stated that the allocations feature is currently not implemented. Properly check to make sure that there are allocations available in range before trying to create it.
1 parent d80660f commit fb33824

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

app/Http/Controllers/Api/Client/Servers/NetworkAllocationController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\NewAllocationRequest;
1818
use Pterodactyl\Http\Requests\Api\Client\Servers\Network\SetPrimaryAllocationRequest;
1919
use Pterodactyl\Services\Allocations\AssignmentService;
20+
use Illuminate\Support\Facades\Log;
2021

2122
class NetworkAllocationController extends ClientApiController
2223
{
@@ -136,8 +137,8 @@ public function setPrimary(SetPrimaryAllocationRequest $request, Server $server,
136137
public function addNew(NewAllocationRequest $request, Server $server): array
137138
{
138139
Log::info('addNew()');
139-
$topRange = config('pterodactyl.allocation.start');
140-
$bottomRange = config('pterodactyl.allocation.stop');
140+
$topRange = config('pterodactyl.allocation.stop',0);
141+
$bottomRange = config('pterodactyl.allocation.start',0);
141142
Log::error($bottomRange);
142143
Log::error($topRange);
143144

@@ -151,7 +152,7 @@ public function addNew(NewAllocationRequest $request, Server $server): array
151152
$allocation = $server->node->allocations()->where('ip',$server->allocation->ip)->whereNull('server_id')->first();
152153

153154
if(!$allocation) {
154-
if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange || config('pterodactyl.allocation.enabled', 0)) {
155+
if($server->node->allocations()->where('ip',$server->allocation->ip)->where([['port', '>=', $bottomRange ], ['port', '<=', $topRange],])->count() >= $topRange-$bottomRange+1 || !config('allocation.enabled', false)) {
155156
Log::error('No allocations available!');
156157
throw new DisplayException(
157158
'No more allocations available!'
@@ -163,7 +164,6 @@ public function addNew(NewAllocationRequest $request, Server $server): array
163164
do {
164165
$port = rand($bottomRange, $topRange);
165166
Log::info('Picking port....');
166-
// TODO ADD ITERATOR THAT TIMES OUT AFTER SEARCHING FOR SO MUCH TIME?
167167
} while(array_search($port, $allPorts));
168168

169169
$this->assignmentService->handle($server->node,[

app/Providers/SettingsServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class SettingsServiceProvider extends ServiceProvider
3030
'pterodactyl:console:count',
3131
'pterodactyl:console:frequency',
3232
'pterodactyl:auth:2fa_required',
33+
'allocation:enabled',
34+
'pterodactyl:allocation:stop',
35+
'pterodactyl:allocation:start',
3336
];
3437

3538
/**

resources/views/admin/servers/view/build.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
<div>
116116
<input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/>
117117
</div>
118-
<p class="text-muted small"><strong>This feature is not currently implemented.</strong> The total number of allocations a user is allowed to create for this server.</p>
118+
<p class="text-muted small">The total number of allocations a user is allowed to create for this server.</p>
119119
</div>
120120
<div class="form-group col-xs-6">
121121
<label for="backup_limit" class="control-label">Backup Limit</label>

resources/views/admin/settings/advanced.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@
115115
<label class="control-label">Status</label>
116116
<div>
117117
<select class="form-control" name="allocation:enabled">
118-
<option value="true" @if(old('allocation:enabled', config('allocation.enabled')) == '1') selected @endif>Enabled</option>
119118
<option value="false">Disabled</option>
119+
<option value="true" @if(old('allocation:enabled', config('allocation.enabled'))) selected @endif>Enabled</option>
120120
</select>
121121
<p class="text-muted small">If enabled, the panel will attempt to auto create a new allocation in the range specified if there are no more allocations already created on the node.</p>
122122
</div>

0 commit comments

Comments
 (0)