felixms / arma-rcon-class-php

A lightweight client for sending commands easily to a BattlEye server.
MIT License
46 stars 22 forks source link
api battleye battleye-commands battleye-server client composer php php-library rcon socket

Arma RCon Class (ARC) 2.2 for PHP

Codacy Badge Packagist Version GitHub License

ARC is a lightweight PHP class, that allows you connecting and sending commands easily to your BattlEye server, including Arma 3, Arma 2 and Arma 2: OA game servers.

Requirements

ARC 2.2 only requires PHP 5.4 or higher!

Installation

Via Composer (recommended)

If you haven't already, download Composer.

$ curl -s http://getcomposer.org/installer | php

Now require and install ARC.

$ composer require nizarii/arma-rcon-class
$ composer install

Without Composer

Choose a release and include ARC in your project: require_once 'arc.php';.

Examples

Getting started

After installing ARC, you can easily use ARC as shown below. It will automatically establish a new connection and authenticate.

use \Nizarii\ARC;

$rcon = new ARC(string $ServerIP, string $RConPassword [, int $Port = 2302 [, array $Options = array()]]);

You are able to send commands with the command() function.

//...
$rcon->command('YourCommand');

ARC will throw an Exception if anything goes wrong. You might want to wrap your code in a try catch block.

use \Nizarii\ARC;

try {
    $rcon = new ARC('127.0.0.1', 'password');

    $array = $rcon->getPlayersArray();

    $rcon
        ->sayGlobal('example')
        ->kickPlayer(1, 'example')
        ->sayPlayer(0, 'example')
        ->disconnect()
    ;

    $rcon->getBans(); // Throws exception, because the connection was closed
} catch (Exception $e) {
    echo "Ups! Something went wrong: {$e->getMessage()}";
}

Please consider that ARC only checks whether the command has been successfully sent via the socket to the server. It does not check if the command has been executed by the server.

Options

Options can be passed to ARC as an array via the fourth parameter of the constructor. The following options are currently available:

Suggestions for new options are always welcome! :+1:

Basic usage:

use \Nizarii\ARC;

$rcon = new ARC('127.0.0.1', 'RConPassword', 2322, [
    'timeoutSec' => 2
]);

//...

Functions

ARC features many functions to send BattlEye commands easier. After creating a new connections as explained above, you are able to use any of these functions:

See here for more information about BattlEye commands

Contributors

Thanks to all contributors for submitting issues and contributing code, including:

New contributors are always welcome :heart:

License

ARC is licensed under the MIT License. View LICENSE file for more information.