hcgcloud / pterodactyl-sdk

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

Fatal error #1

Closed christian1432 closed 5 years ago

christian1432 commented 5 years ago

Hello, when I use the sdk I get the following issue:

Fatal error: Uncaught Error: Call to undefined function HCGCloud\Pterodactyl\array_add() in /var/www/XXXX/XXXXXX.de/XX.XXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php:89 Stack trace: #0 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php(21): HCGCloud\Pterodactyl\Pterodactyl->request('GET', 'api/application...') #1 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/Actions/ManagesUsers.php(18): HCGCloud\Pterodactyl\Pterodactyl->get('api/application...') #2 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/test.php(4): HCGCloud\Pterodactyl\Pterodactyl->users() #3 {main} thrown in /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php on line 89

Can you help?

tyson239 commented 5 years ago

Could you please provide the code that cause this error?

tyson239 commented 5 years ago

I've check the code, it seems that I forgot to add a package whch provides array_add function to composer.json. Please check if your project have illuminate/support installed. If not, run composer require illuminate/support. I will fix this issue later, thank you for your feedback. If there's still have problems, feel free to reply.

christian1432 commented 5 years ago

Hello, get users and servers are perfect.

CreateUser and CreateServer are the following issues:

Fatal error: Uncaught HCGCloud\Pterodactyl\Exceptions\ValidationException: The given data failed to pass validation. in /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php:110 Stack trace: #0 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php(95): HCGCloud\Pterodactyl\Pterodactyl->handleRequestError(Object(GuzzleHttp\Psr7\Response)) #1 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php(33): HCGCloud\Pterodactyl\Pterodactyl->request('POST', 'api/application...', Array) #2 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/Actions/ManagesUsers.php(52): HCGCloud\Pterodactyl\Pterodactyl->post('api/application...', Array) #3 /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/test.php(5): HCGCloud\Pterodactyl\Pterodactyl->createUser(Array) #4 {main} thrown in /var/www/vhosts/XXXXXX.de/test.XXXXXX.de/vendor/hcgcloud/pterodactyl-sdk/src/MakesHttpRequests.php on line 110

christian1432 commented 5 years ago

I used this code:

$server = $pterodactyl->createServer([ "external_id" => "4", "name" => "APITest", "user" => 1, "egg" => 15, "pack" => 0, "docker_image" => "hub.tencentyun.com/unihc/pterodactyl_images:vcmp", "environment" => [ //Not confirmed [ "server_id" => "", "variable_id" => "", "variable_value" => "" ] ], "skip_scripts" => false, "limits" => [ "memory" => 64, "swap" => 0, "disk" => 64, "io" => 500, "cpu" => 0 ], "feature_limits" => [ "databases" => 0, "allocations" => 0 ], "startup" => "./mpsvrrel64 -port {{SERVER_PORT}}", "description" => "test description", "node_id" => 1, "nest_id" => 5, "allocation" => [ "default" => "16", "additional" => [ "17", "18" ] ] ]);

and

$user = $pterodactyl->createUser([ "external_id" => "2", "email" => 'test@test.com', "username" => 'TestUser', "first_name" => 'Test', "last_name" => 'User', "language" => 'zh-cn', "password" => '123456' ]);

tyson239 commented 5 years ago

Make sure you have changed the example code correctly, and some parameters are optional. You can find out example from this unofficial document. https://deploys.io/docs/api/pterodactyl/v1/#create-user You can just try this to create a user:

$user = $pterodactyl->createUser([
"email" => 'test@test.com',
"username" => 'TestUser',
"first_name" => 'Test',
"last_name" => 'User',
"password" => '123456'
]);
tyson239 commented 5 years ago

For create a server, you should also replace those parameters to suit your panel, like 'user', 'egg', 'node_id', 'nest_id'. These id can be found in your panel.

christian1432 commented 5 years ago

Create Users are fine but when I create a server the error came again.

tyson239 commented 5 years ago

what parameters have you changed?

christian1432 commented 5 years ago

I have the following command:

$server = $pterodactyl->createServer([ "name" => "APITest", "user" => 3, "nest_id" => 2, "node_id" => 1, "egg" => 7, "limits" => [ "memory" => 64, "swap" => 0, "disk" => 64, "io" => 500, "cpu" => 0 ], "feature_limits" => [ "databases" => 0, "allocations" => 0 ] ]);

tyson239 commented 5 years ago

"allocation" => [ "default" => "16", "additional" => [ "17", "18" ]

should be also provided, which is your node allocations. ID seems could not be got in frontend, you can check it in database or use API.

christian1432 commented 5 years ago

Hello, can you send me an example which all parameters to create an minecraft server? Thank you :)

tyson239 commented 5 years ago

@christian1432 you should replace those ids in sample code to yours. It's depend on your own panel. We have developed a internal version of the sdk to do these stuff conveniently, and will be release soon.

christian1432 commented 5 years ago

Hello, do you know which date it will be release

FrancoBM12 commented 5 years ago

hey

FrancoBM12 commented 5 years ago

I need help, I get an error when creating a server. This is the code I use:

$ server = $ pterodactyl-> createServer ([      "external_id" => "4",      "name" => "APITest",      "user" => 1,      "egg" => 3,      "pack" => 0,      "docker_image" => "quay.io/pterodactyl/core:java-glibc",      "environment" => [          [              "server_id" => "",              "variable_id" => "",              "variable_value" => ""          ]      ],      "skip_scripts" => false,      "limits" => [          "memory" => 64,          "swap" => 0,          "disk" => 64,          "io" => 500,          "cpu" => 0      ],      "feature_limits" => [          "databases" => 0,          "allocations" => 0      ],      "startup" => "java -Xms128M -Xmx {{SERVER_MEMORY}} M -jar {{SERVER_JARFILE}}",      "description" => "test description",      "deploy" => [          "locations" => [1],          "dedicated_ip" => false,          "port_range" => []      ],      "start_on_completion" => true ]);

tyson239 commented 5 years ago

@xFrancoBM try this minfied one, which is used in our production. the $pack would be an array with validate rules below:

$rule = [
    'egg' => 'require|number',
    'nest' => 'require|number',
    'databases' => 'require|number',
    'allocations' => 'require|number',
    'memory' => 'require|number',
    'swap' => 'require|number',
    'disk' => 'require|number',
    'cpu' => 'require|number',
    'io' => 'require|number'
];

Then use the $pack to get the egg info.

$egg = $pterodactyl->egg($pack['nest'], $pack['egg']);

and use the egg info in the createServer.

$server = $pterodactyl->createServer([
    "external_id" => $external_id,
    "name" => $svr_name,
    "user" => $user['id'],
    "egg" => $pack['egg'],
    "pack" => 0,
    "docker_image" => $egg->dockerImage,
    "skip_scripts" => false,
    "environment" => [],
    "limits" => [
        "memory" => $pack['memory'],
        "swap" => $pack['swap'],
        "disk" => $pack['disk'],
        "io" => $pack['io'],
        "cpu" => $pack['cpu']
    ],
    "feature_limits" => [
        "databases" => $pack['databases'],
        "allocations" => $pack['allocations']
    ],
    "startup" => $egg->startup,
    "description" => "-",
    "deploy" => [
        "locations" => [$node_id],
        "dedicated_ip" => false,
        "port_range" => []
    ],
    "start_on_completion" => true
]);
tyson239 commented 5 years ago

@christian1432 I am sorry that I saw your reply just now. Just like this sdk, the new version we are working on is also not yet integrated. We plan to consider releasing after everything has been completed.

FrancoBM12 commented 5 years ago

Well, I didn't quite get it.

FrancoBM12 commented 5 years ago

Can you help me, please?

tyson239 commented 5 years ago

Could you provide the error message you encountered?

FrancoBM12 commented 5 years ago

That's the mistake that comes to me. https://cdn.discordapp.com/attachments/122900397965705216/597208684841533441/unknown.png

tyson239 commented 5 years ago

Are you using Spigot egg? Try to set the environment variables:

     "environment" => [
        "SERVER_JARFILE" => "server.jar",
        "DL_VERSION" => "latest",
        "DL_PATH" => ""
     ]
FrancoBM12 commented 5 years ago

So to this: I'll add the code you passed me?


     "external_id" => "4",
     "name" => "APITest",
     "user" => 1,
     "egg" => 3,
     "pack" => 0,
     "docker_image" => "quay.io/pterodactyl/core:java-glibc",
     "environment" => [
        "SERVER_JARFILE" => "server.jar",
        "DL_VERSION" => "latest",
        "DL_PATH" => ""
     ],
     "skip_scripts" => false,
     "limits" => [
         "memory" => 64,
         "swap" => 0,
         "disk" => 64,
         "io" => 500,
         "cpu" => 0
     ],
     "feature_limits" => [
         "databases" => 0,
         "allocations" => 0
     ],
     "startup" => "java -Xms128M -Xmx {{SERVER_MEMORY}} M -jar {{SERVER_JARFILE}}",
     "description" => "test description",
     "deploy" => [
         "locations" => [1],
         "dedicated_ip" => false,
         "port_range" => []
     ],
     "start_on_completion" => true
]); 
tyson239 commented 5 years ago
$server = $pterodactyl-> createServer([
    "external_id" => "4",
    "name" => "APITest",
    "user" => 1,
    "egg" => 3,
    "pack" => 0,
    "docker_image" => "quay.io/pterodactyl/core:java-glibc",
    "environment" => [
        "SERVER_JARFILE" => "server.jar",
        "DL_VERSION" => "latest",
        "DL_PATH" => ""
    ],
    "skip_scripts" => false,
    "limits" => [
        "memory" => 64,
        "swap" => 0,
        "disk" => 64,
        "io" => 500,
        "cpu" => 0
    ],
    "feature_limits" => [
        "databases" => 0,
        "allocations" => 0
    ],
    "startup" => "java -Xms128M -Xmx {{SERVER_MEMORY}} M -jar {{SERVER_JARFILE}}",
    "description" => "test description",
    "deploy" => [
        "locations" => [1],
        "dedicated_ip" => false,
        "port_range" => []
    ],
    "start_on_completion" => true
]);
FrancoBM12 commented 5 years ago

This page doesn't work, that comes out

FrancoBM12 commented 5 years ago

Where's the nest going?

tyson239 commented 5 years ago

The nest id of your eggs, check admin/nests. image

FrancoBM12 commented 5 years ago

I mean the api, where do I put the id of the nest?

tyson239 commented 5 years ago

It is not necessary, unless you use the $pterodactyl->egg(); to reuse some variables to create server.

FrancoBM12 commented 5 years ago

So, why do not you let me create a server?

tyson239 commented 5 years ago

try this one, tested just now for Spigot eggs.

$egg = $pterodactyl->egg(1, 3);
$server = $pterodactyl->createServer([
    "name" => "test",
    "user" => 1,
    "egg" => 3,
    "pack" => 0,
    "docker_image" => $egg->dockerImage,
    "skip_scripts" => false,
    "environment" => [
        "SERVER_JARFILE" => "server.jar",
        "DL_VERSION" => "latest",
        "DL_PATH" => ""
    ],
    "limits" => [
        "memory" => 2048,
        "swap" => 0,
        "disk" => 2048,
        "io" => 100,
        "cpu" => 0
    ],
    "feature_limits" => [
        "databases" => 0,
        "allocations" => 0
    ],
    "startup" => $egg->startup,
    "description" => "",
    "deploy" => [
        "locations" => [1],
        "dedicated_ip" => false,
        "port_range" => []
    ],
    "start_on_completion" => true
]);
FrancoBM12 commented 5 years ago

now he just tells me, "the page does not respond"

tyson239 commented 5 years ago

try $pterodactyl->servers(); And see if it can return servers correctly. I don't think it's a problem about the createServer function. Whether it succeeds or not, it should return some data, the server infomation just created, or The given data failed to pass validation. Also try to check the log of your panel to see if the request has received by the panel.

FrancoBM12 commented 5 years ago

the page is blank when you put $ pterodactyl-> servers (); means that if you received the data, and according to the api records when I put the $ server = $ pterodactyl-> createServer also receives it but the page says "this page does not work" so what happens? image

FrancoBM12 commented 5 years ago

that is the code that I am using

tyson239 commented 5 years ago

print_r($pterodactyl->servers());

also try to use

try{
    $pterodactyl = new \HCGCloud\Pterodactyl\Pterodactyl(config('panel.app_key'), config('panel.url'));
    $egg = $pterodactyl->egg($pack['nest'], $pack['egg']);
    $server = $pterodactyl->createServer([
        ....
    ]);
    print_r($server);
}catch(\Exception $e){
    echo $e->getMessage();
}
tyson239 commented 5 years ago

Remember to delete the above image or change your API_KEY as soon as possible. That image contains your API_KEY.

FrancoBM12 commented 5 years ago

I know, look at me saying the same thing "This page does not work privatenodes.ml can not process this request at this time."

tyson239 commented 5 years ago

or just try to get server list first to seems if it's still can't process the request?

try{
    $pterodactyl = new \HCGCloud\Pterodactyl\Pterodactyl('LfCA1xH9K9Gnc5VUh9ZV8xwQun2odBY7zGEStvbRLMbf3Htu', 'http://panel.privatenodes.ml/');
    $servers = $pterodactyl->servers();
    print_r($servers);
}catch(\Exception $e){
    echo $e->getMessage();
}

I have just tried it, and it will return:

{
    "errors": [
        {
            "code": "AccessDeniedHttpException",
            "status": "403",
            "detail": "An error was encountered while processing this request."
        }
    ]
}
tyson239 commented 5 years ago

can I use it to try to create a server?

FrancoBM12 commented 5 years ago

yes

tyson239 commented 5 years ago

I can get this message The given data failed to pass validation.

FrancoBM12 commented 5 years ago

and because?

FrancoBM12 commented 5 years ago

Location id: 1, Node id: 7

tyson239 commented 5 years ago

try to replace environment to the variables or your eggs, I can't test it properly as I can't login to your panel directly. also you can read this document, https://deploys.io/docs/api/pterodactyl/v1/#create-server

FrancoBM12 commented 5 years ago

http://35.199.167.18/ test@panel.com test123 Admin Panel Api: "KkFo2mtWJKKR6mccWKGeUnVhR1Ruk9zeEQzi0oOjpzmvlb0H"

tyson239 commented 5 years ago

clearly works, just set the environment properly.

try{
    $pterodactyl = new \HCGCloud\Pterodactyl\Pterodactyl('KkFo2mtWJKKR6mccWKGeUnVhR1Ruk9zeEQzi0oOjpzmvlb0H', 'http://35.199.167.18');
    $egg = $pterodactyl->egg(1, 4);
    $server = $pterodactyl->createServer([
        "name" => "test",
        "user" => 1,
        "egg" => 4,
        "docker_image" => $egg->dockerImage,
        "skip_scripts" => false,
        "environment" => [
            "SERVER_JARFILE" => "server.jar",
            "SPONGE_VERSION" => "1.11.2-6.1.0-BETA-21"
        ],
        "limits" => [
            "memory" => 256,
            "swap" => 0,
            "disk" => 512,
            "io" => 500,
            "cpu" => 0
        ],
        "feature_limits" => [
            "databases" => 0,
            "allocations" => 0
        ],
        "startup" => $egg->startup,
        "description" => "",
        "deploy" => [
            "locations" => [2],
            "dedicated_ip" => false,
            "port_range" => []
        ],
        "start_on_completion" => true
    ]);
    print_r($server);
}catch(\Exception $e){
    echo $e->getMessage();
}
FrancoBM12 commented 5 years ago

I do not know what happens, but it does not work for me

image

FrancoBM12 commented 5 years ago

keeps coming "this page does not work"

tyson239 commented 5 years ago

Have you enabled error reporting of your PHP? Try putting this code at the top of your file.

error_reporting(1);

just like

<?php
    error_reporting(1);
    ....
?>