xety/laravel-rcon

Laravel 的 RCON 协议服务提供商

v1.0.3 2020-08-06 21:20 UTC

This package is auto-updated.

Last update: 2024-09-22 14:57:30 UTC


README

本软件包是为了为 Laravel 框架提供服务而开发的,允许您使用源 RCON 协议进行工作。您可以在本页面上阅读更多协议规范:https://developer.valvesoftware.com/wiki/Source_RCON_Protocol

安装

  1. 使用以下命令安装 composer 软件包
composer require lukasz-adamski/laravel-rcon
  1. config/app.php 中添加服务提供者
Adams\Rcon\RconServiceProvider::class,
  1. config/app.php 中添加外观
'Rcon' => Adams\Rcon\Facades\Facade::class,
  1. 将配置文件发布到您的项目中
php artisan vendor:publish --provider="Adams\Rcon\RconServiceProvider"

环境

您可以设置环境变量以建立默认的 RCON 连接。

  • RCON_CONNECTION - 存储在 config/rcon.php 中的默认 RCON 连接名称,
  • RCON_HOST - RCON 服务器主机名,
  • RCON_PORT - 监听 RCON 服务器端口的端口,
  • RCON_PASSWORD - 用于授权连接的口令,您可以使用 null 跳过授权,
  • RCON_TIMEOUT - RCON 服务器连接超时。

测试

要运行预定义的测试集,请使用

php vendor/bin/phpunit

使用方法

下面是示例控制器实现

<?php

namespace App\Http\Controllers;

use Rcon;
use App\Http\Controllers\Controller;

class SimpleRconController extends Controller
{
    /**
     * Execute status command on default RCON server.
     *
     * @return Response
     */
    public function defaultStatus()
    {
        $response = Rcon::command('status');

        return view('console', compact('response'));
    }

    /**
     * Execute status command on specified RCON connection.
     *
     * @return Response
     */
    public function gameServerStatus()
    {
        $response = Rcon::connection('game_server')
            ->command('status');

        return view('console', compact('response'));
    }
}