Skip to content

Commit

Permalink
Added support for WISP-PANEL & setting server status array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksandar Ovcharov committed Mar 11, 2024
1 parent 1708e1b commit 03eb033
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pterosync.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,11 @@ function pterosync_CreateAccount(array $params)

$userResult = pteroSyncApplicationApi($params, 'users/external/' . $params['clientsdetails']['id']);
if ($userResult['status_code'] === 404) {
$userResult = pteroSyncApplicationApi($params, 'users?filter[email]=' . urlencode($params['clientsdetails']['email']));
if (PteroSyncSettings::get()->game_panel == 'wisp') {
$userResult = pteroSyncApplicationApi($params, 'users?search=' . urlencode($params['clientsdetails']['email']));
} elseif (PteroSyncSettings::get()->game_panel == 'pterodactyl') {
$userResult = pteroSyncApplicationApi($params, 'users?filter[email]=' . urlencode($params['clientsdetails']['email']));
}
if ($userResult['meta']['pagination']['total'] === 0) {
$userResult = pteroSyncApplicationApi($params, 'users', [
'username' => pteroSyncGetOption($params, 'username', pteroSyncGenerateUsername()),
Expand All @@ -395,12 +399,12 @@ function pterosync_CreateAccount(array $params)
], 'POST');
} else {
foreach ($userResult['data'] as $key => $value) {
if ($value['attributes']['email'] === $params['clientsdetails']['email']) {
$userResult = array_merge($userResult, $value);
if ($value['attributes']['email'] == $params['clientsdetails']['email']) {
$userResult = $value;
$userResult['status_code'] = 200;
break;
}
}
$userResult = array_merge($userResult, $userResult['data'][0]);
}
}

Expand Down Expand Up @@ -811,7 +815,7 @@ function pterosync_LoginLink(array $params)

$hostname = pteroSyncGetHostname($params);
$button1 = '<a class="btn btn-info text-uppercase"
href="' . $hostname . '/server/' . $server['uuid'] . '" target="_blank">
href="' . $hostname . '/server/' . $server['identifier'] . '" target="_blank">
<i class="fas fa-eye fa-fw"></i>
View Server
</a>';
Expand Down Expand Up @@ -861,13 +865,16 @@ function pterosync_ClientArea(array $params)
$isAdmin = $_SESSION['adminid'] ?? 0;
$hostname = pteroSyncGetHostname($params);
$serverId = $params['customfields']['UUID (Server ID)'];
$serverData = pteroSyncGetServerID($params, true, 'user,node');
$serverData = pteroSyncGetServerID($params, true, 'user,node,allocations,nest');
if (!$serverData) return [
'templatefile' => 'clientarea',
'vars' => [
'serverFound' => false
],
];

[$game, $address, $port] = pteroSyncGenerateServerStatusArray($serverData);

$endpoint = 'servers/' . $serverData['identifier'] . '/resources';
$serverState = pteroSyncClientApi($params, $endpoint);

Expand All @@ -881,6 +888,7 @@ function pterosync_ClientArea(array $params)
'startServer' => 'pteroSyncStartServer',
'restartServer' => 'pteroSyncRestartServer',
'stopServer' => 'pteroSyncStopServer',
'killServer' => 'pteroSyncKillServer',
'getState', 'getFtpDetails' => 'pteroSyncServerState',
default => false,
};
Expand All @@ -902,6 +910,7 @@ function pterosync_ClientArea(array $params)
'startUrl' => $actionUrl . '&modop=custom&a=startServer',
'rebootUrl' => $actionUrl . '&modop=custom&a=restartServer',
'stopUrl' => $actionUrl . '&modop=custom&a=stopServer',
'killUrl' => $actionUrl . '&modop=custom&a=killServer',
'serverIp' => $params['domain'],
'serverId' => $serverId,
'ftpDetails' => [
Expand All @@ -910,7 +919,12 @@ function pterosync_ClientArea(array $params)
],
'serverFound' => true,
'serviceId' => $params['serviceid'],
'isAdmin' => $isAdmin
'isAdmin' => $isAdmin,
'gameQueryData' => [
'game' => $game,
'address' => $address,
'port' => $port,
]
],
];
} catch (Exception $err) {
Expand Down

0 comments on commit 03eb033

Please sign in to comment.