22
33namespace Pterodactyl \Http \Controllers \Api \Client \Servers ;
44
5+ use Illuminate \Contracts \Config \Repository ;
56use Pterodactyl \Models \Server ;
67use Illuminate \Http \JsonResponse ;
78use Pterodactyl \Models \Allocation ;
1617use Pterodactyl \Http \Requests \Api \Client \Servers \Network \NewAllocationRequest ;
1718use Pterodactyl \Http \Requests \Api \Client \Servers \Network \SetPrimaryAllocationRequest ;
1819use Pterodactyl \Services \Allocations \AssignmentService ;
19- use Illuminate \Support \Facades \Log ;
2020
2121class NetworkAllocationController extends ClientApiController
2222{
@@ -41,17 +41,27 @@ class NetworkAllocationController extends ClientApiController
4141 * @param \Pterodactyl\Repositories\Eloquent\AllocationRepository $repository
4242 * @param \Pterodactyl\Repositories\Eloquent\ServerRepository $serverRepository
4343 * @param \Pterodactyl\Services\Allocations\AssignmentService $assignmentService
44+ * @param \Illuminate\Contracts\Config\Repository $config
4445 */
46+
47+ /**
48+ * @var \Illuminate\Contracts\Config\Repository
49+ */
50+ private $ config ;
51+
4552 public function __construct (
4653 AllocationRepository $ repository ,
4754 ServerRepository $ serverRepository ,
48- AssignmentService $ assignmentService
55+ AssignmentService $ assignmentService ,
56+ Repository $ config
57+
4958 ) {
5059 parent ::__construct ();
5160
5261 $ this ->repository = $ repository ;
5362 $ this ->serverRepository = $ serverRepository ;
5463 $ this ->assignmentService = $ assignmentService ;
64+ $ this ->config = $ config ;
5565 }
5666
5767 /**
@@ -126,8 +136,10 @@ public function setPrimary(SetPrimaryAllocationRequest $request, Server $server,
126136 public function addNew (NewAllocationRequest $ request , Server $ server ): array
127137 {
128138 Log::info ('addNew() ' );
129- $ topRange = 25700 ;
130- $ bottomRange = 25565 ;
139+ $ topRange = config ('pterodactyl.allocation.start ' );
140+ $ bottomRange = config ('pterodactyl.allocation.stop ' );
141+ Log::error ($ bottomRange );
142+ Log::error ($ topRange );
131143
132144 if ($ server ->allocation_limit <= $ server ->allocations ->count ()) {
133145 Log::error ('You have created the maximum number of allocations! ' );
@@ -139,7 +151,7 @@ public function addNew(NewAllocationRequest $request, Server $server): array
139151 $ allocation = $ server ->node ->allocations ()->where ('ip ' ,$ server ->allocation ->ip )->whereNull ('server_id ' )->first ();
140152
141153 if (!$ allocation ) {
142- if ($ server ->node ->allocations ()->where ('ip ' ,$ server ->allocation ->ip )->count () >= $ topRange -$ bottomRange ) {
154+ if ($ server ->node ->allocations ()->where ('ip ' ,$ server ->allocation ->ip )->where ([[ ' port ' , ' >= ' , $ bottomRange ], [ ' port ' , ' <= ' , $ topRange ],])-> count () >= $ topRange -$ bottomRange || config ( ' pterodactyl.allocation.enabled ' , 0 ) ) {
143155 Log::error ('No allocations available! ' );
144156 throw new DisplayException (
145157 'No more allocations available! '
0 commit comments