承接 d3lph1/minecraft-rcon-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

d3lph1/minecraft-rcon-manager

最新稳定版本:1.3

Composer 安装命令:

composer require d3lph1/minecraft-rcon-manager

包简介

Library for easy interaction with the minecraft server using rcon.

README 文档

README

Library for easy interaction with the minecraft server using rcon.

Installation

Execute command:

composer require d3lph1/minecraft-rcon-manager ~1.0

or add line to require section of composer.json

"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.

use \D3lph1\MinecraftRconManager\DefaultConnector;

$connector = new DefaultConnector();

In order to connect directly to the server, use this construction

$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)

You can also add the server to the server pool in order to get the connection instance later:

$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:

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

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

Remove server from server pool:

$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:

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

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

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

$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.

Get data from last request:

$response = $rcon->last();

Disconnect from server:

$rcon->disconnect();

统计信息

  • 总下载量: 3.01k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固