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"
|
||||
)
|
||||
|
||||
type Team struct {
|
||||
Name string `json:"name"`
|
||||
Score int `json:"score"`
|
||||
Players []PlayerStats `json:"players"`
|
||||
}
|
||||
|
||||
type PlayerStats struct {
|
||||
Name string `json:"name"`
|
||||
SteamID string `json:"steamId"`
|
||||
@ -45,19 +51,18 @@ type RoundResult struct {
|
||||
WinReason string `json:"winReason"`
|
||||
}
|
||||
|
||||
type PlayerTeamHistory map[int]map[uint64]string
|
||||
|
||||
type DemoMeta struct {
|
||||
MatchID uint64 `json:"matchId"`
|
||||
Map string `json:"map"`
|
||||
Players []PlayerStats `json:"players"`
|
||||
Duration float64 `json:"duration"`
|
||||
TickRate float64 `json:"tickRate"`
|
||||
ScoreCT int `json:"scoreCT"`
|
||||
ScoreT int `json:"scoreT"`
|
||||
TeamCT string `json:"teamCT"`
|
||||
TeamT string `json:"teamT"`
|
||||
WinnerTeam string `json:"winnerTeam"`
|
||||
RoundCount int `json:"roundCount"`
|
||||
RoundHistory []RoundResult `json:"roundHistory"`
|
||||
TeamA Team `json:"teamA"`
|
||||
TeamB Team `json:"teamB"`
|
||||
}
|
||||
|
||||
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() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("❌ Demo-Datei fehlt")
|
||||
@ -116,6 +127,7 @@ func main() {
|
||||
var matchId uint64
|
||||
var scoreCT, scoreT, roundCount int
|
||||
var roundHistory []RoundResult
|
||||
var teamHistory = make(PlayerTeamHistory)
|
||||
|
||||
if len(os.Args) >= 3 {
|
||||
inputId := os.Args[2]
|
||||
@ -139,7 +151,6 @@ func main() {
|
||||
}
|
||||
|
||||
playerStats := make(map[uint64]*PlayerStats)
|
||||
playerInitialTeams := make(map[uint64]string)
|
||||
|
||||
getOrCreate := func(player common.Player) *PlayerStats {
|
||||
sid := player.SteamID64
|
||||
@ -148,25 +159,26 @@ func main() {
|
||||
stat = &PlayerStats{
|
||||
Name: player.Name,
|
||||
SteamID: fmt.Sprintf("%d", sid),
|
||||
Team: "", // später gesetzt
|
||||
Team: "",
|
||||
}
|
||||
playerStats[sid] = stat
|
||||
}
|
||||
return stat
|
||||
}
|
||||
|
||||
p.RegisterEventHandler(func(e events.MatchStart) {
|
||||
for _, player := range p.GameState().Participants().Playing() {
|
||||
switch player.Team {
|
||||
case common.TeamTerrorists:
|
||||
playerInitialTeams[player.SteamID64] = "T"
|
||||
case common.TeamCounterTerrorists:
|
||||
playerInitialTeams[player.SteamID64] = "CT"
|
||||
p.RegisterEventHandler(func(e events.RoundStart) {
|
||||
round := roundCount + 1 // nächste Runde
|
||||
teamHistory[round] = map[uint64]string{}
|
||||
|
||||
for _, p := range p.GameState().Participants().Playing() {
|
||||
if p.Team == common.TeamCounterTerrorists {
|
||||
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) {
|
||||
if e.Killer != nil && e.Killer.SteamID64 != e.Victim.SteamID64 {
|
||||
stat := getOrCreate(*e.Killer)
|
||||
@ -218,7 +230,7 @@ func main() {
|
||||
stat.TotalDamage += e.HealthDamage
|
||||
if e.Weapon != nil {
|
||||
switch e.Weapon.Type {
|
||||
case common.EqHE, common.EqIncendiary, common.EqMolotov:
|
||||
case common.EqHE, common.EqMolotov, common.EqIncendiary:
|
||||
stat.UtilityDamage += e.HealthDamage
|
||||
}
|
||||
}
|
||||
@ -278,20 +290,37 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
teamCT := p.GameState().TeamCounterTerrorists().ClanName()
|
||||
if teamCT == "" {
|
||||
teamCT = "CT"
|
||||
teamAName := p.GameState().TeamCounterTerrorists().ClanName()
|
||||
if teamAName == "" {
|
||||
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"
|
||||
if scoreCT > scoreT {
|
||||
winnerTeam = teamCT
|
||||
winnerTeam = teamAName
|
||||
} else if scoreT > scoreCT {
|
||||
winnerTeam = teamT
|
||||
winnerTeam = teamBName
|
||||
}
|
||||
|
||||
duration := sanitizeFloat(header.PlaybackTime.Seconds())
|
||||
@ -309,25 +338,19 @@ func main() {
|
||||
Map: mapName,
|
||||
Duration: duration,
|
||||
TickRate: tickRate,
|
||||
ScoreCT: scoreCT,
|
||||
ScoreT: scoreT,
|
||||
TeamCT: teamCT,
|
||||
TeamT: teamT,
|
||||
WinnerTeam: winnerTeam,
|
||||
RoundCount: roundCount,
|
||||
RoundHistory: roundHistory,
|
||||
}
|
||||
|
||||
// Final: Teamzuweisung korrekt, keine Überschreibung
|
||||
for sid, stat := range playerStats {
|
||||
if stat.Team == "" || stat.Team == "Unknown" {
|
||||
if team, ok := playerInitialTeams[sid]; ok {
|
||||
stat.Team = team
|
||||
} else {
|
||||
stat.Team = "Unknown"
|
||||
}
|
||||
}
|
||||
result.Players = append(result.Players, *stat)
|
||||
TeamA: Team{
|
||||
Name: teamAName,
|
||||
Score: scoreCT,
|
||||
Players: ctPlayers,
|
||||
},
|
||||
TeamB: Team{
|
||||
Name: teamBName,
|
||||
Score: scoreT,
|
||||
Players: tPlayers,
|
||||
},
|
||||
}
|
||||
|
||||
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