PHP code example of hugojf / csgo-server-api-laravel

1. Go to this page and download the library: Download hugojf/csgo-server-api-laravel 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/ */

    

hugojf / csgo-server-api-laravel example snippets


$myCommand = new Command($command, $delay = 0, $wait = false);

// 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)

$myServer = new Server($address, $port);

// Using IP and Port
$server1 = new Server('177.54.150.15', 27001);

// Using full address
$server2 = new Server('177.54.150.15:27002');

// 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",
//      ],
//   ]

// 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();

// 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],
]);

// 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],
]);

// 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",
//      ],
//   ]

// Example response
//  [
//      "177.54.150.15:27001"  => [
//          "stats" => "response-1",
//          "status" => "response-3",
//      ],
//      "177.54.150.15:27002" => [
//          "stats" => "response-2",
//          "status" => "response-4",
//      ],
//   ]

$directByCommandSender = CsGoApi::direct(ByCommandSummary::class);
$directByServerSender = CsGoApi::direct(ByServerCummary::class);

$broadcastByCommandSender = CsGoApi::broadcast(ByCommandSummary::class);
$broadcastByServerSender = CsGoApi::broadcast(ByServerCummary::class);