Track player vouchers

fasthttp
Flashfyre 2024-04-11 10:13:35 -04:00
parent ba7ab22d4d
commit a4014feea8
2 changed files with 21 additions and 3 deletions

View File

@ -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)
}

View File

@ -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 {