forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerConfigurationStructureService.php
More file actions
135 lines (127 loc) · 4.43 KB
/
ServerConfigurationStructureService.php
File metadata and controls
135 lines (127 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
namespace Pterodactyl\Services\Servers;
use Pterodactyl\Models\Mount;
use Pterodactyl\Models\Server;
class ServerConfigurationStructureService
{
/**
* @var \Pterodactyl\Services\Servers\EnvironmentService
*/
private $environment;
/**
* ServerConfigurationStructureService constructor.
*
* @param \Pterodactyl\Services\Servers\EnvironmentService $environment
*/
public function __construct(EnvironmentService $environment)
{
$this->environment = $environment;
}
/**
* Return a configuration array for a specific server when passed a server model.
*
* DO NOT MODIFY THIS FUNCTION. This powers legacy code handling for the new Wings
* daemon, if you modify the structure eggs will break unexpectedly.
*
* @param \Pterodactyl\Models\Server $server
* @param array $override
* @param bool $legacy deprecated
* @return array
*/
public function handle(Server $server, array $override = [], bool $legacy = false): array
{
$clone = $server;
// If any overrides have been set on this call make sure to update them on the
// cloned instance so that the configuration generated uses them.
if (!empty($override)) {
$clone = $server->fresh();
foreach ($override as $key => $value) {
$clone->setAttribute($key, $value);
}
}
return $legacy
? $this->returnLegacyFormat($clone)
: $this->returnCurrentFormat($clone);
}
/**
* Returns the new data format used for the Wings daemon.
*
* @param \Pterodactyl\Models\Server $server
* @return array
*/
protected function returnCurrentFormat(Server $server)
{
return [
'uuid' => $server->uuid,
'suspended' => $server->suspended,
'environment' => $this->environment->handle($server),
'invocation' => $server->startup,
'skip_egg_scripts' => $server->skip_scripts,
'build' => [
'memory_limit' => $server->memory,
'swap' => $server->swap,
'io_weight' => $server->io,
'cpu_limit' => $server->cpu,
'threads' => $server->threads,
'disk_space' => $server->disk,
],
'container' => [
'image' => $server->image,
'oom_disabled' => $server->oom_disabled,
'requires_rebuild' => false,
],
'allocations' => [
'default' => [
'ip' => $server->allocation->ip,
'port' => $server->allocation->port,
],
'mappings' => $server->getAllocationMappings(),
],
'mounts' => $server->mounts->map(function (Mount $mount) {
return [
'source' => $mount->source,
'target' => $mount->target,
'read_only' => $mount->read_only,
];
}),
];
}
/**
* Returns the legacy server data format to continue support for old egg configurations
* that have not yet been updated.
*
* @param \Pterodactyl\Models\Server $server
* @return array
* @deprecated
*/
protected function returnLegacyFormat(Server $server)
{
return [
'uuid' => $server->uuid,
'build' => [
'default' => [
'ip' => $server->allocation->ip,
'port' => $server->allocation->port,
],
'ports' => $server->allocations->groupBy('ip')->map(function ($item) {
return $item->pluck('port');
})->toArray(),
'env' => $this->environment->handle($server),
'oom_disabled' => $server->oom_disabled,
'memory' => (int)$server->memory,
'swap' => (int)$server->swap,
'io' => (int)$server->io,
'cpu' => (int)$server->cpu,
'threads' => $server->threads,
'disk' => (int)$server->disk,
'image' => $server->image,
],
'service' => [
'egg' => $server->egg->uuid,
'skip_scripts' => $server->skip_scripts,
],
'rebuild' => false,
'suspended' => (int)$server->suspended,
];
}
}