diff --git a/api/savedata.go b/api/savedata.go index 7896af4..abfb91c 100644 --- a/api/savedata.go +++ b/api/savedata.go @@ -66,7 +66,7 @@ func handleSavedataUpdate(uuid []byte, slot int, save any) error { return fmt.Errorf("invalid system data") } - err = db.UpdateAccountStats(uuid, save.GameStats) + err = db.UpdateAccountStats(uuid, save.GameStats, save.VoucherCounts) if err != nil { return fmt.Errorf("failed to update account stats: %s", err) } diff --git a/db/account.go b/db/account.go index fe94953..0d97d3d 100644 --- a/db/account.go +++ b/db/account.go @@ -41,8 +41,8 @@ func UpdateAccountLastActivity(uuid []byte) error { return nil } -func UpdateAccountStats(uuid []byte, stats defs.GameStats) error { - var columns = []string{"playTime", "battles", "classicSessionsPlayed", "sessionsWon", "highestEndlessWave", "highestLevel", "pokemonSeen", "pokemonDefeated", "pokemonCaught", "pokemonHatched", "eggsPulled"} +func UpdateAccountStats(uuid []byte, stats defs.GameStats, voucherCounts map[string]int) error { + var columns = []string{"playTime", "battles", "classicSessionsPlayed", "sessionsWon", "highestEndlessWave", "highestLevel", "pokemonSeen", "pokemonDefeated", "pokemonCaught", "pokemonHatched", "eggsPulled", "regularVouchers", "plusVouchers", "premiumVouchers", "goldenVouchers"} var statCols []string var statValues []interface{} @@ -64,6 +64,24 @@ func UpdateAccountStats(uuid []byte, stats defs.GameStats) error { } } + for k, v := range voucherCounts { + var column string + switch k { + case "0": + column = "regularVouchers" + case "1": + column = "plusVouchers" + case "2": + column = "premiumVouchers" + case "3": + column = "goldenVouchers" + default: + continue + } + statCols = append(statCols, column) + statValues = append(statValues, v) + } + var statArgs []interface{} statArgs = append(statArgs, uuid) for range 2 {