seatlon / cs2-log
Counter-Strike 2 log parsing in PHP
Installs: 424
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/seatlon/cs2-log
Requires
- php: ^8.1
- nesbot/carbon: ^3.11
Requires (Dev)
- laravel/pint: ^1.12
- pestphp/pest: ^2.0
- phpstan/phpstan: ^2.1
- spatie/ray: ^1.28
README
Parsing Counter-Strike (2) logs in PHP. Provides typed objects for each log and a class for matching individual log lines.
Installation
You can install the package via composer:
composer require seatlon/cs2-log
Usage Examples
Basic Usage (Line by Line - Backwards Compatible)
use CSLog\CS2\Patterns; $lines = file('server.log', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { $event = Patterns::match($line); if ($event) { // Process event } }
Advanced Usage (Full Parser with Carbon)
use CSLog\CS2\Parser; use CSLog\CS2\Models\RoundStats; use CSLog\CS2\Models\TeamPlaying; use CSLog\CS2\Models\ServerCVar; use CSLog\CS2\Models\Kill; $logContent = file_get_contents('server.log'); $parser = new Parser(); $events = $parser->parse($logContent); foreach ($events as $event) { if ($event instanceof RoundStats) { echo "Round {$event->roundNumber} at {$event->timestamp->format('H:i:s')}\n"; echo "Score: CT {$event->scoreCT} - {$event->scoreT} T\n"; foreach ($event->players as $playerKey => $stats) { if ($stats['accountid'] > 0) { echo " {$stats['accountid']}: {$stats['kills']}K / {$stats['deaths']}D\n"; } } } elseif ($event instanceof TeamPlaying) { echo "Team {$event->side}: {$event->teamName}\n"; echo "Assigned at: {$event->timestamp->format('H:i:s')}\n"; } elseif ($event instanceof ServerCVar) { echo "Server setting: {$event->cvar} = {$event->value}\n"; } elseif ($event instanceof Kill) { echo "{$event->attacker->name} killed {$event->victim->name}\n"; echo "Time: {$event->timestamp->diffForHumans()}\n"; } }
Working with Carbon Timestamps
use Carbon\Carbon; // Filter events by time $recentEvents = array_filter($events, function($event) { return $event->timestamp->isAfter(Carbon::now()->subHour()); }); // Get events from specific date $dateEvents = array_filter($events, function($event) { return $event->timestamp->isSameDay('2026-01-19'); }); // Group events by hour $hourlyGroups = collect($events)->groupBy(function($event) { return $event->timestamp->format('Y-m-d H:00'); }); // Calculate time differences $firstEvent = $events[0]; $lastEvent = end($events); $duration = $firstEvent->timestamp->diffInMinutes($lastEvent->timestamp); echo "Match duration: {$duration} minutes\n";
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
- Alexander Nilsson (SeatloN)
- Harry (hjbdev)
- All Contributors
- eBot (for some of the original Global Offensive patterns, which I have updated and refined for CS2)
License
The MIT License (MIT). Please see License File for more information.
Docker Build Command
docker build -t cs2-log .
Docker Run Command
docker run --rm --tty cs2-log