定制 seatlon/cs2-log 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

seatlon/cs2-log

最新稳定版本:v2.0.7

Composer 安装命令:

composer require seatlon/cs2-log

包简介

Counter-Strike 2 log parsing in PHP

README 文档

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

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

统计信息

  • 总下载量: 424
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-01-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固