hugojf/csgo-server-api-laravel
Composer 安装命令:
composer require hugojf/csgo-server-api-laravel
包简介
A simple way to communicate with CS:GO servers.
README 文档
README
Laravel package to interface CS:GO Server API.
How it works
This package interfaces my CS:GO API main endpoints:
/send which you can send a command, with a delay to a single server;
/sendAll which you can send a command, with a delay to all servers controlled by the API;
Requirements
-
PHP 7.*
-
CS:GO Server API installation
Installation
Using Composer, run:
composer require hugojf/csgo-server-api-laravel
Publish config:
php artisan vendor:publish --provider="hugojf\CsgoServerApi\Providers\PackageServiceProvider"
Configuration
Any configuration can be modified inside configs/csgo-api.php
CSGO_API_URL=http://my-csgo-server-api.com/
API server endpoint URL.
CSGO_API_KEY=abcdef123456
API server authentication key.
Usage
Creating a command
$myCommand = new Command($command, $delay = 0, $wait = false);
Parameters
$commandis the command to be executed;$delaytells how long the API should wait before sending the command;$waittells the API to wait for server response before responding the request.
Examples
// Get server stats $statsCommand = new Command('stats', 0, true); // Kick bots $botsCommand = new Command('bot_kick'); // Schedule say message $sayCommand = new Command('say Hi!', 30000)
Creating a server
$myServer = new Server($address, $port);
Parameters
$addressis the full address or just IP;$portis the server port.
Examples
// Using IP and Port $server1 = new Server('177.54.150.15', 27001); // Using full address $server2 = new Server('177.54.150.15:27002');
Sending a list of commands to a list of servers
// Sends `stats` and `status` to both servers // // You can replace `direct` with `to`, they are the same CsgoApi::direct(ByCommandSummary::class)->addCommand([ new Command('stats', 1500, true), new Command('status', 1500, true), ])->addServer( new Server('177.54.150.15:27001'), new Server('177.54.150.15:27002'), )->send(); // Expected response: // [ // "stats" => [ // "177.54.150.15:27001" => "response-1", // "177.54.150.15:27001" => "response-2", // ], // "status" => [ // "177.54.150.15:27001" => "response-3", // "177.54.150.15:27001" => "response-4", // ], // ]
Broadcasting a list of commands to all servers controlled by the API
// Sends `say` and `quit` to all servers // // You can replace `broadcast` with ``, they are the same CsgoApi::broadcast(ByCommandSummary::class)->addCommand([ new Command('say "Closing server for maintenance in 30 seconds', 0), new Command('say "Closing server for maintenance in 15 seconds', 15000), new Command('say "Closing server for maintenance in 5 seconds', 25000), new Command('quit', 30000), ])->send();
Different ways you can add commands or servers
In an attempt to avoid instantiating every server or command, you can use the following formats:
Servers
// Creating a DirectSender $sender = CsgoApi::direct(); // Using full Server object // // All 4 methods are identical, use what feels right $sender->addServer(new Server('177.54.150.15:27001')); $sender->addServers(new Server('177.54.150.15:27001')); $sender->server(new Server('177.54.150.15:27001')); $sender->servers(new Server('177.54.150.15:27001')); // Using list of Server objects $sender->addServer([ new Server('177.54.150.15:27001'), new Server('177.54.150.15:27002'), ]); // Using string address $sender->addServer('177.54.150.15:27002'); // Using list of string addresses $sender->addServer([ '177.54.150.15:27001', '177.54.150.15:27002', ]); // Using IP and Port separately $sender->addServer('177.54.150.15', 27002); // Using list of IP and Ports $sender->addServer([ ['177.54.150.15', 27001], ['177.54.150.15', 27002], ]);
Commands
// Creating a DirectSender $sender = CsgoApi::direct(); // Using full Command object // // All 4 methods are identical, use what feels right $sender->addCommand(new Command('stats', 1000, false)); $sender->addCommands(new Command('stats', 1000, false)); $sender->command(new Command('stats', 1000, false)); $sender->commands(new Command('stats', 1000, false)); // Using list of Command objects $sender->addCommandItem([ new Command('stats', 1500, false), new Command('status', 1500, false), ]); // Using command parameters directly $sender->addCommand('stats', 1500, false); // Using list of command parameters $sender->addCommand([ ['stats', '1500', false], ['status', '1500', false], ]);
Changing summary class
You can change the way responses are grouped by passing a new Summary class
ByCommandSummary::class
Groups responses by command first and then server after.
// Example response // [ // "stats" => [ // "177.54.150.15:27001" => "response-1", // "177.54.150.15:27002" => "response-2", // ], // "status" => [ // "177.54.150.15:27001" => "response-3", // "177.54.150.15:27002" => "response-4", // ], // ]
ByServerSummary::class
Groups responses by server first and then command after.
// Example response // [ // "177.54.150.15:27001" => [ // "stats" => "response-1", // "status" => "response-3", // ], // "177.54.150.15:27002" => [ // "stats" => "response-2", // "status" => "response-4", // ], // ]
Example
$directByCommandSender = CsGoApi::direct(ByCommandSummary::class); $directByServerSender = CsGoApi::direct(ByServerCummary::class); $broadcastByCommandSender = CsGoApi::broadcast(ByCommandSummary::class); $broadcastByServerSender = CsGoApi::broadcast(ByServerCummary::class);
hugojf/csgo-server-api-laravel 适用场景与选型建议
hugojf/csgo-server-api-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hugojf/csgo-server-api-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hugojf/csgo-server-api-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2019-11-02