diff --git a/gpcm/report.go b/gpcm/report.go index f353341..7449372 100644 --- a/gpcm/report.go +++ b/gpcm/report.go @@ -1,14 +1,29 @@ package gpcm import ( + "encoding/json" "strconv" "wwfc/common" "wwfc/logging" "wwfc/qr2" - "github.com/logrusorgru/aurora/v3" ) +type RaceResultPlayer struct { + Pid *int `json:"pid"` + FinishPosition *int `json:"finish_position"` + FinishTimeMs *int `json:"finish_time_ms"` + CharacterId *int `json:"character_id"` + KartId *int `json:"kart_id"` + ClientRttMs *float64 `json:"client_rtt_ms"` +} + +type RaceResult struct { + ClientReportVersion string `json:"client_report_version"` + TimestampClient string `json:"timestamp_client"` + Players []RaceResultPlayer `json:"players"` +} + func (g *GameSpySession) handleWWFCReport(command common.GameSpyCommand) { for key, value := range command.OtherValues { logging.Info(g.ModuleName, "WiiLink Report:", aurora.Yellow(key)) @@ -71,7 +86,26 @@ func (g *GameSpySession) handleWWFCReport(command common.GameSpyCommand) { } logging.Info(g.ModuleName, "Received race result from profile", aurora.BrightCyan(strconv.FormatUint(uint64(g.User.ProfileId), 10))) - logging.Info(g.ModuleName, "Race result payload:", aurora.BrightMagenta(value)) + + var raceResult RaceResult + err := json.Unmarshal([]byte(value), &raceResult) + if err != nil { + logging.Error(g.ModuleName, "Error parsing race result JSON:", err.Error()) + logging.Info(g.ModuleName, "Raw payload:", aurora.BrightMagenta(value)) + continue + } + + logging.Info(g.ModuleName, "Race result version:", aurora.Yellow(raceResult.ClientReportVersion)) + logging.Info(g.ModuleName, "Timestamp:", aurora.Yellow(raceResult.TimestampClient)) + logging.Info(g.ModuleName, "Player count:", aurora.Yellow(len(raceResult.Players))) + + for i, player := range raceResult.Players { + logging.Info(g.ModuleName, "Player", aurora.Cyan(i), "- PID:", aurora.Cyan(player.Pid), + "Pos:", aurora.Cyan(player.FinishPosition), + "Time:", aurora.Cyan(player.FinishTimeMs), "ms", + "Char:", aurora.Cyan(player.CharacterId), + "Kart:", aurora.Cyan(player.KartId)) + } } } }