dsg/postscriptum-rcon-php

0.1.0 2020-12-19 21:36 UTC

README

Post Scriptum RCON PHP Logo

Post Scriptum RCON PHP

PHP Wrapper for Post Scriptum RCON Commands

Deutsche Squad Gemeinschaft Deutsche Squad Gemeinschaft Total Downloads Latest Stable Version Latest Unstable Version License
Deutsche Squad Gemeinschaft Discord

Join the Squad RCON Community

If you have any questions or need help with getting started with RCON in OWI games you should make sure to join the Squad RCON Community on Discord.

Installation

You can install this package by using composer and the following command:

composer require dsg/postscriptum-rcon-php

The code will then be available under the DSG\PostScriptumRCON namespace.

Commands

  • ListPlayers
  • AdminListDisconnectedPlayers
  • ShowNextMap
  • AdminKick "<NameOrSteamId>" <KickReason>
  • AdminKickById <PlayerId> <KickReason>
  • AdminBan "<NameOrSteamId>" "<BanLength>" <BanReason>
  • AdminBanById <PlayerId> "<BanLength>" <BanReason>
  • AdminBroadcast <Message>
  • AdminRestartMatch
  • AdminEndMatch
  • AdminChangeMap <MapName>
  • AdminSetNextMap <MapName>
  • AdminSetMaxNumPlayers <NumPlayers>
  • AdminSetServerPassword <Password>
  • AdminForceTeamChange <NameOrSteamId>
  • AdminForceTeamChangeById <PlayerId>
  • AdminDemoteCommander <PlayerName>
  • AdminDemoteCommanderById <PlayerId>
  • AdminDisbandSquad <TeamId> <SquadId>
  • AdminRemovePlayerFromSquad <PlayerName>
  • AdminRemovePlayerFromSquadById <PlayerId>
  • AdminWarn <NameOrSteamId> <WarnReason>
  • AdminWarnById <PlayerId> <WarnReason>

USAGE

Create an instance

Instanciate the PostScriptumServer class to open a new RCON connection. This will throw an Exception if no connection can be made.

use DSG\PostScriptumRCON\PostScriptumServer;

...

/** @var PostScriptumServer */
$server = new PostScriptumServer(new ServerConnectionInfo('127.0.0.1', 21114, 'YourRconPassword'));

ListPlayers

Get the current Player list using the ListPlayers command. This does not include disconnected players.

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

Get disconnected Players

Get disconnected players using the ListPlayers command.

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

AdminKick

Kick a player by name, SteamId or ingame id.

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

// or

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

AdminBan

Ban a player by name, SteamId or ingame id.

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

// or

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

Get the current map

Get the current map using the ShowNextMap command

/** @var string */
$map = $server->currentMap();

Get the next map

Get the next map using the ShowNextMap command

/** @var string */
$map = $server->nextMap();

AdminRestartMatch

Restart the current match

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

AdminEndMatch

End the current match

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

AdminBroadcast

Broadcast message to all players on the server

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

AdminChangeMap

Set the next map and end the current game immediately.

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

AdminSetNextMap

Sets next map

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

AdminSetMaxNumPlayers

Set the maximum amount of players / slots

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

AdminSetServerPassword

Set the server password

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

AdminForceTeamChange

Forces a player to the opposite team by providing the name or steamid.

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

AdminForceTeamChangeById

Forces a player to the opposite team by providing the ingame Player id.

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

AdminDisbandSquad command.

Disbands a Squad by providing the Team id / index & Squad id / index.

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

AdminRemovePlayerFromSquad

Removes a Player from his Squad by providing the Player name.

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

AdminRemovePlayerFromSquadById

Removes a player from his Squad by providing the ingame Player id.

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

AdminWarn

Warns a Player by providing his name / steamid and a message.

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

AdminWarnById

Warns a Player by id.

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

Important Note

Make sure to always close the connection manually or trigger a disconnect by destructing the object to preventt blocking the RCON server by using up it'S available connections.

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

Special Thanks

  • SquadSlovenia (Intial creators)
  • Brozowski (Major contributor)
  • [ToG] subtlerod (Major contributions to the used SquadRcon implementation)
  • Thomas Smyth (Creator of SquadJS, a great resource for Squad RCON).