forked from Alex/Pterodactyl-Panel
Simplify logic in websocket control
This commit is contained in:
parent
bb559422dc
commit
6c61577699
@ -3,12 +3,11 @@
|
||||
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Http\Response;
|
||||
use Pterodactyl\Models\Server;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Permission;
|
||||
use Pterodactyl\Services\Nodes\NodeJWTService;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
use Pterodactyl\Services\Servers\GetUserPermissionsService;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
@ -55,26 +54,22 @@ class WebsocketController extends ClientApiController
|
||||
{
|
||||
$user = $request->user();
|
||||
if ($user->cannot(Permission::ACTION_WEBSOCKET_CONNECT, $server)) {
|
||||
throw new HttpException(Response::HTTP_FORBIDDEN, 'You do not have permission to connect to this server\'s websocket.');
|
||||
throw new HttpForbiddenException('You do not have permission to connect to this server\'s websocket.');
|
||||
}
|
||||
|
||||
$permissions = $this->permissionsService->handle($server, $user);
|
||||
|
||||
$node = null;
|
||||
$node = $server->node;
|
||||
if (! is_null($server->transfer)) {
|
||||
// Check if the user has permissions to receive transfer logs.
|
||||
if (! in_array('admin.websocket.transfer', $permissions)) {
|
||||
throw new HttpException(Response::HTTP_FORBIDDEN, 'You do not have permission to view transfer logs');
|
||||
throw new HttpForbiddenException('You do not have permission to view server transfer logs.');
|
||||
}
|
||||
|
||||
// Redirect the websocket request to the new node if the server has been archived.
|
||||
if ($server->transfer->archived) {
|
||||
$node = $server->transfer->newNode;
|
||||
} else {
|
||||
$node = $server->node;
|
||||
}
|
||||
} else {
|
||||
$node = $server->node;
|
||||
}
|
||||
|
||||
$token = $this->jwtService
|
||||
|
Loading…
Reference in New Issue
Block a user