anvilm / rcon
适用于 Laravel 的 Minecraft Rcon 库
v1.2
2024-03-06 19:17 UTC
Requires
- php: ^8.1
README
Minecraft RCON 库 for Laravel
安装
您可以使用 composer 获取此包
composer require anvilm/rcon
配置
要在您的服务器上使用 RCON,您需要在 Minecraft 服务器设置中启用并配置它。
在文件 server.properties 中
rcon.port=25575 enable-rcon=true rcon.password=123
入门指南
创建连接
要创建与 Minecraft 服务器 RCON 的连接,您需要创建 RCON 类的对象。
use AnvilM\RCON\RCON; $Ip = '127.0.0.1'; //Server IP $Port = 25575; //RCON port $Password = '123'; //RCON password $Timeout = 30; //Timeout in ms $RCON = new RCON($Ip, $Port, $Password, $Timeout);
发送命令
要向服务器发送命令,请使用 RСON 类的此方法。此方法将返回服务器的响应。
use AnvilM\RCON\RCON; ... $RCON->sendCommand('time set day');
服务器响应
所有响应
要获取服务器的所有响应,请使用以下方法
use AnvilM\RCON\RCON; ... $Response = $RCON->ResponseService->getAllResponses();
最后响应
要获取服务器的最后响应,请使用以下方法
use AnvilM\RCON\RCON; ... $Response = $RCON->ResponseService->getLastResponse();
按 ID 获取响应
如果您有该响应的 ID,您可以从列表中获取特定的服务器响应。
use AnvilM\RCON\RCON; ... $Response = $RCON->ResponseService->getResponse(3);
示例
以下是一个使用此库的真实示例
namespace App\Http\Controllers; use AnvilM\RCON\RCON; class RCONController extends Controller { public function setDay() { $Ip = '127.0.0.1'; //Server IP $Port = 25575; //RCON port $Password = '123'; //RCON password $Timeout = 30; //Timeout in ms $RCON = new RCON($Ip, $Port, $Password, $Timeout); //Create connection $RCON->sendCommand('time set day'); //Send command $Response = $RCON->ResponseService->getLastResponse(); //Get last response echo $Response; } }
执行此代码后,您应该得到以下结果
Set the time to 1000