Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 2f488ae

Browse files
authored
feat: Added the ability to select the java version for minecraft servers (#303)
* feat: Added the ability to select the java version for minecraft servers * fix: Unused array elements have been removed
1 parent 7ef645c commit 2f488ae

File tree

15 files changed

+440
-7
lines changed

15 files changed

+440
-7
lines changed

system/acp/engine/java.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018-2025 Solovev Sergei
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
if (!defined('EGP')) {
20+
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
21+
}
22+
23+
$info = '<i class="fa-brands fa-java"></i> Управление версиями java';
24+
25+
$aSection = [
26+
'index',
27+
'add',
28+
'delete',
29+
];
30+
31+
if (!in_array($section, $aSection)) {
32+
$section = 'index';
33+
}
34+
35+
$html->get('menu', 'sections/java');
36+
37+
$html->unit('s_' . $section, true);
38+
39+
unset($aSection[array_search($section, $aSection)]);
40+
41+
foreach ($aSection as $noactive) {
42+
$html->unit('s_' . $noactive);
43+
}
44+
45+
$sql->query('SELECT `id` FROM `java_versions`');
46+
$html->set('java', $sql->num());
47+
48+
$html->pack('menu');
49+
50+
include(SEC . 'java/' . $section . '.php');

system/acp/sections/java/add.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018-2025 Solovev Sergei
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
if (!defined('EGP')) {
20+
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
21+
}
22+
23+
if ($go) {
24+
$aData = [];
25+
26+
$aData['unit'] = isset($_POST['unit']) ? trim($_POST['unit']) : '';
27+
$aData['name'] = isset($_POST['name']) ? trim($_POST['name']) : '';
28+
$aData['executable_file'] = isset($_POST['executable_file']) ? trim($_POST['executable_file']) : '';
29+
$aData['status'] = $_POST['status'] ?? 1;
30+
31+
if (in_array('', $aData)) {
32+
sys::outjs(['e' => 'Необходимо заполнить все поля']);
33+
}
34+
35+
$sql->query('INSERT INTO `java_versions` set '
36+
. '`unit`="' . $aData['unit'] . '",'
37+
. '`name`="' . htmlspecialchars($aData['name']) . '",'
38+
. '`executable_file`="' . $aData['executable_file'] . '",'
39+
. '`status`="' . $aData['status'] . '"');
40+
41+
sys::outjs(['s' => $sql->id()]);
42+
}
43+
44+
$unit = '<option value="0">Выберите локацию</option>';
45+
46+
$sql->query('SELECT `id`, `name` FROM `units` ORDER BY `id` ASC');
47+
while ($units = $sql->get()) {
48+
$unit .= '<option value="' . $units['id'] . '">#' . $units['id'] . ' ' . $units['name'] . '</option>';
49+
}
50+
51+
$html->get('add', 'sections/java');
52+
53+
$html->set('unit', $unit);
54+
55+
$html->pack('main');
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018-2025 Solovev Sergei
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
if (!defined('EGP')) {
20+
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
21+
}
22+
23+
$sql->query('SELECT `id` FROM `servers` WHERE `java_version`="' . $id . '" LIMIT 1');
24+
if ($sql->num()) {
25+
sys::outjs(['e' => 'Невозможно удалить версию java, пока она используется игровыми серверами.']);
26+
}
27+
28+
$sql->query('DELETE FROM `java_versions` WHERE `id`="' . $id . '" LIMIT 1');
29+
30+
sys::outjs(['s' => 'ok']);

system/acp/sections/java/edit.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018-2025 Solovev Sergei
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
if (!defined('EGP')) {
20+
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
21+
}
22+
23+
$sql->query('SELECT * FROM `java_versions` WHERE `id`="' . $id . '" LIMIT 1');
24+
$javaVersions = $sql->get();
25+
26+
if ($go) {
27+
$aData = [];
28+
29+
$aData['unit'] = isset($_POST['unit']) ? trim($_POST['unit']) : $javaVersions['unit'];
30+
$aData['name'] = isset($_POST['name']) ? trim($_POST['name']) : $javaVersions['name'];
31+
$aData['executable_file'] = isset($_POST['executable_file']) ? trim($_POST['executable_file']) : $javaVersions['executable_file'];
32+
$aData['status'] = $_POST['status'] ?? $javaVersions['status'];
33+
34+
if (in_array('', $aData)) {
35+
sys::outjs(['e' => 'Необходимо заполнить все поля']);
36+
}
37+
38+
$sql->query('UPDATE `java_versions` set '
39+
. '`unit`="' . $aData['unit'] . '",'
40+
. '`name`="' . htmlspecialchars($aData['name']) . '",'
41+
. '`executable_file`="' . $aData['executable_file'] . '",'
42+
. '`status`="' . $aData['status'] . '" WHERE `id`="' . $id . '" LIMIT 1');
43+
44+
sys::outjs(['s' => $id]);
45+
}
46+
47+
foreach ($javaVersions as $i => $val) {
48+
$html->set($i, $val);
49+
}
50+
51+
$unit = '<option value="0">Выберите локацию</option>';
52+
53+
$sql->query('SELECT `id`, `name` FROM `units` ORDER BY `id` ASC');
54+
while ($units = $sql->get()) {
55+
$unit .= '<option value="' . $units['id'] . '">#' . $units['id'] . ' ' . $units['name'] . '</option>';
56+
}
57+
58+
$html->get('edit', 'sections/java');
59+
60+
$html->set('unit', str_replace('"' . $javaVersions['unit'] . '"', '"' . $javaVersions['unit'] . '" selected="select"', $unit));
61+
$html->set('status', $javaVersions['status'] == 1 ? '<option value="1">Доступна</option><option value="0">Недоступна</option>' : '<option value="0">Недоступна</option><option value="1">Доступна</option>');
62+
63+
$html->pack('main');

system/acp/sections/java/index.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2018-2025 Solovev Sergei
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
if (!defined('EGP')) {
20+
exit(header('Refresh: 0; URL=http://' . $_SERVER['HTTP_HOST'] . '/404'));
21+
}
22+
23+
if ($id) {
24+
include(SEC . 'java/edit.php');
25+
} else {
26+
$list = null;
27+
28+
$sql->query('
29+
SELECT jv.`id`, jv.`unit`, jv.`name`, jv.`status`, u.`name` as unit_name
30+
FROM `java_versions` jv
31+
LEFT JOIN `units` u ON jv.`unit` = u.`id`
32+
ORDER BY jv.`id` ASC
33+
');
34+
35+
while ($row = $sql->get()) {
36+
$list .= '<tr>';
37+
$list .= '<td>' . $row['id'] . '</td>';
38+
$list .= '<td><a href="' . $cfg['http'] . 'acp/java/id/' . $row['id'] . '">' . $row['name'] . '</a></td>';
39+
if ($row['unit_name']) {
40+
$list .= '<td>#' . $row['unit'] . ' ' . $row['unit_name'] . '</td>';
41+
} else {
42+
$list .= '<td>Локация отсутствует</td>';
43+
}
44+
$list .= '<td>' . ($row['status'] == '1' ? 'Доступна' : 'Недоступна') . '</td>';
45+
$list .= '<td><a href="#" onclick="return java_delete(\'' . $row['id'] . '\')" class="text-red">Удалить</a></td>';
46+
$list .= '</tr>';
47+
}
48+
49+
$html->get('index', 'sections/java');
50+
51+
$html->set('list', $list);
52+
53+
$html->pack('main');
54+
}

system/data/acpengine.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'letter',
4040
'logs',
4141
'cashback',
42+
'java',
4243
];
4344

4445
// Массив регулярных выражений

system/library/games/mc/action.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public static function start($id, $type = 'start')
2828
{
2929
global $cfg, $sql, $user, $start_point;
3030

31-
$sql->query('SELECT `uid`, `unit`, `tarif`, `game`, `address`, `port`, `slots_start`, `name`, `ram`, `cpu`, `time_start` FROM `servers` WHERE `id`="' . $id . '" LIMIT 1');
31+
$sql->query('SELECT `uid`, `unit`, `tarif`, `game`, `address`, `port`, `slots_start`, `name`, `ram`, `cpu`, `time_start`, `java_version` FROM `servers` WHERE `id`="' . $id . '" LIMIT 1');
3232
$server = $sql->get();
3333

3434
$sql->query('SELECT `install` FROM `tarifs` WHERE `id`="' . $server['tarif'] . '" LIMIT 1');
@@ -68,8 +68,19 @@ public static function start($id, $type = 'start')
6868

6969
unlink($temp);
7070

71+
$java = 'java';
72+
73+
if ($server['java_version'] != 0) {
74+
$sql->query('SELECT `executable_file` FROM `java_versions` WHERE `id`="' . $server['java_version'] . '" LIMIT 1');
75+
$javaVersion = $sql->get();
76+
77+
if ($javaVersion) {
78+
$java = $javaVersion['executable_file'];
79+
}
80+
}
81+
7182
// Параметры запуска
72-
$bash = 'java -Xmx' . $server['ram'] . 'M -Xms' . $server['ram'] . 'M -jar start.jar nogui';
83+
$bash = $java . ' -Xms' . $server['ram'] . 'M -Xmx' . $server['ram'] . 'M -jar start.jar nogui';
7384

7485
// Временный файл
7586
$temp = sys::temp($bash);
@@ -83,7 +94,7 @@ public static function start($id, $type = 'start')
8394
. 'sudo -u server' . $server['uid'] . ' mkdir -p oldstart;' // Создание папки логов
8495
. 'cat console.log >> oldstart/' . date('d.m.Y_H:i:s', $server['time_start']) . '.log; rm console.log; rm oldstart/01.01.1970_03:00:00.log;' // Перемещение лога предыдущего запуска
8596
. 'chown server' . $server['uid'] . ':servers server.properties start.sh;' // Обновление владельца файлов
86-
. 'sudo systemd-run --unit=server' . $server['uid'] . ' --scope -p CPUQuota=' . $server['cpu'] . '% -p MemoryMax=' . $server['ram'] . 'M sudo -u server' . $server['uid'] . ' tmux new-session -ds s_' . $server['uid'] . ' sh -c "./start.sh"'); // Запуск игровго сервера
97+
. 'sudo systemd-run --unit=server' . $server['uid'] . ' --scope -p CPUQuota=' . $server['cpu'] . '% -p MemoryMax=' . $server['ram'] + '512' . 'M sudo -u server' . $server['uid'] . ' tmux new-session -ds s_' . $server['uid'] . ' sh -c "./start.sh"'); // Запуск игровго сервера
8798

8899
// Обновление информации в базе
89100
$sql->query('UPDATE `servers` set `status`="' . $type . '", `online`="0", `players`="", `time_start`="' . $start_point . '", `stop`="1" WHERE `id`="' . $id . '" LIMIT 1');

system/sections/servers/mc/settings/start.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
$html->nav('Параметры запуска');
2424

25-
$sql->query('SELECT `uid`, `slots`, `slots_start`, `autorestart` FROM `servers` WHERE `id`="' . $id . '" LIMIT 1');
25+
$sql->query('SELECT `uid`, `unit`, `slots`, `slots_start`, `java_version` FROM `servers` WHERE `id`="' . $id . '" LIMIT 1');
2626
$server = array_merge($server, $sql->get());
2727

2828
include(LIB . 'games/games.php');
@@ -40,6 +40,13 @@
4040
$sql->query('UPDATE `servers` set `slots_start`="' . $slots . '" WHERE `id`="' . $id . '" LIMIT 1');
4141
}
4242

43+
$mcache->delete('server_settings_' . $id);
44+
sys::outjs(['s' => 'ok'], $nmch);
45+
case 'java_version':
46+
if ($value != $server['java_version']) {
47+
$sql->query('UPDATE `servers` set `java_version`="' . $value . '" WHERE `id`="' . $id . '" LIMIT 1');
48+
}
49+
4350
$mcache->delete('server_settings_' . $id);
4451
sys::outjs(['s' => 'ok'], $nmch);
4552
}
@@ -52,13 +59,20 @@
5259
$slots .= '<option value="' . $slot . '">' . $slot . ' шт.</option>';
5360
}
5461

55-
// Авторестарт при зависании
56-
$autorestart = $server['autorestart'] ? '<option value="1">Включен</option><option value="0">Выключен</option>' : '<option value="0">Выключен</option><option value="1">Включен</option>';
62+
$javaVersion = '<option value="0">Native</option>';
63+
64+
$sql->query('SELECT `id`, `unit`, `name`, `status` FROM `java_versions` ORDER BY `id` ASC');
65+
66+
while ($javaVersions = $sql->get()) {
67+
if ($javaVersions['unit'] == $server['unit'] && $javaVersions['status'] == true) {
68+
$javaVersion .= '<option value="' . $javaVersions['id'] . '">' . $javaVersions['name'] . '</option>';
69+
}
70+
}
5771

5872
$html->get('start', 'sections/servers/' . $server['game'] . '/settings');
5973

6074
$html->set('id', $id);
61-
$html->set('autorestart', $autorestart);
6275
$html->set('slots', str_replace('"' . $server['slots_start'] . '"', '"' . $server['slots_start'] . '" selected="select"', $slots));
76+
$html->set('java_version', str_replace('"' . $server['java_version'] . '"', '"' . $server['java_version'] . '" selected="select"', $javaVersion));
6377

6478
$html->pack('start');

template/acp/all.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ <h5>Основное меню</h5>
104104
тарифами</a></li>
105105
<li><a href="[acp]addons" |p_addons|class="active" |_p_addons|><i class="fa fa-cubes"></i> Управление
106106
дополнениями</a></li>
107+
<li><a href="[acp]java" |p_java|class="active" |_p_java|><i class="fa-brands fa-java"></i> Управление
108+
версиями java</a></li>
107109
</ul>
108110

109111
<div class="hr-gray"></div>

0 commit comments

Comments
 (0)