update
This commit is contained in:
parent
2cadb34efd
commit
aa208a14d4
103
main.go
103
main.go
@ -12,6 +12,12 @@ import (
|
|||||||
msg "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/msgs2"
|
msg "github.com/markus-wa/demoinfocs-golang/v4/pkg/demoinfocs/msgs2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Team struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Score int `json:"score"`
|
||||||
|
Players []PlayerStats `json:"players"`
|
||||||
|
}
|
||||||
|
|
||||||
type PlayerStats struct {
|
type PlayerStats struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
SteamID string `json:"steamId"`
|
SteamID string `json:"steamId"`
|
||||||
@ -45,19 +51,18 @@ type RoundResult struct {
|
|||||||
WinReason string `json:"winReason"`
|
WinReason string `json:"winReason"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PlayerTeamHistory map[int]map[uint64]string
|
||||||
|
|
||||||
type DemoMeta struct {
|
type DemoMeta struct {
|
||||||
MatchID uint64 `json:"matchId"`
|
MatchID uint64 `json:"matchId"`
|
||||||
Map string `json:"map"`
|
Map string `json:"map"`
|
||||||
Players []PlayerStats `json:"players"`
|
|
||||||
Duration float64 `json:"duration"`
|
Duration float64 `json:"duration"`
|
||||||
TickRate float64 `json:"tickRate"`
|
TickRate float64 `json:"tickRate"`
|
||||||
ScoreCT int `json:"scoreCT"`
|
|
||||||
ScoreT int `json:"scoreT"`
|
|
||||||
TeamCT string `json:"teamCT"`
|
|
||||||
TeamT string `json:"teamT"`
|
|
||||||
WinnerTeam string `json:"winnerTeam"`
|
WinnerTeam string `json:"winnerTeam"`
|
||||||
RoundCount int `json:"roundCount"`
|
RoundCount int `json:"roundCount"`
|
||||||
RoundHistory []RoundResult `json:"roundHistory"`
|
RoundHistory []RoundResult `json:"roundHistory"`
|
||||||
|
TeamA Team `json:"teamA"`
|
||||||
|
TeamB Team `json:"teamB"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanitizeFloat(value float64) float64 {
|
func sanitizeFloat(value float64) float64 {
|
||||||
@ -96,6 +101,12 @@ func reasonToString(reason events.RoundEndReason) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseSteamID(id string) (uint64, error) {
|
||||||
|
var sid uint64
|
||||||
|
_, err := fmt.Sscanf(id, "%d", &sid)
|
||||||
|
return sid, err
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Println("❌ Demo-Datei fehlt")
|
fmt.Println("❌ Demo-Datei fehlt")
|
||||||
@ -116,6 +127,7 @@ func main() {
|
|||||||
var matchId uint64
|
var matchId uint64
|
||||||
var scoreCT, scoreT, roundCount int
|
var scoreCT, scoreT, roundCount int
|
||||||
var roundHistory []RoundResult
|
var roundHistory []RoundResult
|
||||||
|
var teamHistory = make(PlayerTeamHistory)
|
||||||
|
|
||||||
if len(os.Args) >= 3 {
|
if len(os.Args) >= 3 {
|
||||||
inputId := os.Args[2]
|
inputId := os.Args[2]
|
||||||
@ -139,7 +151,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playerStats := make(map[uint64]*PlayerStats)
|
playerStats := make(map[uint64]*PlayerStats)
|
||||||
playerInitialTeams := make(map[uint64]string)
|
|
||||||
|
|
||||||
getOrCreate := func(player common.Player) *PlayerStats {
|
getOrCreate := func(player common.Player) *PlayerStats {
|
||||||
sid := player.SteamID64
|
sid := player.SteamID64
|
||||||
@ -148,25 +159,26 @@ func main() {
|
|||||||
stat = &PlayerStats{
|
stat = &PlayerStats{
|
||||||
Name: player.Name,
|
Name: player.Name,
|
||||||
SteamID: fmt.Sprintf("%d", sid),
|
SteamID: fmt.Sprintf("%d", sid),
|
||||||
Team: "", // später gesetzt
|
Team: "",
|
||||||
}
|
}
|
||||||
playerStats[sid] = stat
|
playerStats[sid] = stat
|
||||||
}
|
}
|
||||||
return stat
|
return stat
|
||||||
}
|
}
|
||||||
|
|
||||||
p.RegisterEventHandler(func(e events.MatchStart) {
|
p.RegisterEventHandler(func(e events.RoundStart) {
|
||||||
for _, player := range p.GameState().Participants().Playing() {
|
round := roundCount + 1 // nächste Runde
|
||||||
switch player.Team {
|
teamHistory[round] = map[uint64]string{}
|
||||||
case common.TeamTerrorists:
|
|
||||||
playerInitialTeams[player.SteamID64] = "T"
|
for _, p := range p.GameState().Participants().Playing() {
|
||||||
case common.TeamCounterTerrorists:
|
if p.Team == common.TeamCounterTerrorists {
|
||||||
playerInitialTeams[player.SteamID64] = "CT"
|
teamHistory[round][p.SteamID64] = "CT"
|
||||||
|
} else if p.Team == common.TeamTerrorists {
|
||||||
|
teamHistory[round][p.SteamID64] = "T"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Eventhandler (Kill, Hurt, etc.)
|
|
||||||
p.RegisterEventHandler(func(e events.Kill) {
|
p.RegisterEventHandler(func(e events.Kill) {
|
||||||
if e.Killer != nil && e.Killer.SteamID64 != e.Victim.SteamID64 {
|
if e.Killer != nil && e.Killer.SteamID64 != e.Victim.SteamID64 {
|
||||||
stat := getOrCreate(*e.Killer)
|
stat := getOrCreate(*e.Killer)
|
||||||
@ -218,7 +230,7 @@ func main() {
|
|||||||
stat.TotalDamage += e.HealthDamage
|
stat.TotalDamage += e.HealthDamage
|
||||||
if e.Weapon != nil {
|
if e.Weapon != nil {
|
||||||
switch e.Weapon.Type {
|
switch e.Weapon.Type {
|
||||||
case common.EqHE, common.EqIncendiary, common.EqMolotov:
|
case common.EqHE, common.EqMolotov, common.EqIncendiary:
|
||||||
stat.UtilityDamage += e.HealthDamage
|
stat.UtilityDamage += e.HealthDamage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,20 +290,37 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
teamCT := p.GameState().TeamCounterTerrorists().ClanName()
|
teamAName := p.GameState().TeamCounterTerrorists().ClanName()
|
||||||
if teamCT == "" {
|
if teamAName == "" {
|
||||||
teamCT = "CT"
|
teamAName = "CT"
|
||||||
|
}
|
||||||
|
teamBName := p.GameState().TeamTerrorists().ClanName()
|
||||||
|
if teamBName == "" {
|
||||||
|
teamBName = "T"
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, stat := range playerStats {
|
||||||
|
sid, _ := parseSteamID(stat.SteamID)
|
||||||
|
if team, ok := teamHistory[1][sid]; ok {
|
||||||
|
stat.Team = team
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ctPlayers, tPlayers []PlayerStats
|
||||||
|
for _, stat := range playerStats {
|
||||||
|
switch stat.Team {
|
||||||
|
case "CT":
|
||||||
|
ctPlayers = append(ctPlayers, *stat)
|
||||||
|
case "T":
|
||||||
|
tPlayers = append(tPlayers, *stat)
|
||||||
}
|
}
|
||||||
teamT := p.GameState().TeamTerrorists().ClanName()
|
|
||||||
if teamT == "" {
|
|
||||||
teamT = "T"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
winnerTeam := "Draw"
|
winnerTeam := "Draw"
|
||||||
if scoreCT > scoreT {
|
if scoreCT > scoreT {
|
||||||
winnerTeam = teamCT
|
winnerTeam = teamAName
|
||||||
} else if scoreT > scoreCT {
|
} else if scoreT > scoreCT {
|
||||||
winnerTeam = teamT
|
winnerTeam = teamBName
|
||||||
}
|
}
|
||||||
|
|
||||||
duration := sanitizeFloat(header.PlaybackTime.Seconds())
|
duration := sanitizeFloat(header.PlaybackTime.Seconds())
|
||||||
@ -309,25 +338,19 @@ func main() {
|
|||||||
Map: mapName,
|
Map: mapName,
|
||||||
Duration: duration,
|
Duration: duration,
|
||||||
TickRate: tickRate,
|
TickRate: tickRate,
|
||||||
ScoreCT: scoreCT,
|
|
||||||
ScoreT: scoreT,
|
|
||||||
TeamCT: teamCT,
|
|
||||||
TeamT: teamT,
|
|
||||||
WinnerTeam: winnerTeam,
|
WinnerTeam: winnerTeam,
|
||||||
RoundCount: roundCount,
|
RoundCount: roundCount,
|
||||||
RoundHistory: roundHistory,
|
RoundHistory: roundHistory,
|
||||||
}
|
TeamA: Team{
|
||||||
|
Name: teamAName,
|
||||||
// Final: Teamzuweisung korrekt, keine Überschreibung
|
Score: scoreCT,
|
||||||
for sid, stat := range playerStats {
|
Players: ctPlayers,
|
||||||
if stat.Team == "" || stat.Team == "Unknown" {
|
},
|
||||||
if team, ok := playerInitialTeams[sid]; ok {
|
TeamB: Team{
|
||||||
stat.Team = team
|
Name: teamBName,
|
||||||
} else {
|
Score: scoreT,
|
||||||
stat.Team = "Unknown"
|
Players: tPlayers,
|
||||||
}
|
},
|
||||||
}
|
|
||||||
result.Players = append(result.Players, *stat)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonData, err := json.Marshal(result)
|
jsonData, err := json.Marshal(result)
|
||||||
|
|||||||
BIN
parser_cs2-linux
BIN
parser_cs2-linux
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user