2017 © Pedro PelĂĄez
 

library minecraft-rcon-manager

Library for easy interaction with the minecraft server using rcon.

image

d3lph1/minecraft-rcon-manager

Library for easy interaction with the minecraft server using rcon.

  • Thursday, July 12, 2018
  • by D3lph1
  • Repository
  • 1 Watchers
  • 1 Stars
  • 359 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 18 % Grown

The README.md

minecraft-rcon-manager

Library for easy interaction with the minecraft server using rcon., (*1)

Installation

Execute command:, (*2)

composer require d3lph1/minecraft-rcon-manager ~1.0

or add line to require section of composer.json, (*3)

"d3lph1/minecraft-rcon-manage": "~1.0",

Usage

Overview

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();

Connecting

First, you need to create an instance of the Connector class. The instance will serve to create a connection to the server, add servers to the pool and remove them from there., (*4)

use \D3lph1\MinecraftRconManager\DefaultConnector;

$connector = new DefaultConnector();

In order to connect directly to the server, use this construction, (*5)

$rcon = $connector->connect($host, $port, $password, $timeout);

Where: * $host - Server host (By default, 127.0.0.1) * $port - Rcon port (By default, 25575) * $password - Rcon password * $timeout - Connection timeout (By default, 1 second), (*6)

You can also add the server to the server pool in order to get the connection instance later:, (*7)

$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
];

Ok, now we need the servers in the pool. Now that you need a server in the future, you will pull it out of the pool like this:, (*8)

$rcon = $connector->get('hi_tech');

// Or...
$rcon = $connector['mmo'];

Remove server from server pool:, (*9)

$connector->remove('hi_tech');

// or...
unset($connector['hi_tech']);

Sending requests

Using the constructs described above, we get an instance of the class D3lph1\MinecraftRconManager\Rcon with which we can finally send requests to our server:, (*10)

$response = $rcon->send('say Yes, it works...');

In return we will get something like this: §d[Rcon§d] Yes, it works..., (*11)

You can get not only the body of the answer but the entire array in which besides the body contains also the service information. Just pass true to the second argument to send()., (*12)

$response = $rcon->send('say Yes, it works...', true);

This array contains element type - the type of request (authorization or command execution) and the request id - required to check the integrity of the response., (*13)

Get data from last request:, (*14)

$response = $rcon->last();

Disconnect from server:, (*15)

$rcon->disconnect();

The Versions

12/07 2018

dev-master

9999999-dev

Library for easy interaction with the minecraft server using rcon.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bogdan Chertkov

minecraft rcon mc

12/07 2018

1.3

1.3.0.0

Library for easy interaction with the minecraft server using rcon.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bogdan Chertkov

minecraft rcon mc

26/10 2017

1.2

1.2.0.0

Library for easy interaction with the minecraft server using rcon.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bogdan Chertkov

minecraft rcon mc

20/03 2017

1.1

1.1.0.0

Library for easy interaction with the minecraft server using rcon.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bogdan Chertkov

minecraft rcon mc

19/03 2017

1.0

1.0.0.0

Library for easy interaction with the minecraft server using rcon.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bogdan Chertkov

minecraft rcon mc