Skip to content

Commit

Permalink
Merge pull request #1 from boyski33/main
Browse files Browse the repository at this point in the history
add counter-strike 2 log parser
  • Loading branch information
janstuemmel authored Jun 17, 2023
2 parents 6d00056 + ba04ab4 commit 09ed8e6
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 3,011 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# Folders
_obj
_test
vendor/
.idea/

# Dependency directories
/!vendor

# Go specific
*.d
*.test
*.out

# End of file marker
# If you need to ignore any additional files or directories, add them below this line

coverage.out
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
# csgo-log
# cs2-log

Go package for parsing csgo server logfiles. It exports types for csgo logfiles, their regular expressions, a function for parsing and a function for converting to non-html-escaped JSON.
Go package for parsing cs2 server logfiles. It exports types for cs2 logfiles, their regular expressions, a function for
parsing and a function for converting to non-html-escaped JSON.

## Usage

For more examples look at the [tests](./csgolog_test.go) and the command-line utility in [examples folder](./example). Have also a look at [godoc](http://godoc.org/github.com/janstuemmel/csgo-log).
For more examples look at the [tests](./cs2log_test.go) and the command-line utility in [examples folder](./example).
Have also a look at [godoc](http://godoc.org/github.com/janstuemmel/cs2-log).

```go
package main

import (
"fmt"
"fmt"

"github.com/janstuemmel/csgo-log"
"github.com/janstuemmel/cs2-log"
)

func main() {

var msg csgolog.Message
var msg cs2log.Message

// a line from a server logfile
line := `L 11/05/2018 - 15:44:36: "Player<12><STEAM_1:1:0101011><CT>" purchased "m4a1"`
// a line from a server logfile
line := `L 11/05/2018 - 15:44:36: "Player<12><[U:1:29384012]><CT>" purchased "m4a1"`

// parse into Message
msg, err := csgolog.Parse(line)
// parse into Message
msg, err := cs2log.Parse(line)

if err != nil {
panic(err)
}
if err != nil {
panic(err)
}

fmt.Println(msg.GetType(), msg.GetTime().String())
fmt.Println(msg.GetType(), msg.GetTime().String())

// cast Message interface to PlayerPurchase type
playerPurchase, ok := msg.(csgolog.PlayerPurchase)
// cast Message interface to PlayerPurchase type
playerPurchase, ok := msg.(cs2log.PlayerPurchase)

if ok != true {
panic("casting failed")
}
if ok != true {
panic("casting failed")
}

fmt.Println(playerPurchase.Player.SteamID, playerPurchase.Item)
fmt.Println(playerPurchase.Player.SteamID, playerPurchase.Item)

// get json non-htmlescaped
jsn := csgolog.ToJSON(msg)
// get json non-htmlescaped
jsn := cs2log.ToJSON(msg)

fmt.Println(jsn)
fmt.Println(jsn)
}
```

Example JSON output:

```json
{
"time": "2018-11-05T15:44:36Z",
"type": "PlayerPurchase",
"player": {
"name": "Player",
"id": 12,
"steam_id": "STEAM_1:1:0101011",
"steam_id": "[U:1:29384012]",
"side": "CT"
},
"item": "m4a1"
Expand Down
54 changes: 25 additions & 29 deletions csgolog.go → cs2log.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/*
Package csgolog provides utilities for parsing a csgo server logfile.
It exports types for csgo logfiles, their regular expressions, a function
Package cs2log provides utilities for parsing a counter-strike 2 server logfile.
It exports types for cs2 logfiles, their regular expressions, a function
for parsing and a function for converting to non-html-escaped JSON.
Look at the examples for Parse and ToJSON for usage instructions.
You will find a command-line utility in examples folder as well as an
example logfile with ~3000 lines.
*/
package csgolog
package cs2log

import (
"bytes"
Expand Down Expand Up @@ -360,49 +356,49 @@ const (
// TeamNoticePattern regular expression
TeamNoticePattern = `Team "(CT|TERRORIST)" triggered "(\w+)" \(CT "(\d+)"\) \(T "(\d+)"\)`
// PlayerConnectedPattern regular expression
PlayerConnectedPattern = `"(.+)<(\d+)><([\w:]+)><>" connected, address "(.*)"`
PlayerConnectedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><>" connected, address "(.*)"`
// PlayerDisconnectedPattern regular expression
PlayerDisconnectedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT|Unassigned|)>" disconnected \(reason "(.+)"\)`
PlayerDisconnectedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT|Unassigned|)>" disconnected \(reason "(.+)"\)`
// PlayerEnteredPattern regular expression
PlayerEnteredPattern = `"(.+)<(\d+)><([\w:]+)><>" entered the game`
PlayerEnteredPattern = `"(.+)<(\d+)><([\[\]\w:]+)><>" entered the game`
// PlayerBannedPattern regular expression
PlayerBannedPattern = `Banid: "(.+)<(\d+)><([\w:]+)><\w*>" was banned "([\w. ]+)" by "(\w+)"`
PlayerBannedPattern = `Banid: "(.+)<(\d+)><([\[\]\w:]+)><\w*>" was banned "([\w. ]+)" by "(\w+)"`
// PlayerSwitchedPattern regular expression
PlayerSwitchedPattern = `"(.+)<(\d+)><([\w:]+)>" switched from team <(Unassigned|Spectator|TERRORIST|CT)> to <(Unassigned|Spectator|TERRORIST|CT)>`
PlayerSwitchedPattern = `"(.+)<(\d+)><([\[\]\w:]+)>" switched from team <(Unassigned|Spectator|TERRORIST|CT)> to <(Unassigned|Spectator|TERRORIST|CT)>`
// PlayerSayPattern regular expression
PlayerSayPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" say(_team)? "(.*)"`
PlayerSayPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" say(_team)? "(.*)"`
// PlayerPurchasePattern regular expression
PlayerPurchasePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" purchased "(\w+)"`
PlayerPurchasePattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" purchased "(\w+)"`
// PlayerKillPattern regular expression
PlayerKillPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] killed "(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] with "(\w+)" ?(\(?(headshot|penetrated|headshot penetrated)?\))?`
PlayerKillPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] killed "(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] with "(\w+)" ?(\(?(headshot|penetrated|headshot penetrated)?\))?`
// PlayerKillAssistPattern regular expression
PlayerKillAssistPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" assisted killing "(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>"`
PlayerKillAssistPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" assisted killing "(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>"`
// PlayerAttackPattern regular expression
PlayerAttackPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] attacked "(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] with "(\w+)" \(damage "(\d+)"\) \(damage_armor "(\d+)"\) \(health "(\d+)"\) \(armor "(\d+)"\) \(hitgroup "([\w ]+)"\)`
PlayerAttackPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] attacked "(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] with "(\w+)" \(damage "(\d+)"\) \(damage_armor "(\d+)"\) \(health "(\d+)"\) \(armor "(\d+)"\) \(hitgroup "([\w ]+)"\)`
// PlayerKilledBombPattern regular expression
PlayerKilledBombPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] was killed by the bomb\.`
PlayerKilledBombPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] was killed by the bomb\.`
// PlayerKilledSuicidePattern regular expression
PlayerKilledSuicidePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] committed suicide with "(.*)"`
PlayerKilledSuicidePattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" \[(-?\d+) (-?\d+) (-?\d+)\] committed suicide with "(.*)"`
// PlayerPickedUpPattern regular expression
PlayerPickedUpPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" picked up "(\w+)"`
PlayerPickedUpPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" picked up "(\w+)"`
// PlayerDroppedPattern regular expression
PlayerDroppedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT|Unassigned)>" dropped "(\w+)"`
PlayerDroppedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT|Unassigned)>" dropped "(\w+)"`
// PlayerMoneyChangePattern regular expression
PlayerMoneyChangePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" money change (\d+)\+?(-?\d+) = \$(\d+) \(tracked\)( \(purchase: (\w+)\))?`
PlayerMoneyChangePattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" money change (\d+)\+?(-?\d+) = \$(\d+) \(tracked\)( \(purchase: (\w+)\))?`
// PlayerBombGotPattern regular expression
PlayerBombGotPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Got_The_Bomb"`
PlayerBombGotPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" triggered "Got_The_Bomb"`
// PlayerBombPlantedPattern regular expression
PlayerBombPlantedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Planted_The_Bomb"`
PlayerBombPlantedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" triggered "Planted_The_Bomb"`
// PlayerBombDroppedPattern regular expression
PlayerBombDroppedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Dropped_The_Bomb"`
PlayerBombDroppedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" triggered "Dropped_The_Bomb"`
// PlayerBombBeginDefusePattern regular expression
PlayerBombBeginDefusePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Begin_Bomb_Defuse_With(out)?_Kit"`
PlayerBombBeginDefusePattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" triggered "Begin_Bomb_Defuse_With(out)?_Kit"`
// PlayerBombDefusedPattern regular expression
PlayerBombDefusedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Defused_The_Bomb"`
PlayerBombDefusedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" triggered "Defused_The_Bomb"`
// PlayerThrewPattern regular expression
PlayerThrewPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" threw (\w+) \[(-?\d+) (-?\d+) (-?\d+)\]( flashbang entindex (\d+))?\)?`
PlayerThrewPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" threw (\w+) \[(-?\d+) (-?\d+) (-?\d+)\]( flashbang entindex (\d+))?\)?`
// PlayerBlindedPattern regular expression
PlayerBlindedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" blinded for ([\d.]+) by "(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" from flashbang entindex (\d+)`
PlayerBlindedPattern = `"(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" blinded for ([\d.]+) by "(.+)<(\d+)><([\[\]\w:]+)><(TERRORIST|CT)>" from flashbang entindex (\d+)`
// ProjectileSpawnedPattern regular expression
ProjectileSpawnedPattern = `Molotov projectile spawned at (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+), velocity (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+)`
// GameOverPattern regular expression
Expand Down
Loading

0 comments on commit 09ed8e6

Please sign in to comment.