Skip to content

Commit 21b37b8

Browse files
committed
Initial Commit
0 parents  commit 21b37b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1322
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.github export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/psalm.xml.dist export-ignore
10+
/tests export-ignore
11+
/.editorconfig export-ignore
12+
/.php-cs-fixer.dist.php export-ignore
13+
/art export-ignore
14+
/docs export-ignore
15+
/UPGRADING.md export-ignore

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.idea
2+
.php_cs
3+
.php_cs.cache
4+
.phpunit.result.cache
5+
build
6+
composer.lock
7+
coverage
8+
docs
9+
phpunit.xml
10+
psalm.xml
11+
vendor
12+
.php-cs-fixer.cache
13+

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
All notable changes to `cs-log-parser-php` will be documented in this file.
4+

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) hjbdev <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Counter-Strike log parsing in PHP
2+
3+
<!-- [![Latest Version on Packagist](https://img.shields.io/packagist/v/hjbdev/cs-log-parser-php.svg?style=flat-square)](https://packagist.org/packages/hjbdev/cs-log-parser-php)
4+
[![Tests](https://img.shields.io/github/actions/workflow/status/hjbdev/cs-log-parser-php/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/hjbdev/cs-log-parser-php/actions/workflows/run-tests.yml)
5+
[![Total Downloads](https://img.shields.io/packagist/dt/hjbdev/cs-log-parser-php.svg?style=flat-square)](https://packagist.org/packages/hjbdev/cs-log-parser-php) -->
6+
7+
Parsing Counter-Strike (GO and soon CS2) logs in PHP. Provides typed objects for each log and a class for matching individual log lines.
8+
9+
10+
## Installation
11+
12+
You can install the package via composer:
13+
14+
```bash
15+
composer require hjbdev/cs-log-parser-php
16+
```
17+
18+
## Usage
19+
20+
```php
21+
use CSLog\CSGO\Patterns;
22+
23+
$model = Patterns::match($log);
24+
```
25+
26+
## Testing
27+
28+
```bash
29+
composer test
30+
```
31+
32+
## Changelog
33+
34+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
35+
36+
## Credits
37+
38+
- [Harry (hjbdev)](https://github.com/hjbdev)
39+
- [All Contributors](../../contributors)
40+
- [eBot](https://github.com/deStrO/eBot-CSGO) (for Global Offensive regex patterns)
41+
42+
## License
43+
44+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "hjbdev/cs-log-parser-php",
3+
"description": "Counter-Strike log parsing in PHP",
4+
"keywords": [
5+
"hjbdev",
6+
"cs-log-parser-php"
7+
],
8+
"homepage": "https://github.com/hjbdev/cs-log-parser-php",
9+
"license": "MIT",
10+
"authors": [
11+
{
12+
"name": "Harry (hjbdev)",
13+
"email": "[email protected]",
14+
"role": "Developer"
15+
}
16+
],
17+
"require": {
18+
"php": "^8.1"
19+
},
20+
"require-dev": {
21+
"laravel/pint": "^1.12",
22+
"pestphp/pest": "^2.0",
23+
"spatie/ray": "^1.28"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"CSLog\\": "src"
28+
}
29+
},
30+
"autoload-dev": {
31+
"psr-4": {
32+
"CSLog\\Tests\\": "tests"
33+
}
34+
},
35+
"scripts": {
36+
"test": "vendor/bin/pest",
37+
"test-coverage": "vendor/bin/pest --coverage",
38+
"format": "vendor/bin/pint"
39+
},
40+
"config": {
41+
"sort-packages": true,
42+
"allow-plugins": {
43+
"pestphp/pest-plugin": true,
44+
"phpstan/extension-installer": true
45+
}
46+
},
47+
"minimum-stability": "dev",
48+
"prefer-stable": true
49+
}

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="Spatie Test Suite">
5+
<directory>tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage>
9+
<report>
10+
<html outputDirectory="build/coverage"/>
11+
<text outputFile="build/coverage.txt"/>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
</report>
14+
</coverage>
15+
<logging>
16+
<junit outputFile="build/report.junit.xml"/>
17+
</logging>
18+
<source>
19+
<include>
20+
<directory suffix=".php">./src</directory>
21+
</include>
22+
</source>
23+
</phpunit>

src/CS2/Models/Attack.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class Attack extends Model
8+
{
9+
public const PATTERN = '/"(?P<attackerName>.*)[<](?P<attackerId>\d+)[>][<](?P<attackerSteamId>.*)[>][<](?P<attackerTeam>CT|TERRORIST|Unassigned|Spectator)[>]" \[(?P<attackerX>[\-]?[0-9]+) (?P<attackerY>[\-]?[0-9]+) (?P<attackerZ>[\-]?[0-9]+)\] attacked "(?P<victimName>.*)[<](?P<victimId>\d+)[>][<](?P<victimSteamId>.*)[>][<](?P<victimTeam>CT|TERRORIST|Unassigned|Spectator)[>]" \[(?P<victimX>[\-]?[0-9]+) (?P<victimY>[\-]?[0-9]+) (?P<victimZ>[\-]?[0-9]+)\] with "(?P<attackerWeapon>[a-zA-Z0-9_]+)" \(damage "(?P<attackerDamage>[0-9]+)"\) \(damage_armor "(?P<attackerDamageArmor>[0-9]+)"\) \(health "(?P<victimHealth>[0-9]+)"\) \(armor "(?P<victimArmor>[0-9]+)"\) \(hitgroup "(?P<victimHitGroup>.*)"\)/';
10+
11+
public string $type = 'Attack';
12+
13+
public string $attackerName;
14+
15+
public string $attackerId;
16+
17+
public string $attackerSteamId;
18+
19+
public string $attackerTeam;
20+
21+
public int $attackerX;
22+
23+
public int $attackerY;
24+
25+
public int $attackerZ;
26+
27+
public string $attackerWeapon;
28+
29+
public int $attackerDamage;
30+
31+
public int $attackerDamageArmor;
32+
33+
public string $victimHitGroup;
34+
35+
public string $victimName;
36+
37+
public string $victimId;
38+
39+
public string $victimSteamId;
40+
41+
public string $victimTeam;
42+
43+
public int $victimX;
44+
45+
public int $victimY;
46+
47+
public int $victimZ;
48+
49+
public int $victimHealth;
50+
51+
public int $victimArmor;
52+
}

src/CS2/Models/Blinded.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class Blinded extends Model
8+
{
9+
public const PATTERN = '/"(?P<victimName>.+)[<](?P<victimId>\d+)[>][<](?P<victimSteamId>.*)[>][<](?P<victimTeam>CT|TERRORIST|Unassigned|Spectator)[>]" blinded for (?<time>[0-9.]+) by "(?P<throwerName>.+)[<](?P<throwerUserId>\d+)[>][<](?P<throwerSteamId>.*)[>][<](?P<throwerTeam>CT|TERRORIST|Unassigned|Spectator)[>]" from flashbang entindex (?<entindex>[0-9]+)/';
10+
11+
public string $type = 'Blinded';
12+
13+
public string $victimId;
14+
15+
public string $victimName;
16+
17+
public string $victimTeam;
18+
19+
public string $victimSteamId;
20+
21+
public string $throwerUserId;
22+
23+
public string $throwerName;
24+
25+
public string $throwerTeam;
26+
27+
public string $throwerSteamId;
28+
29+
public float $time;
30+
31+
public int $entindex;
32+
}

src/CS2/Models/BombDefusing.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class BombDefusing extends Model
8+
{
9+
public const PATTERN = '/"(?P<userName>.+)[<](?P<userId>\d+)[>][<](?P<steamId>.*)[>][<](?P<userTeam>CT|TERRORIST|Unassigned|Spectator)[>]" triggered "(Begin_Bomb_Defuse_With_Kit|Begin_Bomb_Defuse_Without_Kit)"/';
10+
11+
public string $type = 'BombDefusing';
12+
13+
public string $userId;
14+
15+
public string $userName;
16+
17+
public string $userTeam;
18+
19+
public string $steamId;
20+
}

src/CS2/Models/BombPlanting.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class BombPlanting extends Model
8+
{
9+
public const PATTERN = '/"(?P<userName>.+)[<](?P<userId>\d+)[>][<](?P<steamId>.*)[>][<](?P<userTeam>CT|TERRORIST|Unassigned|Spectator)[>]" triggered "Planted_The_Bomb" at bombsite (?P<bombsite>A|B)/';
10+
11+
public string $type = 'BombPlanting';
12+
13+
public string $userId;
14+
15+
public string $userName;
16+
17+
public string $userTeam;
18+
19+
public string $steamId;
20+
21+
public string $bombsite;
22+
}

src/CS2/Models/ChangeMap.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class ChangeMap extends Model
8+
{
9+
public const PATTERN = '/(Started map|Loading map) "(?P<maps>.*)"/';
10+
11+
public string $type = 'ChangeMap';
12+
13+
public string $maps;
14+
}

src/CS2/Models/ChangeName.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class ChangeName extends Model
8+
{
9+
public const PATTERN = '/"(?P<userName>.+)[<](?P<userId>\d+)[>][<](?P<steamId>.*)[>][<](?P<userTeam>CT|TERRORIST|Unassigned|Spectator)[>]" changed name to "(?P<newName>.*)"/';
10+
11+
public string $type = 'ChangeName';
12+
13+
public string $userId;
14+
15+
public string $userName;
16+
17+
public string $userTeam;
18+
19+
public string $steamId;
20+
21+
public string $newName;
22+
}

src/CS2/Models/Connected.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace CSLog\CS2\Models;
4+
5+
use CSLog\Model;
6+
7+
class Connected extends Model
8+
{
9+
public const PATTERN = '/"(?P<userName>.+)[<](?P<userId>\d+)[>][<](?P<steamId>.*)[>][<][>]" connected, address "(?P<address>.*)"/';
10+
11+
public string $type = 'Connected';
12+
13+
public string $userId;
14+
15+
public string $userName;
16+
17+
public string $steamId;
18+
19+
public string $address;
20+
}

0 commit comments

Comments
 (0)