Remove voucher compensation code

pull/23/merge
Pancakes 5 months ago
parent 872c03d14b
commit dd00d90211
No known key found for this signature in database
GPG Key ID: 5792877BFA27DC8F

@ -2,7 +2,6 @@ package savedata
import ( import (
"fmt" "fmt"
"strconv"
"github.com/pagefaultgames/rogueserver/db" "github.com/pagefaultgames/rogueserver/db"
"github.com/pagefaultgames/rogueserver/defs" "github.com/pagefaultgames/rogueserver/defs"
@ -14,36 +13,6 @@ func GetSystem(uuid []byte) (defs.SystemSaveData, error) {
return system, err return system, err
} }
// TODO: this should be a transaction
compensations, err := db.FetchAndClaimAccountCompensations(uuid)
if err != nil {
return system, fmt.Errorf("failed to fetch compensations: %s", err)
}
var needsUpdate bool
for compensationType, amount := range compensations {
system.VoucherCounts[strconv.Itoa(compensationType)] += amount
if amount > 0 {
needsUpdate = true
}
}
if needsUpdate {
err = db.StoreSystemSaveData(uuid, system)
if err != nil {
return system, fmt.Errorf("failed to update system save data: %s", err)
}
err = db.DeleteClaimedAccountCompensations(uuid)
if err != nil {
return system, fmt.Errorf("failed to delete claimed compensations: %s", err)
}
err = db.UpdateAccountStats(uuid, system.GameStats, system.VoucherCounts)
if err != nil {
return system, fmt.Errorf("failed to update account stats: %s", err)
}
}
return system, nil return system, nil
} }
@ -61,11 +30,6 @@ func UpdateSystem(uuid []byte, data defs.SystemSaveData) error {
return fmt.Errorf("failed to update account stats: %s", err) return fmt.Errorf("failed to update account stats: %s", err)
} }
err = db.DeleteClaimedAccountCompensations(uuid)
if err != nil {
return fmt.Errorf("failed to delete claimed compensations: %s", err)
}
return db.StoreSystemSaveData(uuid, data) return db.StoreSystemSaveData(uuid, data)
} }

@ -47,11 +47,6 @@ func Update(uuid []byte, slot int, save any) error {
return fmt.Errorf("failed to update account stats: %s", err) return fmt.Errorf("failed to update account stats: %s", err)
} }
err = db.DeleteClaimedAccountCompensations(uuid)
if err != nil {
return fmt.Errorf("failed to delete claimed compensations: %s", err)
}
return db.StoreSystemSaveData(uuid, save) return db.StoreSystemSaveData(uuid, save)
case defs.SessionSaveData: // Session case defs.SessionSaveData: // Session

@ -154,43 +154,6 @@ func SetAccountBanned(uuid []byte, banned bool) error {
return nil return nil
} }
func FetchAndClaimAccountCompensations(uuid []byte) (map[int]int, error) {
var compensations = make(map[int]int)
results, err := handle.Query("SELECT voucherType, count FROM accountCompensations WHERE uuid = ?", uuid)
if err != nil {
return nil, err
}
defer results.Close()
for results.Next() {
var voucherType int
var count int
err := results.Scan(&voucherType, &count)
if err != nil {
return compensations, err
}
compensations[voucherType] = count
}
_, err = handle.Exec("UPDATE accountCompensations SET claimed = 1 WHERE uuid = ?", uuid)
if err != nil {
return compensations, err
}
return compensations, nil
}
func DeleteClaimedAccountCompensations(uuid []byte) error {
_, err := handle.Exec("DELETE FROM accountCompensations WHERE uuid = ? AND claimed = 1", uuid)
if err != nil {
return err
}
return nil
}
func FetchAccountKeySaltFromUsername(username string) ([]byte, []byte, error) { func FetchAccountKeySaltFromUsername(username string) ([]byte, []byte, error) {
var key, salt []byte var key, salt []byte
err := handle.QueryRow("SELECT hash, salt FROM accounts WHERE username = ?", username).Scan(&key, &salt) err := handle.QueryRow("SELECT hash, salt FROM accounts WHERE username = ?", username).Scan(&key, &salt)

@ -92,6 +92,11 @@ func setupDb(tx *sql.Tx) error {
`ALTER TABLE sessions DROP COLUMN IF EXISTS active`, `ALTER TABLE sessions DROP COLUMN IF EXISTS active`,
`CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`, `CREATE TABLE IF NOT EXISTS activeClientSessions (uuid BINARY(16) NOT NULL PRIMARY KEY, clientSessionId VARCHAR(32) NOT NULL, FOREIGN KEY (uuid) REFERENCES accounts (uuid) ON DELETE CASCADE ON UPDATE CASCADE)`,
// ----------------------------------
// MIGRATION 002
`DROP TABLE accountCompensations`,
} }
for _, q := range queries { for _, q := range queries {

Loading…
Cancel
Save