Documentation ¶
Overview ¶
Package csgolog provides utilities for parsing a csgo server logfile. It exports types for csgo 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.
Index ¶
- Constants
- Variables
- func ToJSON(m Message) string
- type Equation
- type FreezTimeStart
- type GameOver
- type Get5Event
- type Get5EventParams
- type Get5Events
- type Message
- func NewFreezTimeStart(ti time.Time, r []string) Message
- func NewGameOver(ti time.Time, r []string) Message
- func NewGet5Event(ti time.Time, r []string) Message
- func NewPlayerAttack(ti time.Time, r []string) Message
- func NewPlayerBanned(ti time.Time, r []string) Message
- func NewPlayerBlinded(ti time.Time, r []string) Message
- func NewPlayerBombBeginDefuse(ti time.Time, r []string) Message
- func NewPlayerBombDefused(ti time.Time, r []string) Message
- func NewPlayerBombDropped(ti time.Time, r []string) Message
- func NewPlayerBombGot(ti time.Time, r []string) Message
- func NewPlayerBombPlanted(ti time.Time, r []string) Message
- func NewPlayerConnected(ti time.Time, r []string) Message
- func NewPlayerDisconnected(ti time.Time, r []string) Message
- func NewPlayerDropped(ti time.Time, r []string) Message
- func NewPlayerEntered(ti time.Time, r []string) Message
- func NewPlayerKill(ti time.Time, r []string) Message
- func NewPlayerKillAssist(ti time.Time, r []string) Message
- func NewPlayerKillOther(ti time.Time, r []string) Message
- func NewPlayerKilledBomb(ti time.Time, r []string) Message
- func NewPlayerKilledSuicide(ti time.Time, r []string) Message
- func NewPlayerMoneyChange(ti time.Time, r []string) Message
- func NewPlayerPickedUp(ti time.Time, r []string) Message
- func NewPlayerPurchase(ti time.Time, r []string) Message
- func NewPlayerSay(ti time.Time, r []string) Message
- func NewPlayerSwitched(ti time.Time, r []string) Message
- func NewPlayerThrew(ti time.Time, r []string) Message
- func NewProjectileSpawned(ti time.Time, r []string) Message
- func NewRconEvent(ti time.Time, r []string) Message
- func NewServerCvar(ti time.Time, r []string) Message
- func NewServerMessage(ti time.Time, r []string) Message
- func NewTeamNotice(ti time.Time, r []string) Message
- func NewTeamScored(ti time.Time, r []string) Message
- func NewUnknown(ti time.Time, r []string) Message
- func NewWorldGameCommencing(ti time.Time, r []string) Message
- func NewWorldMatchStart(ti time.Time, r []string) Message
- func NewWorldRoundEnd(ti time.Time, r []string) Message
- func NewWorldRoundRestart(ti time.Time, r []string) Message
- func NewWorldRoundStart(ti time.Time, r []string) Message
- func Parse(line string) (Message, error)
- func ParseWithPatterns(line string, patterns map[*regexp.Regexp]MessageFunc) (Message, error)
- type MessageFunc
- type Meta
- type Player
- type PlayerAttack
- type PlayerBanned
- type PlayerBlinded
- type PlayerBombBeginDefuse
- type PlayerBombDefused
- type PlayerBombDropped
- type PlayerBombGot
- type PlayerBombPlanted
- type PlayerConnected
- type PlayerDisconnected
- type PlayerDropped
- type PlayerEntered
- type PlayerKill
- type PlayerKillAssist
- type PlayerKillOther
- type PlayerKilledBomb
- type PlayerKilledSuicide
- type PlayerMoneyChange
- type PlayerPickedUp
- type PlayerPurchase
- type PlayerSay
- type PlayerSwitched
- type PlayerThrew
- type Position
- type PositionFloat
- type ProjectileSpawned
- type Rcon
- type ServerCvar
- type ServerMessage
- type TeamNotice
- type TeamScored
- type Unknown
- type Velocity
- type WorldGameCommencing
- type WorldMatchStart
- type WorldRoundEnd
- type WorldRoundRestart
- type WorldRoundStart
Examples ¶
Constants ¶
const ( // ServerMessagePattern regular expression ServerMessagePattern = `server_message: "(\w+)"` // FreezTimeStartPattern regular expression FreezTimeStartPattern = `Starting Freeze period` // WorldMatchStartPattern regular expression WorldMatchStartPattern = `World triggered "Match_Start" on "(\w+)"` // WorldRoundStartPattern regular expression WorldRoundStartPattern = `World triggered "Round_Start"` // WorldRoundRestartPattern regular expression WorldRoundRestartPattern = `World triggered "Restart_Round_\((\d+)_second\)` // WorldRoundEndPattern regular expression WorldRoundEndPattern = `World triggered "Round_End"` // WorldGameCommencingPattern regular expression WorldGameCommencingPattern = `World triggered "Game_Commencing"` // TeamScoredPattern regular expression TeamScoredPattern = `Team "(CT|TERRORIST)" scored "(\d+)" with "(\d+)" players` // TeamNoticePattern regular expression TeamNoticePattern = `Team "(CT|TERRORIST)" triggered "(\w+)" \(CT "(\d+)"\) \(T "(\d+)"\)` // PlayerConnectedPattern regular expression PlayerConnectedPattern = `"(.+)<(\d+)><([\w:]+)><>" connected, address "(.*)"` // PlayerDisconnectedPattern regular expression PlayerDisconnectedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT|Unassigned|)>" disconnected \(reason "(.+)"\)` // PlayerEnteredPattern regular expression PlayerEnteredPattern = `"(.+)<(\d+)><([\w:]+)><>" entered the game` // PlayerBannedPattern regular expression 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)>` // PlayerSayPattern regular expression PlayerSayPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" say(_team)? "(.*)"` // PlayerPurchasePattern regular expression PlayerPurchasePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" purchased "(\w+)"` // PlayerKillPattern regular expression PlayerKillPattern = `` /* 207-byte string literal not displayed */ // PlayerKillAssistPattern regular expression PlayerKillAssistPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" assisted killing "(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>"` // PlayerAttackPattern regular expression PlayerAttackPattern = `` /* 262-byte string literal not displayed */ // PlayerKilledBombPattern regular expression 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 "(.*)"` // PlayerPickedUpPattern regular expression PlayerPickedUpPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" picked up "(\w+)"` // PlayerDroppedPattern regular expression PlayerDroppedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT|Unassigned)>" dropped "(\w+)"` // PlayerMoneyChangePattern regular expression 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"` // PlayerBombPlantedPattern regular expression PlayerBombPlantedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Planted_The_Bomb"` // PlayerBombDroppedPattern regular expression PlayerBombDroppedPattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Dropped_The_Bomb"` // PlayerBombBeginDefusePattern regular expression PlayerBombBeginDefusePattern = `"(.+)<(\d+)><([\w:]+)><(TERRORIST|CT)>" triggered "Begin_Bomb_Defuse_With(out)?_Kit"` // PlayerBombDefusedPattern regular expression 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+))?\)?` // PlayerBlindedPattern regular expression PlayerBlindedPattern = `` /* 133-byte string literal not displayed */ // ProjectileSpawnedPattern regular expression ProjectileSpawnedPattern = `Molotov projectile spawned at (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+), velocity (-?\d+\.\d+) (-?\d+\.\d+) (-?\d+\.\d+)` // GameOverPattern regular expression GameOverPattern = `Game Over: (\w+) (\w+) (\w+) score (\d+):(\d+) after (\d+) min` // ServerCvarPattern regular expression ServerCvarPattern = `server_cvar: "(\w+)" "(.*)"` // Get5EventPattern regular expression Get5EventPattern = `` /* 334-byte string literal not displayed */ // RconEventPattern regular expression RconEventPattern = `rcon from "(.*):(\d+)": command "(.*)"` // PlayerKillOtherPattern regular expression PlayerKillOtherPattern = `` /* 135-byte string literal not displayed */ )
Variables ¶
var DefaultPatterns = map[*regexp.Regexp]MessageFunc{ regexp.MustCompile(ServerMessagePattern): NewServerMessage, regexp.MustCompile(FreezTimeStartPattern): NewFreezTimeStart, regexp.MustCompile(WorldMatchStartPattern): NewWorldMatchStart, regexp.MustCompile(WorldRoundStartPattern): NewWorldRoundStart, regexp.MustCompile(WorldRoundRestartPattern): NewWorldRoundRestart, regexp.MustCompile(WorldRoundEndPattern): NewWorldRoundEnd, regexp.MustCompile(WorldGameCommencingPattern): NewWorldGameCommencing, regexp.MustCompile(TeamScoredPattern): NewTeamScored, regexp.MustCompile(TeamNoticePattern): NewTeamNotice, regexp.MustCompile(PlayerConnectedPattern): NewPlayerConnected, regexp.MustCompile(PlayerDisconnectedPattern): NewPlayerDisconnected, regexp.MustCompile(PlayerEnteredPattern): NewPlayerEntered, regexp.MustCompile(PlayerBannedPattern): NewPlayerBanned, regexp.MustCompile(PlayerSwitchedPattern): NewPlayerSwitched, regexp.MustCompile(PlayerSayPattern): NewPlayerSay, regexp.MustCompile(PlayerPurchasePattern): NewPlayerPurchase, regexp.MustCompile(PlayerKillPattern): NewPlayerKill, regexp.MustCompile(PlayerKillAssistPattern): NewPlayerKillAssist, regexp.MustCompile(PlayerAttackPattern): NewPlayerAttack, regexp.MustCompile(PlayerKilledBombPattern): NewPlayerKilledBomb, regexp.MustCompile(PlayerKilledSuicidePattern): NewPlayerKilledSuicide, regexp.MustCompile(PlayerPickedUpPattern): NewPlayerPickedUp, regexp.MustCompile(PlayerDroppedPattern): NewPlayerDropped, regexp.MustCompile(PlayerMoneyChangePattern): NewPlayerMoneyChange, regexp.MustCompile(PlayerBombGotPattern): NewPlayerBombGot, regexp.MustCompile(PlayerBombPlantedPattern): NewPlayerBombPlanted, regexp.MustCompile(PlayerBombDroppedPattern): NewPlayerBombDropped, regexp.MustCompile(PlayerBombBeginDefusePattern): NewPlayerBombBeginDefuse, regexp.MustCompile(PlayerBombDefusedPattern): NewPlayerBombDefused, regexp.MustCompile(PlayerThrewPattern): NewPlayerThrew, regexp.MustCompile(PlayerBlindedPattern): NewPlayerBlinded, regexp.MustCompile(ProjectileSpawnedPattern): NewProjectileSpawned, regexp.MustCompile(GameOverPattern): NewGameOver, regexp.MustCompile(ServerCvarPattern): NewServerCvar, regexp.MustCompile(Get5EventPattern): NewGet5Event, regexp.MustCompile(RconEventPattern): NewRconEvent, regexp.MustCompile(PlayerKillOtherPattern): NewPlayerKillOther, }
var ErrorNoMatch = errors.New("no match")
ErrorNoMatch error when pattern is not matching
var HTTPLinePattern = regexp.MustCompile(`(\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}.\d{3}) - (.*)`)
HTTPLinePattern is the regular expression to capture a line of a HTTP logging
var LogLinePattern = regexp.MustCompile(`L (\d{2}\/\d{2}\/\d{4} - \d{2}:\d{2}:\d{2}): (.*)`)
LogLinePattern is the regular expression to capture a line of a logfile
Functions ¶
func ToJSON ¶
ToJSON marshals messages to JSON without escaping html
Example ¶
// parse Message msg, _ := Parse(`L 11/05/2018 - 15:44:36: "Player-Name<12><STEAM_1:1:0101011><CT>" purchased "m4a1"`) // cast Message interface type to PlayerPurchase type playerPurchase, _ := msg.(PlayerPurchase) fmt.Println(playerPurchase.Player.SteamID) fmt.Println(playerPurchase.Item) // get json non-html-escaped jsn := ToJSON(msg) fmt.Println(jsn)
Output: STEAM_1:1:0101011 m4a1 {"time":"2018-11-05T15:44:36Z","type":"PlayerPurchase","player":{"name":"Player-Name","id":12,"steam_id":"STEAM_1:1:0101011","side":"CT"},"item":"m4a1"}
Types ¶
type Equation ¶
Equation holds the parameters and result of a money change equation in the form A + B = Result
type FreezTimeStart ¶
type FreezTimeStart struct{ Meta }
FreezTimeStart is received before each round
type GameOver ¶
type GameOver struct { Meta Mode string `json:"mode"` MapGroup string `json:"map_group"` Map string `json:"map"` ScoreCT int `json:"score_ct"` ScoreT int `json:"score_t"` Duration int `json:"duration"` }
GameOver is received when a team won and the game ends
type Get5Event ¶
type Get5Event struct { Meta Matchid string `json:"matchid"` Params Get5EventParams `json:"params"` Event string `json:"event"` }
type Get5EventParams ¶
type Get5EventParams struct { MapNumber int `json:"map_number,omitempty"` MapName string `json:"map_name,omitempty"` Team1Name string `json:"team1_name,omitempty"` Team1Score int `json:"team1_score,omitempty"` Team1SeriesScore int `json:"team1_series_score,omitempty"` Team2Name string `json:"team2_name,omitempty"` Team2Score int `json:"team2_score,omitempty"` Team2SeriesScore int `json:"team2_series_score,omitempty"` Headshot int `json:"headshot,omitempty"` Weapon string `json:"weapon,omitempty"` Reason int `json:"reason,omitempty"` Message string `json:"message,omitempty"` File string `json:"file,omitempty"` Site int `json:"site,omitempty"` Stage string `json:"stage,omitempty"` Victim string `json:"victim"` Attacker string `json:"attacker"` Winner string `json:"winner"` WinnerSide string `json:"winner_side"` }
type Get5Events ¶
type Get5Events string
Get5Event event types(enum)
const ( Get5SeriesStart Get5Events = "series_start" Get5MapVeto Get5Events = "map_veto" Get5MapPick Get5Events = "map_pick" Get5SidePicked Get5Events = "side_picked" Get5KnifeStart Get5Events = "knife_start" Get5KnifeWon Get5Events = "knife_won" Get5GoingLive Get5Events = "going_live" Get5PlayerDeath Get5Events = "player_death" Get5RoundEnd Get5Events = "round_end" Get5SideSwap Get5Events = "side_swap" Get5MapEnd Get5Events = "map_end" Get5SeriesEnd Get5Events = "series_end" Get5BackupLoaded Get5Events = "backup_loaded" Get5MatchConfigLoadFail Get5Events = "match_config_load_fail" Get5ClientSay Get5Events = "client_say" Get5BombPlanted Get5Events = "bomb_planted" Get5BombDefused Get5Events = "bomb_defused" Get5BombExploded Get5Events = "bomb_exploded" Get5PlayerConnected Get5Events = "player_connect" Get5PlayerDisconnect Get5Events = "player_disconnect" Get5TeamReady Get5Events = "team_ready" Get5TeamUnready Get5Events = "team_unready" )
type Message ¶
Message is the interface for all messages
func Parse ¶
Parse parses a plain log message and returns message type or error if there's no match
Example ¶
var msg Message // a line from a server logfile line := `L 11/05/2018 - 15:44:36: "Player-Name<12><STEAM_1:1:0101011><CT>" purchased "m4a1"` // parse Message msg, _ = Parse(line) fmt.Println(msg.GetType()) fmt.Println(msg.GetTime().String())
Output: PlayerPurchase 2018-11-05 15:44:36 +0000 UTC
func ParseWithPatterns ¶
Parse attempts to match a plain log message against the map of provided patterns, if the line matches a key from the map, the corresponding MessageFunc is called on the line to parse it into a Message
type Player ¶
type Player struct { Name string `json:"name"` ID int `json:"id"` SteamID string `json:"steam_id"` Side string `json:"side"` }
Player holds the information about a player known from log
type PlayerAttack ¶
type PlayerAttack struct { Meta Attacker Player `json:"attacker"` AttackerPosition Position `json:"attacker_pos"` Victim Player `json:"victim"` VictimPosition Position `json:"victim_pos"` Weapon string `json:"weapon"` Damage int `json:"damage"` DamageArmor int `json:"damage_armor"` Health int `json:"health"` Armor int `json:"armor"` Hitgroup string `json:"hitgroup"` }
PlayerAttack is recieved when a player attacks another
type PlayerBanned ¶
type PlayerBanned struct { Meta Player Player `json:"player"` Duration string `json:"duration"` By string `json:"by"` }
PlayerBanned is received when a player gots banned from the server
type PlayerBlinded ¶
type PlayerBlinded struct { Meta Attacker Player `json:"attacker"` Victim Player `json:"victim"` For float32 `json:"for"` Entindex int `json:"entindex"` }
PlayerBlinded is received when a player got blinded
type PlayerBombBeginDefuse ¶
PlayerBombBeginDefuse is received when a player begins defusing the bomb
type PlayerBombDefused ¶
PlayerBombDefused is received when a player defused the bomb
type PlayerBombDropped ¶
PlayerBombDropped is received when a player drops the bomb
type PlayerBombGot ¶
PlayerBombGot is received when a player picks up the bomb
type PlayerBombPlanted ¶
PlayerBombPlanted is received when a player plants the bomb
type PlayerConnected ¶
PlayerConnected message is received when a player connects and holds the address from where the player is connecting
type PlayerDisconnected ¶
PlayerDisconnected is received when a player disconnets and holds the reason why the player left
type PlayerDropped ¶
PlayerDropped is recieved when a player drops an item
type PlayerEntered ¶
PlayerEntered is received when a player enters the game
type PlayerKill ¶
type PlayerKill struct { Meta Attacker Player `json:"attacker"` AttackerPosition Position `json:"attacker_pos"` Victim Player `json:"victim"` VictimPosition Position `json:"victim_pos"` Weapon string `json:"weapon"` Headshot bool `json:"headshot"` Penetrated bool `json:"penetrated"` }
PlayerKill is received when a player kills another
type PlayerKillAssist ¶
type PlayerKillAssist struct { Meta Attacker Player `json:"attacker"` Victim Player `json:"victim"` }
PlayerKillAssist is received when a player assisted killing another
type PlayerKillOther ¶
type PlayerKillOther struct { Meta Attacker Player `json:"attacker"` AttackerPosition Position `json:"attacker_pos"` Victim string `json:"victim"` VictimID string `json:"victim_id"` VictimPosition Position `json:"victim_pos"` Weapon string `json:"weapon"` }
PlayerKillOther is received when a player destroys map resources
type PlayerKilledBomb ¶
PlayerKilledBomb is received when a player is killed by the bomb
type PlayerKilledSuicide ¶
type PlayerKilledSuicide struct { Meta Player Player `json:"player"` Position Position `json:"pos"` With string `json:"with"` }
PlayerKilledSuicide is received when a player commited suicide
type PlayerMoneyChange ¶
type PlayerMoneyChange struct { Meta Player Player `json:"player"` Equation Equation `json:"equation"` Purchase string `json:"purchase"` }
PlayerMoneyChange is received when a player loses or receives money TODO: add before +-money
type PlayerPickedUp ¶
PlayerPickedUp is received when a player picks up an item
type PlayerPurchase ¶
PlayerPurchase holds info about which player bought an item
type PlayerSay ¶
type PlayerSay struct { Meta Player Player `json:"player"` Text string `json:"text"` Team bool `json:"team"` }
PlayerSay is received when a player writes into chat
type PlayerSwitched ¶
type PlayerSwitched struct { Meta Player Player `json:"player"` From string `json:"from"` To string `json:"to"` }
PlayerSwitched is received when a player switches sides
type PlayerThrew ¶
type PlayerThrew struct { Meta Player Player `json:"player"` Position Position `json:"pos"` Entindex int `json:"entindex"` Grenade string `json:"grenade"` }
PlayerThrew is received when a player threw a grenade
type PositionFloat ¶
PositionFloat holds more exact coords
type ProjectileSpawned ¶
type ProjectileSpawned struct { Meta Position PositionFloat `json:"pos"` Velocity Velocity `json:"velocity"` }
ProjectileSpawned is received when a molotov spawned
type ServerCvar ¶
type ServerMessage ¶
ServerMessage is received on a server event
type TeamNotice ¶
type TeamNotice struct { Meta Side string `json:"side"` Notice string `json:"notice"` ScoreCT int `json:"score_ct"` ScoreT int `json:"score_t"` }
TeamNotice message is received at the end of a round and holds information about which team won the round and the score
type TeamScored ¶
type TeamScored struct { Meta Side string `json:"side"` Score int `json:"score"` NumPlayers int `json:"num_players"` }
TeamScored is received at the end of each round and holds the scores for a team
type Unknown ¶
Unknown holds the raw log message of a message that is not defined in patterns but starts with time
type WorldGameCommencing ¶
type WorldGameCommencing struct{ Meta }
WorldGameCommencing message is received when a game is commencing
type WorldMatchStart ¶
WorldMatchStart holds the map wich will be played when match starts
type WorldRoundEnd ¶
type WorldRoundEnd struct{ Meta }
WorldRoundEnd message is received when a round ends
type WorldRoundRestart ¶
WorldRoundRestart is received when the server wants to restart a round
type WorldRoundStart ¶
type WorldRoundStart struct{ Meta }
WorldRoundStart message is received when a new round starts