dsg/squad-rcon-php
Composer 安装命令:
composer require dsg/squad-rcon-php
包简介
Squad Server RCon library
README 文档
README
Squad RCON PHP
RCON PHP wrapper for Squad server management
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/squad-rcon-php
The code will then be available under the DSG\SquadRCON namespace.
Commands
- ListPlayers
- ListSquads
- AdminListDisconnectedPlayers
- ShowCurrentMap
- ShowNextMap
- AdminKick "<NameOrSteamId>" <KickReason>
- AdminKickById <PlayerId> <KickReason>
- AdminBan "<NameOrSteamId>" "<BanLength>" <BanReason>
- AdminBanById <PlayerId> "<BanLength>" <BanReason>
- AdminBroadcast <Message>
- AdminRestartMatch
- AdminEndMatch
- AdminChangeLevel <LevelName>
- AdminSetNextLevel <LevelName>
- AdminChangeLayer <LayerName>
- AdminSetNextLayer <LayerName>
- AdminSetMaxNumPlayers <NumPlayers>
- AdminSetServerPassword <Password>
- AdminSlomo <TimeDilation>
- AdminForceTeamChange <NameOrSteamId>
- AdminForceTeamChangeById <PlayerId>
- AdminDemoteCommander <PlayerName>
- AdminDemoteCommanderById <PlayerId>
- AdminDisbandSquad <TeamId> <SquadId>
- AdminRemovePlayerFromSquad <PlayerName>
- AdminRemovePlayerFromSquadById <PlayerId>
- AdminWarn <NameOrSteamId> <WarnReason>
- AdminWarnById <PlayerId> <WarnReason>
- AdminVoteLevel <Choices, concatenated by +>
- AdminVoteLayer <Choices, concatenated by +>
- AdminVoteNextLevel <Choices, concatenated by +>
- AdminVoteNextLayer <Choices, concatenated by +>
- AdminVote <Vote name> <Choices, concatenated by +>
USAGE
Create an instance
Instanciate the SquadServer class to open a new RCON connection. This will throw an Exception if no connection can be made.
use DSG\SquadRCON\SquadServer; ... /** @var SquadServer */ $server = new SquadServer(new ServerConnectionInfo( host: '127.0.0.1', port: 21114, password: 'YourRconPassword' ));
Get current server population (Teams, Squads, Players)
Get the current population. This does use ListPlayers & ListSquads to get the Teams, Squads and Players properly ordered.
/** @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');
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();
ListSquads
Get currently active squads (and teams)
/** @var Team[] */ $teams = $server->listSquads();
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 array */ $map = $server->showCurrentMap(); echo $map['level']; echo $map['layer'];
Get the next map
Get the next map using the ShowNextMap command
/** @var array */ $map = $server->showNextMap(); echo $map['level']; echo $map['layer'];
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');
AdminChangeLevel
Change the level ( and pick a random layer on it) and travel to it immediately
/** @var bool */ $success = $server->adminChangeLevel('Sumari');
AdminSetNextLevel
Set the next Level ( and pick a random layer on it) to travel to after this match ends
/** @var bool */ $success = $server->adminSetNextLevel('Sumari');
AdminChangeLayer
Change the layer and travel to it immediately
/** @var bool */ $success = $server->adminChangeLayer('Sumari AAS v1');
AdminSetNextLayer
Set the next layer to travel to after this match ends
/** @var bool */ $success = $server->adminSetNextLayer('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');
AdminSlomo
Sets the game speed with the AdminSlomo. Default 1.0
/** @var bool */ $success = $server->adminSlomo(1.5);
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).
dsg/squad-rcon-php 适用场景与选型建议
dsg/squad-rcon-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.55k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2020 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dsg/squad-rcon-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dsg/squad-rcon-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-02-01