PHP code example of dsg / squad-rcon-php

1. Go to this page and download the library: Download dsg/squad-rcon-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dsg / squad-rcon-php example snippets


use DSG\SquadRCON\SquadServer;

...

/** @var SquadServer */
$server = new SquadServer(new ServerConnectionInfo(
    host: '127.0.0.1',
    port: 21114,
    password: 'YourRconPassword'
));

/** @var Population */
$population = $server->serverPopulation();

/** @var Team[] */
$teams = $population->getTeams();

foreach ($teams as $team) {
    $name = $team->getName();
    
    foreach ($team->getSquads() as $squad) {
        $creatorName = $squad->getCreatorName();
        $creatorSteamId = $squad->getCreatorSteamId();
        
        foreach ($squad->getPlayers() as $player) {
            $name = $player->getName();
            $steamId = $player->getSteamId();
        }
    }
    
    foreach ($team->getPlayers() as $unassigned) {
        $name = $player->getName();
        $steamId = $player->getSteamId();
    }
}

// or

/** @var Player[] */
$players = $population->getPlayers();

// or

/** @var Player|null */
$player = $population->getPlayerBySteamId('76561197960287930');

/** @var Player[] */
$players = $server->listPlayers();

/** @var Player[] */
$players = $server->listDisconnectedPlayers();

/** @var Team[] */
$teams = $server->listSquads();

/** @var bool */
$success = $server->adminKick('76561197960287930', 'Reason');

// or

/** @var bool */
$success = $server->adminKickById($player->getId(), 'Reason');

/** @var bool */
$success = $server->adminBan('76561197960287930', '1h', 'Reason');

// or

/** @var bool */
$success = $server->adminBanById($player->getId(), '1h', 'Reason');

/** @var array */
$map = $server->showCurrentMap();
echo $map['level'];
echo $map['layer'];

/** @var array */
$map = $server->showNextMap();
echo $map['level'];
echo $map['layer'];

/** @var bool */
$success = $server->adminRestartMatch();

/** @var bool */
$success = $server->adminEndMatch();

/** @var bool */
$success = $server->adminBroadcast('Hello from the other side');

/** @var bool */
$success = $server->adminChangeLevel('Sumari');

/** @var bool */
$success = $server->adminSetNextLevel('Sumari');

/** @var bool */
$success = $server->adminChangeLayer('Sumari AAS v1');

/** @var bool */
$success = $server->adminSetNextLayer('Sumari AAS v1');

/** @var bool */
$success = $server->adminSetMaxNumPlayers(80);

/** @var bool */
$success = $server->adminSetServerPassword('secret');

/** @var bool */
$success = $server->adminSlomo(1.5);

/** @var bool */
$success = $server->adminForceTeamChange('Name or SteamId');

/** @var bool */
$success = $server->adminForceTeamChangeById($player->getId());

/** @var bool */
$success = $server->adminDisbandSquad($team->getId(), $squad->getId());

/** @var bool */
$success = $server->adminRemovePlayerFromSquad('Name');

/** @var bool */
$success = $server->adminRemovePlayerFromSquadById($player->getId());

/** @var bool */
$success = $server->adminWarn('Name or SteamId', 'Warn Reason');

/** @var bool */
$success = $server->adminWarnById($player->getId(), 'Warn Reason');

$server->disconnect();
// Or
unset($server);

composer