knik/gameap-daemon-client

GameAP Daemon PHP Client

0.6.6 2023-05-04 16:09 UTC

This package is auto-updated.

Last update: 2024-04-04 18:51:29 UTC


README

Build Status Scrutinizer Code Quality Coverage Status

Installation

composer require knik/gameap-daemon-client

Usage

Commands

Connect to server

$gdaemonCommands = new GdaemonCommands([
    'host' => 'localhost',
    'port' => 31717,
    'serverCertificate' => '/path/to/server.crt',
    'localCertificate' => '/path/to/client.crt',
    'privateKey' => '/path/to/client.key.pem',
    'privateKeyPass' => '1234',
    'timeout' => 10,
    'workDir' => '/home/user',
]);

$gdaemonCommands->connect();

Execute command

$result = $gdaemonCommands->exec('echo HELLO');
var_dump($result); // string(5) "HELLO"

Exit code:

$result = $gdaemonCommands->exec('echo HELLO', $exitCode);
var_dump($result); // string(5) "HELLO"
var_dump($exitCode); // int(0)

Files

Connect to server

$gdaemonFiles = new GdaemonFiles([
    'host' => 'localhost',
    'port' => 31717,
    'serverCertificate' => '/path/to/server.crt',
    'localCertificate' => '/path/to/client.crt',
    'privateKey' => '/path/to/client.key.pem',
    'privateKeyPass' => '1234',
    'timeout' => 10,
]);

$gdaemonFiles->connect();

Listing directory

Detail info about files
$result = $gdaemonFiles->directoryContents('/path/to/dir');

print_r($result);
/*
Array
(
    [0] => Array
       (
           [name] => directory
           [size] => 0
           [mtime] => 1542013640
           [type] => dir
           [permissions] => 0755
       )

    [1] => Array
       (
           [name] => file.txt
           [size] => 15654
           [mtime] => 1542013150
           [type] => file
           [permissions] => 0644
       )

)

*/
File names only
$result = $gdaemonFiles->listFiles('/path/to/dir');

print_r($result);
Array
(
    [0] => directory
    [1] => file.txt
)

Create directory

$gdaemonFiles->mkdir('/path/to/new_dir');

Remove

$gdaemonFiles->delete('/path/to/file.txt');

To remove a directory that contains other files or directories:

$gdaemonFiles->delete('/path/to/file.txt', true);

Rename

Rename or move files/directories

$gdaemonFiles->rename('/path/to/file.txt', '/path/to/new_name.txt');

Copy

$gdaemonFiles->copy('/path/to/file.txt', '/path/to/new_file.txt');

Change permission

$gdaemonFiles->chmod(0755, '/path/to/file.txt');

Exist checking

$gdaemonFiles->exist('/path/to/file.txt');

Metadata

$result = $gdaemonFiles->directoryContents('/path/to/file.txt');

print_r($result);
/*
Array
(
    [name] => file.txt
    [size] => 43
    [type] => file
    [mtime] => 1541971363
    [atime] => 1541971363
    [ctime] => 1541971363
    [permissions] => 0644
    [mimetype] => text/plain
)
*/

Download file from server

$gdaemonFiles->get('/remote/path/to/file.txt', '/local/path/to/file.txt');

File handle:

$fileHandle = fopen('php://temp', 'w+b');
$gdaemonFiles->get('/remote/path/to/file.txt', $fileHandle);

Upload file

$gdaemonFiles->put('/local/path/to/file.txt', '/remote/path/to/file.txt');

File handle:

$fileHandle = fopen('/local/path/to/file.txt', 'r');
$gdaemonFiles->put($fileHandle, '/remote/path/to/file.txt');

Status

Connect to server

$gdaemonStatus = new GdaemonStatus([
    'host' => 'localhost',
    'port' => 31717,
    'serverCertificate' => '/path/to/server.crt',
    'localCertificate' => '/path/to/client.crt',
    'privateKey' => '/path/to/client.key.pem',
    'privateKeyPass' => '1234',
    'timeout' => 10,
]);

$gdaemonStatus->connect();

GameAP Daemon Version

Get GameAP Daemon version and compilation date

$version = $gdaemonStatus->version();

Base Information

Get uptime info, number of working and waiting tasks, number of online servers list

$info = $gdaemonStatus->infoBase();

Details Information

Get uptime info, ID list of working and waiting tasks, ID list of online servers list

$info = $gdaemonStatus->infoDetails();