Skip to content

Commit 97cad1d

Browse files
committed
Update seeders to not error out and allow updating values quickly.
1 parent e791d56 commit 97cad1d

File tree

6 files changed

+288
-157
lines changed

6 files changed

+288
-157
lines changed

app/Models/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Service extends Model
4949
*
5050
* @return string
5151
*/
52-
public function defaultIndexFile()
52+
public static function defaultIndexFile()
5353
{
5454
return <<<'EOF'
5555
'use strict';

app/Repositories/ServiceRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function create(array $data)
5959
'description' => (isset($data['description'])) ? $data['description'] : null,
6060
'folder' => $data['folder'],
6161
'startup' => (isset($data['startup'])) ? $data['startup'] : null,
62-
'index_file' => $service->defaultIndexFile(),
62+
'index_file' => Service::defaultIndexFile(),
6363
])->save();
6464

6565
// It is possible for an event to return false or throw an exception

database/seeds/MinecraftServiceTableSeeder.php

Lines changed: 121 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
2323
*/
24-
use Pterodactyl\Models;
2524
use Illuminate\Database\Seeder;
25+
use Pterodactyl\Models\Service;
26+
use Pterodactyl\Models\ServiceOption;
27+
use Pterodactyl\Models\ServiceVariable;
2628

2729
class MinecraftServiceTableSeeder extends Seeder
2830
{
2931
/**
3032
* The core service ID.
3133
*
32-
* @var Models\Service
34+
* @var \Pterodactyl\Models\Service
3335
*/
3436
protected $service;
3537

@@ -40,6 +42,47 @@ class MinecraftServiceTableSeeder extends Seeder
4042
*/
4143
protected $option = [];
4244

45+
private $default_mc = <<<'EOF'
46+
'use strict';
47+
48+
/**
49+
* Pterodactyl - Daemon
50+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>
51+
*
52+
* Permission is hereby granted, free of charge, to any person obtaining a copy
53+
* of this software and associated documentation files (the "Software"), to deal
54+
* in the Software without restriction, including without limitation the rights
55+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56+
* copies of the Software, and to permit persons to whom the Software is
57+
* furnished to do so, subject to the following conditions:
58+
*
59+
* The above copyright notice and this permission notice shall be included in all
60+
* copies or substantial portions of the Software.
61+
*
62+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
67+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
68+
* SOFTWARE.
69+
*/
70+
const rfr = require('rfr');
71+
const _ = require('lodash');
72+
73+
const Core = rfr('src/services/index.js');
74+
75+
class Service extends Core {
76+
onConsole(data) {
77+
// Hide the output spam from Bungeecord getting pinged.
78+
if (_.endsWith(data, '<-> InitialHandler has connected')) return;
79+
return super.onConsole(data);
80+
}
81+
}
82+
83+
module.exports = Service;
84+
EOF;
85+
4386
/**
4487
* Run the database seeds.
4588
*
@@ -54,55 +97,76 @@ public function run()
5497

5598
private function addCoreService()
5699
{
57-
$this->service = Models\Service::create([
58-
'author' => 'ptrdctyl-v040-11e6-8b77-86f30ca893d3',
100+
$this->service = Service::updateOrCreate([
101+
'author' => config('pterodactyl.service.core'),
102+
'folder' => 'minecraft',
103+
], [
59104
'name' => 'Minecraft',
60105
'description' => 'Minecraft - the classic game from Mojang. With support for Vanilla MC, Spigot, and many others!',
61-
'file' => 'minecraft',
62-
'executable' => 'java',
63-
'startup' => '-Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}',
106+
'startup' => 'java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}',
107+
'index_file' => $this->default_mc,
64108
]);
65109
}
66110

67111
private function addCoreOptions()
68112
{
69-
$this->option['vanilla'] = Models\ServiceOption::create([
113+
$this->option['vanilla'] = ServiceOption::updateOrCreate([
70114
'service_id' => $this->service->id,
115+
'tag' => 'vanilla',
116+
], [
71117
'name' => 'Vanilla Minecraft',
72118
'description' => 'Minecraft is a game about placing blocks and going on adventures. Explore randomly generated worlds and build amazing things from the simplest of homes to the grandest of castles. Play in Creative Mode with unlimited resources or mine deep in Survival Mode, crafting weapons and armor to fend off dangerous mobs. Do all this alone or with friends.',
73-
'tag' => 'vanilla',
74119
'docker_image' => 'quay.io/pterodactyl/minecraft',
75-
'executable' => null,
120+
'config_startup' => '{"done": ")! For help, type ", "userInteraction": [ "Go to eula.txt for more info."]}',
121+
'config_logs' => '{"custom": false, "location": "logs/latest.log"}',
122+
'config_files' => '{"server.properties":{"parser": "properties", "find":{"server-ip": "0.0.0.0", "enable-query": "true", "server-port": "{{server.build.default.port}}", "query.port": "{{server.build.default.port}}"}}}',
123+
'config_stop' => 'stop',
124+
'config_from' => null,
76125
'startup' => null,
77126
]);
78127

79-
$this->option['spigot'] = Models\ServiceOption::create([
128+
$this->option['spigot'] = ServiceOption::updateOrCreate([
80129
'service_id' => $this->service->id,
130+
'tag' => 'spigot',
131+
], [
81132
'name' => 'Spigot',
82133
'description' => 'Spigot is the most widely-used modded Minecraft server software in the world. It powers many of the top Minecraft server networks around to ensure they can cope with their huge player base and ensure the satisfaction of their players. Spigot works by reducing and eliminating many causes of lag, as well as adding in handy features and settings that help make your job of server administration easier.',
83-
'tag' => 'spigot',
84134
'docker_image' => 'quay.io/pterodactyl/minecraft:spigot',
85-
'executable' => null,
86-
'startup' => '-Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}',
135+
'config_startup' => null,
136+
'config_files' => '{"spigot.yml":{"parser": "yaml", "find":{"settings.restart-on-crash": "false"}}}',
137+
'config_logs' => null,
138+
'config_stop' => null,
139+
'config_from' => $this->option['vanilla']->id,
140+
'startup' => null,
87141
]);
88142

89-
$this->option['sponge'] = Models\ServiceOption::create([
143+
$this->option['sponge'] = ServiceOption::updateOrCreate([
90144
'service_id' => $this->service->id,
145+
'tag' => 'sponge',
146+
], [
91147
'name' => 'Sponge (SpongeVanilla)',
92148
'description' => 'SpongeVanilla is the SpongeAPI implementation for Vanilla Minecraft.',
93-
'tag' => 'sponge',
94149
'docker_image' => 'quay.io/pterodactyl/minecraft:sponge',
95-
'executable' => null,
150+
'config_startup' => '{"userInteraction": [ "You need to agree to the EULA"]}',
151+
'config_files' => null,
152+
'config_logs' => null,
153+
'config_stop' => null,
154+
'config_from' => $this->option['vanilla']->id,
96155
'startup' => null,
97156
]);
98157

99-
$this->option['bungeecord'] = Models\ServiceOption::create([
158+
$this->option['bungeecord'] = ServiceOption::updateOrCreate([
100159
'service_id' => $this->service->id,
160+
'tag' => 'bungeecord',
161+
], [
101162
'name' => 'Bungeecord',
102163
'description' => 'For a long time, Minecraft server owners have had a dream that encompasses a free, easy, and reliable way to connect multiple Minecraft servers together. BungeeCord is the answer to said dream. Whether you are a small server wishing to string multiple game-modes together, or the owner of the ShotBow Network, BungeeCord is the ideal solution for you. With the help of BungeeCord, you will be able to unlock your community\'s full potential.',
103-
'tag' => 'bungeecord',
104164
'docker_image' => 'quay.io/pterodactyl/minecraft:bungeecord',
105-
'executable' => null,
165+
'config_startup' => '{"done": "Listening on ", "userInteraction": [ "Listening on /0.0.0.0:25577"]}',
166+
'config_files' => '{"config.yml":{"parser": "yaml", "find":{"listeners[0].query_enabled": true, "listeners[0].query_port": "{{server.build.default.port}}", "listeners[0].host": "0.0.0.0:{{server.build.default.port}}", "servers.*.address":{"127.0.0.1": "{{config.docker.interface}}", "localhost": "{{config.docker.interface}}"}}}}',
167+
'config_logs' => '{"custom": false, "location": "proxy.log.0"}',
168+
'config_stop' => 'end',
169+
'config_from' => null,
106170
'startup' => null,
107171
]);
108172
}
@@ -117,121 +181,130 @@ private function addVariables()
117181

118182
private function addVanillaVariables()
119183
{
120-
Models\ServiceVariable::create([
184+
ServiceVariable::updateOrCreate([
121185
'option_id' => $this->option['vanilla']->id,
186+
'env_variable' => 'SERVER_JARFILE',
187+
], [
122188
'name' => 'Server Jar File',
123189
'description' => 'The name of the server jarfile to run the server with.',
124-
'env_variable' => 'SERVER_JARFILE',
125190
'default_value' => 'server.jar',
126191
'user_viewable' => 1,
127192
'user_editable' => 1,
128193
'required' => 1,
129-
'regex' => '/^([\w\d._-]+)(\.jar)$/',
194+
'rules' => 'required|regex:/^([\w\d._-]+)(\.jar)$/',
130195
]);
131196

132-
Models\ServiceVariable::create([
197+
ServiceVariable::updateOrCreate([
133198
'option_id' => $this->option['vanilla']->id,
199+
'env_variable' => 'VANILLA_VERSION',
200+
], [
134201
'name' => 'Server Version',
135202
'description' => 'The version of Minecraft Vanilla to install. Use "latest" to install the latest version.',
136-
'env_variable' => 'VANILLA_VERSION',
137203
'default_value' => 'latest',
138204
'user_viewable' => 1,
139205
'user_editable' => 1,
140206
'required' => 1,
141-
'regex' => '/^(latest|[a-zA-Z0-9_\.-]{3,7})$/',
207+
'rules' => 'required|string|between:3,7',
142208
]);
143209
}
144210

145211
private function addSpigotVariables()
146212
{
147-
Models\ServiceVariable::create([
213+
ServiceVariable::updateOrCreate([
148214
'option_id' => $this->option['spigot']->id,
215+
'env_variable' => 'SERVER_JARFILE',
216+
], [
149217
'name' => 'Server Jar File',
150218
'description' => 'The name of the server jarfile to run the server with.',
151-
'env_variable' => 'SERVER_JARFILE',
152219
'default_value' => 'server.jar',
153220
'user_viewable' => 1,
154221
'user_editable' => 1,
155222
'required' => 1,
156-
'regex' => '/^([\w\d._-]+)(\.jar)$/',
223+
'rules' => 'required|regex:/^([\w\d._-]+)(\.jar)$/',
157224
]);
158225

159-
Models\ServiceVariable::create([
226+
ServiceVariable::updateOrCreate([
160227
'option_id' => $this->option['spigot']->id,
228+
'env_variable' => 'DL_VERSION',
229+
], [
161230
'name' => 'Spigot Version',
162231
'description' => 'The version of Spigot to download (using the --rev tag). Use "latest" for latest.',
163-
'env_variable' => 'DL_VERSION',
164232
'default_value' => 'latest',
165233
'user_viewable' => 1,
166234
'user_editable' => 1,
167235
'required' => 1,
168-
'regex' => '/^(latest|[a-zA-Z0-9_\.-]{3,7})$/',
236+
'rules' => 'required|string|between:3,7',
169237
]);
170238

171-
Models\ServiceVariable::create([
239+
ServiceVariable::updateOrCreate([
172240
'option_id' => $this->option['spigot']->id,
241+
'env_variable' => 'DL_PATH',
242+
], [
173243
'name' => 'Download Path',
174244
'description' => 'A URL to use to download Spigot rather than building it on the server. This is not user viewable. Use <code>{{DL_VERSION}}</code> in the URL to automatically insert the assigned version into the URL. If you do not enter a URL Spigot will build directly in the container (this will fail on low memory containers).',
175-
'env_variable' => 'DL_PATH',
176245
'default_value' => '',
177246
'user_viewable' => 0,
178247
'user_editable' => 0,
179248
'required' => 0,
180-
'regex' => '/^(.*)$/',
249+
'rules' => 'required|string',
181250
]);
182251
}
183252

184253
private function addSpongeVariables()
185254
{
186-
Models\ServiceVariable::create([
255+
ServiceVariable::updateOrCreate([
187256
'option_id' => $this->option['sponge']->id,
257+
'env_variable' => 'SPONGE_VERSION',
258+
], [
188259
'name' => 'Sponge Version',
189260
'description' => 'The version of SpongeVanilla to download and use.',
190-
'env_variable' => 'SPONGE_VERSION',
191-
'default_value' => '1.10.2-5.1.0-BETA-359',
261+
'default_value' => '1.10.2-5.2.0-BETA-381',
192262
'user_viewable' => 1,
193263
'user_editable' => 0,
194264
'required' => 1,
195-
'regex' => '/^([a-zA-Z0-9.\-_]+)$/',
265+
'rules' => 'required|regex:/^([a-zA-Z0-9.\-_]+)$/',
196266
]);
197267

198-
Models\ServiceVariable::create([
268+
ServiceVariable::updateOrCreate([
199269
'option_id' => $this->option['sponge']->id,
270+
'env_variable' => 'SERVER_JARFILE',
271+
], [
200272
'name' => 'Server Jar File',
201273
'description' => 'The name of the Jarfile to use when running SpongeVanilla.',
202-
'env_variable' => 'SERVER_JARFILE',
203274
'default_value' => 'server.jar',
204275
'user_viewable' => 1,
205276
'user_editable' => 1,
206277
'required' => 1,
207-
'regex' => '/^([\w\d._-]+)(\.jar)$/',
278+
'rules' => 'required|regex:/^([\w\d._-]+)(\.jar)$/',
208279
]);
209280
}
210281

211282
private function addBungeecordVariables()
212283
{
213-
Models\ServiceVariable::create([
284+
ServiceVariable::updateOrCreate([
214285
'option_id' => $this->option['bungeecord']->id,
286+
'env_variable' => 'BUNGEE_VERSION',
287+
], [
215288
'name' => 'Bungeecord Version',
216289
'description' => 'The version of Bungeecord to download and use.',
217-
'env_variable' => 'BUNGEE_VERSION',
218290
'default_value' => 'latest',
219291
'user_viewable' => 1,
220292
'user_editable' => 1,
221293
'required' => 1,
222-
'regex' => '/^(latest|[\d]{1,6})$/',
294+
'rules' => 'required|alpha_num|between:1,6',
223295
]);
224296

225-
Models\ServiceVariable::create([
297+
ServiceVariable::updateOrCreate([
226298
'option_id' => $this->option['bungeecord']->id,
299+
'env_variable' => 'SERVER_JARFILE',
300+
], [
227301
'name' => 'Bungeecord Jar File',
228302
'description' => 'The name of the Jarfile to use when running Bungeecord.',
229-
'env_variable' => 'SERVER_JARFILE',
230303
'default_value' => 'bungeecord.jar',
231304
'user_viewable' => 1,
232305
'user_editable' => 1,
233306
'required' => 1,
234-
'regex' => '/^([\w\d._-]+)(\.jar)$/',
307+
'rules' => 'required|regex:/^([\w\d._-]+)(\.jar)$/',
235308
]);
236309
}
237310
}

0 commit comments

Comments
 (0)