PHP code example of d3lph1 / minecraft-rcon-manager
1. Go to this page and download the library: Download d3lph1/minecraft-rcon-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
d3lph1 / minecraft-rcon-manager example snippets
use \D3lph1\MinecraftRconManager\DefaultConnector;
use \D3lph1\MinecraftRconManager\Exceptions\ConnectSocketException;
use \D3lph1\MinecraftRconManager\Exceptions\AccessDenyException;
$connector = new DefaultConnector();
try {
// Connect to RCON
$rcon = $connector->connect('127.0.0.1', 25575, '123456');
}catch(ConnectSocketException $e) {
// do something...
}catch(AccessDenyException $e) {
// do something...
}
// Get only response body
$response = $rcon->send('say Yes, it works...');
print_r($response); // §d[Rcon§d] Yes, it works...
// Get response array
$response = $rcon->send('say Yes, it works...', true);
print_r($response);
/**
* Array (
* [id] => 16
* [type] => 0
* [body] => §d[Rcon§d] Yes, it works...
* )
*
*/
// Get last response
$last = $rcon->getLast();
// Close RCON connection
$rcon->disconnect();
use \D3lph1\MinecraftRconManager\DefaultConnector;
$connector = new DefaultConnector();
$connector->add($name, $host, $port, $password, $timeout);
// Still as an option...
$connector->add('hi_tech', [
'host' => '127.0.0.1',
'port' => 25575,
'password' => '123456',
'timeout' => 1
]);
// Since the Connector class implements the ArrayAccess interface,
// the servers can be placed into the pool by accessing the object as an array.
$connector['mmo'] = [
'host' => '127.0.0.1',
'port' => 25576,
'password' => '123456',
'timeout' => 1
];