hcgcloud / pterodactyl-sdk

Pterodactyl Panel PHP SDK/API wrapper
https://hcgcloud.github.io/pterodactyl-sdk-docs/
MIT License
27 stars 25 forks source link

Server create #7

Closed DAThosting closed 4 years ago

DAThosting commented 4 years ago

Hi,

nice work. I played around with your sdk and can't create servers. Uncaught HCGCloud\Pterodactyl\Exceptions\ValidationException: The given data failed to pass validation. in /var/www/testsite/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php:110

My testfile is the following:

require_once("vendor/autoload.php"); 
$pterodactyl = new \HCGCloud\Pterodactyl\Pterodactyl('xLm12Vhbroswc0CODE2Ds0oLrzrfAtODQoVaqWqYBWOcKDReotFv', 'http://127.0.0.1/');
$nest_id = 1;
$egg_id = 5;
$location_id = 1;
$egg = $pterodactyl->egg($nest_id, $egg_id); //get docker_image and startup directly from egg
$server = $pterodactyl->createServer([
    "external_id" => 11,
    "name" => "test",
    "user" => 1,
    "egg" => $egg_id,
    "pack" => 0,
    "docker_image" => $egg->dockerImage,
    "skip_scripts" => false,
    "environment" => [],
    "limits" => [
        "memory" => 2048,
        "swap" => 0,
        "disk" => 20000,
        "io" => 0,
        "cpu" => 100
    ],
    "feature_limits" => [
        "databases" => 0,
        "allocations" => 0
    ],
    "startup" => $egg->startup,
    "description" => "",
    "deploy" => [
        "locations" => [$location_id],
        "dedicated_ip" => false,
        "port_range" => []
    ],
    "start_on_completion" => true
]);
print_r($server);

My node is on 0.6.12. I am able to create servers right in the panel.

Also I'm playing with your newly created node support, there also I got the same errors.

tyson239 commented 4 years ago

Hi, have you replaced nest_id, egg_id, location_id to your panel's id?

tyson239 commented 4 years ago

Also the environment variables of the eggs should be set too.

DAThosting commented 4 years ago

Yes the id's are the same on my testpanel. Your example is based on a standard fresh installed panel I guess. Cause all IDs are the same.

tyson239 commented 4 years ago

try to use the following code:

try {
    $servers = $pterodactyl->createServer([
        //...
    ]);
}catch(\Exception $e){
    print_r($e->errors());
}

then you can find which parameter failed to pass the validation.

tyson239 commented 4 years ago

my test panel is not fresh installed, the ids for me is Vanilla Minecraft eggs. however it have two environment variables SERVER_JARFILE, VANILLA_VERSION, you should also pass them in your data array, though they have default value:

"environment" => [
    "SERVER_JARFILE" => "server.jar",
    "VANILLA_VERSION" => "latest"
]

I will improve the example code later.

DAThosting commented 4 years ago

Got it... externalID have to be a string... Also IO has set between 10 and 1000.

I get node creation running, but need the keys hash from the configuration file. Searching on the official documentation, I can't find a way to get them. Need them to directly add a node and write the key in core.json

tyson239 commented 4 years ago

what's the mean of key hash?

DAThosting commented 4 years ago

If you add a node successfully, then you have to run ether the auto-deployment or use the given config for core.json. In this config right at the bottom there is a "keys". How I get this via API? Or how it is created.

tyson239 commented 4 years ago

you mean the auto deploy of a server? I think it is unnecessary to get the keys of a daemon, it's just for the communication between panel and daemon, also you should not be able get this via api.

tyson239 commented 4 years ago

if you mean editing this: image you can check https://dashflo.net/docs/api/pterodactyl/v1/#edit-node, as our documentation about node is not finished yet. It's called public in api. image

DAThosting commented 4 years ago

Short automatic procedure:

  1. creating dedicated server via a api from my hoster
  2. installing the os and pterodactyl daemon
  3. creating node via your api

Now I have to link the panel with my node. The only missing thing is this key to get it run without problems.

tyson239 commented 4 years ago

I think the api can't do this, you need to install it manually.

DAThosting commented 4 years ago

Hm, I'll create a issue at pterodactyl directly.

Thank you anyway. Works perfect with your sdk!

tyson239 commented 4 years ago

I checked the panel routes just now, it seems that only this route can get the token: https://github.com/pterodactyl/panel/blob/39f1392eee10d3256c793dba1ec9e2b5f3daefdf/routes/admin.php#L154

Requested when the clicking Generate Token from the admin control of the panel. image

DAThosting commented 4 years ago

https://github.com/pterodactyl/panel/issues/1632

Same feature request already asked :D

MrFallen commented 4 years ago

Hello! I want create TF2 server. Whats wrong? image