fruitbytes/pterodactyl-sdk

Pterodactyl PHP SDK(非官方版)

dev-master 2018-05-17 23:41 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:41:56 UTC


README

Latest Version on Packagist Total Downloads Software License

要在您的项目中安装SDK,您需要通过 composer 引入此包

composer require fruitbytes/pterodactyl-sdk

然后使用Composer的自动加载功能

require __DIR__.'/../vendor/autoload.php';

最后创建SDK的一个实例

$pterodactyl = new \Fruitbytes\Pterodactyl\Pterodactyl(PUBLIC_KEY_HERE, SECRET_KEY_HERE, BASE_URI_HERE);

用法

使用Pterodactyl实例,您可以执行多种操作,以及获取Pterodactyl API提供的不同资源

$servers = $pterodactyl->servers();

这将为您提供一个数组,包含您可访问的服务器,每个服务器由一个 Fruitbytes\Pterodactyl\Resources\Server 的实例表示,这个实例有多个公共属性,如 $name$id$owner$memory 等。

您也可以使用以下方式检索单个服务器:

$server = $pterodactyl->server(SERVER_ID_HERE);

在此SDK支持的多项操作中,您可能需要传递一些参数,例如在创建新服务器时

$server = $pterodactyl->createServer([
    "name"=>"API Test",
    "description"=>"API Description",
    "user_id"=>1,
    "location_id"=>1,
    "auto_deploy"=>true,
    "memory"=>64,
    "swap"=>0,
    "disk"=>1024,
    "cpu"=>0,
    "io"=>500,
    "service_id"=>1,
    "option_id"=>1,
    "startup"=>"java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}",
    "env_SERVER_JARFILE"=>"server.jar",
    "env_VANILLA_VERSION"=>"latest"
]);

这些参数将用于发送到Pterodactyl服务器的POST请求中,您可以在 Pterodactyl官方API文档 中找到每个操作所需参数的更多信息。

请注意,例如,此请求将仅启动服务器创建过程,您的服务器可能需要几分钟才能完成配置,您需要检查服务器的 $installed 属性以确定它是否已准备好或尚未准备好。

用户管理

$pterodactyl->users();
$pterodactyl->user($userId);
$pterodactyl->createUser(array $data);
$pterodactyl->deleteUser($userId);

在用户实例上,您还可以调用

$user->delete();

服务器管理

$pterodactyl->servers();
$pterodactyl->server($serverId);
$pterodactyl->createServer(array $data);
$pterodactyl->deleteServer($serverId);

// Server access
$pterodactyl->suspendServer($serverId);
$pterodactyl->unsuspendServer($serverId);

在服务器实例上,您还可以调用

$server->delete();
$server->suspend();
$server->unsuspend();

使用服务器

$pterodactyl->powerServer($serverUuid, $action); // 'start', 'stop', 'restart', 'kill'
$pterodactyl->commandServer($serverUuid, $command);

在服务器实例上,您还可以调用

$server->power($action); // 'start', 'stop', 'restart', 'kill'
$server->command($command);

许可证

fruitbytes/pterodactyl-sdk 在MIT许可证(MIT)下授权。有关更多信息,请参阅 许可证文件