Skip to content

Commit 87b96bd

Browse files
committed
Add core logic to allow for limited databases and allocations
1 parent 5f6c153 commit 87b96bd

File tree

8 files changed

+128
-43
lines changed

8 files changed

+128
-43
lines changed

app/Http/Requests/Api/Application/Servers/UpdateServerBuildConfigurationRequest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
1313
*/
1414
public function rules(): array
1515
{
16-
$rules = Server::getUpdateRulesForId($this->route()->parameter('server')->id);
16+
$rules = Server::getUpdateRulesForId($this->getModel(Server::class)->id);
1717

1818
return [
1919
'allocation' => $rules['allocation_id'],
@@ -26,6 +26,9 @@ public function rules(): array
2626
'add_allocations.*' => 'integer',
2727
'remove_allocations' => 'bail|array',
2828
'remove_allocations.*' => 'integer',
29+
'feature_limits' => 'required|array',
30+
'feature_limits.databases' => $rules['database_limit'],
31+
'feature_limits.allocations' => $rules['allocation_limit'],
2932
];
3033
}
3134

@@ -39,7 +42,9 @@ public function validated()
3942
$data = parent::validated();
4043

4144
$data['allocation_id'] = $data['allocation'];
42-
unset($data['allocation']);
45+
$data['database_limit'] = $data['feature_limits']['databases'];
46+
$data['allocation_limit'] = $data['feature_limits']['allocations'];
47+
unset($data['allocation'], $data['feature_limits']);
4348

4449
return $data;
4550
}
@@ -56,6 +61,8 @@ public function attributes()
5661
'remove_allocations' => 'allocations to remove',
5762
'add_allocations.*' => 'allocation to add',
5863
'remove_allocations.*' => 'allocation to remove',
64+
'feature_limits.databases' => 'Database Limit',
65+
'feature_limits.allocations' => 'Allocation Limit',
5966
];
6067
}
6168
}

app/Models/Server.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
6969
'skip_scripts' => 'sometimes',
7070
'image' => 'required',
7171
'startup' => 'required',
72+
'database_limit' => 'present',
73+
'allocation_limit' => 'present',
7274
];
7375

7476
/**
@@ -93,6 +95,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
9395
'skip_scripts' => 'boolean',
9496
'image' => 'string|max:255',
9597
'installed' => 'boolean',
98+
'database_limit' => 'nullable|integer|min:0',
99+
'allocation_limit' => 'nullable|integer|min:0',
96100
];
97101

98102
/**
@@ -116,6 +120,8 @@ class Server extends Model implements CleansAttributes, ValidableContract
116120
'egg_id' => 'integer',
117121
'pack_id' => 'integer',
118122
'installed' => 'integer',
123+
'database_limit' => 'integer',
124+
'allocation_limit' => 'integer',
119125
];
120126

121127
/**

app/Services/Servers/BuildModificationService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function handle(Server $server, array $data)
9191
'cpu' => array_get($data, 'cpu'),
9292
'disk' => array_get($data, 'disk'),
9393
'allocation_id' => array_get($data, 'allocation_id'),
94+
'database_limit' => array_get($data, 'database_limit'),
95+
'allocation_limit' => array_get($data, 'allocation_limit'),
9496
]);
9597

9698
$allocations = $this->allocationRepository->findWhere([['server_id', '=', $server->id]]);

app/Transformers/Api/Application/ServerTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public function transform(Server $server): array
7575
'io' => $server->io,
7676
'cpu' => $server->cpu,
7777
],
78+
'feature_limits' => [
79+
'databases' => $server->database_limit,
80+
'allocations' => $server->allocation_limit,
81+
],
7882
'user' => $server->owner_id,
7983
'node' => $server->node_id,
8084
'allocation' => $server->allocation_id,

app/Transformers/Api/Client/ServerTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public function transform(Server $server): array
3636
'io' => $server->io,
3737
'cpu' => $server->cpu,
3838
],
39+
'feature_limits' => [
40+
'databases' => $server->database_limit,
41+
'allocations' => $server->allocation_limit,
42+
],
3943
];
4044
}
4145
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddDatabaseAndPortLimitColumnsToServersTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('servers', function (Blueprint $table) {
17+
$table->unsignedInteger('database_limit')->after('installed')->nullable()->default(0);
18+
$table->unsignedInteger('allocation_limit')->after('installed')->nullable()->default(0);
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::table('servers', function (Blueprint $table) {
30+
$table->dropColumn(['database_limit', 'allocation_limit']);
31+
});
32+
}
33+
}

resources/themes/pterodactyl/admin/servers/new.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<div class="form-group col-sm-4">
112112
<label for="pSwap">Swap</label>
113113
<div class="input-group">
114-
<input type="text" value="{{ old('swap') }}" class="form-control" name="swap" id="pSwap" />
114+
<input type="text" value="{{ old('swap', 0) }}" class="form-control" name="swap" id="pSwap" />
115115
<span class="input-group-addon">MB</span>
116116
</div>
117117
</div>

resources/themes/pterodactyl/admin/servers/view/build.blade.php

Lines changed: 69 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -89,50 +89,79 @@
8989
</div>
9090
</div>
9191
<div class="col-sm-7">
92-
<div class="box">
93-
<div class="box-header with-border">
94-
<h3 class="box-title">Allocation Management</h3>
95-
</div>
96-
<div class="box-body">
97-
<div class="form-group">
98-
<label for="pAllocation" class="control-label">Game Port</label>
99-
<select id="pAllocation" name="allocation_id" class="form-control">
100-
@foreach ($assigned as $assignment)
101-
<option value="{{ $assignment->id }}"
102-
@if($assignment->id === $server->allocation_id)
103-
selected="selected"
104-
@endif
105-
>{{ $assignment->alias }}:{{ $assignment->port }}</option>
106-
@endforeach
107-
</select>
108-
<p class="text-muted small">The default connection address that will be used for this game server.</p>
109-
</div>
110-
<div class="form-group">
111-
<label for="pAddAllocations" class="control-label">Assign Additional Ports</label>
112-
<div>
113-
<select name="add_allocations[]" class="form-control" multiple id="pAddAllocations">
114-
@foreach ($unassigned as $assignment)
115-
<option value="{{ $assignment->id }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
116-
@endforeach
117-
</select>
92+
<div class="row">
93+
<div class="col-xs-12">
94+
<div class="box">
95+
<div class="box-header with-border">
96+
<h3 class="box-title">Application Feature Limits</h3>
11897
</div>
119-
<p class="text-muted small">Please note that due to software limitations you cannot assign identical ports on different IPs to the same server.</p>
120-
</div>
121-
<div class="form-group">
122-
<label for="pRemoveAllocations" class="control-label">Remove Additional Ports</label>
123-
<div>
124-
<select name="remove_allocations[]" class="form-control" multiple id="pRemoveAllocations">
125-
@foreach ($assigned as $assignment)
126-
<option value="{{ $assignment->id }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
127-
@endforeach
128-
</select>
98+
<div class="box-body">
99+
<div class="row">
100+
<div class="form-group col-xs-6">
101+
<label for="cpu" class="control-label">Database Limit</label>
102+
<div>
103+
<input type="text" name="database_limit" class="form-control" value="{{ old('database_limit', $server->database_limit) }}"/>
104+
</div>
105+
<p class="text-muted small">The total number of databases a user is allowed to create for this server. Leave blank to allow unlimmited.</p>
106+
</div>
107+
<div class="form-group col-xs-6">
108+
<label for="cpu" class="control-label">Allocation Limit</label>
109+
<div>
110+
<input type="text" name="allocation_limit" class="form-control" value="{{ old('allocation_limit', $server->allocation_limit) }}"/>
111+
</div>
112+
<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. Leave blank to allow unlimited.</p>
113+
</div>
114+
</div>
129115
</div>
130-
<p class="text-muted small">Simply select which ports you would like to remove from the list above. If you want to assign a port on a different IP that is already in use you can select it from the left and delete it here.</p>
131116
</div>
132117
</div>
133-
<div class="box-footer">
134-
{!! csrf_field() !!}
135-
<button type="submit" class="btn btn-primary pull-right">Update Build Configuration</button>
118+
<div class="col-xs-12">
119+
<div class="box">
120+
<div class="box-header with-border">
121+
<h3 class="box-title">Allocation Management</h3>
122+
</div>
123+
<div class="box-body">
124+
<div class="form-group">
125+
<label for="pAllocation" class="control-label">Game Port</label>
126+
<select id="pAllocation" name="allocation_id" class="form-control">
127+
@foreach ($assigned as $assignment)
128+
<option value="{{ $assignment->id }}"
129+
@if($assignment->id === $server->allocation_id)
130+
selected="selected"
131+
@endif
132+
>{{ $assignment->alias }}:{{ $assignment->port }}</option>
133+
@endforeach
134+
</select>
135+
<p class="text-muted small">The default connection address that will be used for this game server.</p>
136+
</div>
137+
<div class="form-group">
138+
<label for="pAddAllocations" class="control-label">Assign Additional Ports</label>
139+
<div>
140+
<select name="add_allocations[]" class="form-control" multiple id="pAddAllocations">
141+
@foreach ($unassigned as $assignment)
142+
<option value="{{ $assignment->id }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
143+
@endforeach
144+
</select>
145+
</div>
146+
<p class="text-muted small">Please note that due to software limitations you cannot assign identical ports on different IPs to the same server.</p>
147+
</div>
148+
<div class="form-group">
149+
<label for="pRemoveAllocations" class="control-label">Remove Additional Ports</label>
150+
<div>
151+
<select name="remove_allocations[]" class="form-control" multiple id="pRemoveAllocations">
152+
@foreach ($assigned as $assignment)
153+
<option value="{{ $assignment->id }}">{{ $assignment->alias }}:{{ $assignment->port }}</option>
154+
@endforeach
155+
</select>
156+
</div>
157+
<p class="text-muted small">Simply select which ports you would like to remove from the list above. If you want to assign a port on a different IP that is already in use you can select it from the left and delete it here.</p>
158+
</div>
159+
</div>
160+
<div class="box-footer">
161+
{!! csrf_field() !!}
162+
<button type="submit" class="btn btn-primary pull-right">Update Build Configuration</button>
163+
</div>
164+
</div>
136165
</div>
137166
</div>
138167
</div>

0 commit comments

Comments
 (0)