PHP code example of aon4o / cs2-gsi-parser

1. Go to this page and download the library: Download aon4o/cs2-gsi-parser 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/ */

    

aon4o / cs2-gsi-parser example snippets


use Aon4o\Cs2GsiParser\GameState;

/** @var string|array|object $data */
$game_state = GameState::from($data);

echo $game_state->map->name; // de_dust2

use Aon4o\Cs2GsiParser\ConfigWriter;

$config = ConfigWriter::new()
    ->setUrl('http://yourdomain.com/cs2-gsi-endpoint')
    ->setAuthToken('your_auth_key')
    ->setSettings(timeout: 5.0, buffer: 0.1, throttle: 0.1, heartbeat: 30.0)
    ->get();

echo $config;
// "cs2-gsi"
// {
//     "uri" "http://yourdomain.com/cs2-gsi-endpoint"
//     "timeout" "5"
//     "buffer"  "0.1"
//     "throttle" "0.1"
//     "heartbeat" "30"
//     "auth"
//     {
//         "token" "your_auth_key"
//     }
//     "data"
//     {
//         "map_round_wins" "1"
//         "map" "1"
//         "player_id" "1"
//         "player_match_stats" "1"
//         "player_state" "1"
//         "player_weapons" "1"
//         "provider" "1"
//         "round" "1"
//         "allgrenades" "1"
//         "allplayers_id" "1"
//         "allplayers_match_stats" "1"
//         "allplayers_position" "1"
//         "allplayers_state" "1"
//         "allplayers_weapons" "1"
//         "bomb" "1"
//         "phase_countdowns" "1"
//         "player_position" "1"
//     }
// }

use Aon4o\Cs2GsiParser\GameState;
use Aon4o\Cs2GsiParser\EventExtractor;

/** @var GameState $prev */
/** @var GameState $curr */

new EventExtractor($prev, $curr)->allEvents();
new EventExtractor($prev, $curr)->mapEvents();
new EventExtractor($prev, $curr)->playerEvents();
new EventExtractor($prev, $curr)->roundEvents();

// Example output

 array:1 [                                                                                                                                                                                      
    0 => Aon4o\Cs2GsiParser\Enums\Custom\Event {#741                                                                                                                                             
      +name: "MAP_PHASE_CHANGED"                                                                                                                                                                 
      +value: "map.phase_changed"                                                                                                                                                                
    }                                                                                                                                                                                            
  ]