Skip to content

Commit

Permalink
Merge branch 'pagefaultgames:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
StrayanDropbear authored May 21, 2024
2 parents d386424 + 7bfd9df commit 5a4b38c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
4 changes: 1 addition & 3 deletions api/daily/rankings.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package daily

import (
"log"

"github.com/pagefaultgames/rogueserver/db"
"github.com/pagefaultgames/rogueserver/defs"
)
Expand All @@ -28,7 +26,7 @@ import (
func Rankings(category, page int) ([]defs.DailyRanking, error) {
rankings, err := db.FetchRankings(category, page)
if err != nil {
log.Print("failed to retrieve rankings")
return rankings, err
}

return rankings, nil
Expand Down
4 changes: 1 addition & 3 deletions api/daily/rankingspagecount.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
package daily

import (
"log"

"github.com/pagefaultgames/rogueserver/db"
)

// /daily/rankingpagecount - fetch daily ranking page count
func RankingPageCount(category int) (int, error) {
pageCount, err := db.FetchRankingPageCount(category)
if err != nil {
log.Print("failed to retrieve ranking page count")
return pageCount, err
}

return pageCount, nil
Expand Down
4 changes: 4 additions & 0 deletions api/savedata/clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func Clear(uuid []byte, slot int, seed string, save defs.SessionSaveData) (Clear
waveCompleted--
}

if save.Score >= 20000 {
db.SetAccountBanned(uuid, true)

Check failure on line 54 in api/savedata/clear.go

View workflow job for this annotation

GitHub Actions / Build (linux)

Error return value of `db.SetAccountBanned` is not checked (errcheck)

Check failure on line 54 in api/savedata/clear.go

View workflow job for this annotation

GitHub Actions / Build (windows)

Error return value of `db.SetAccountBanned` is not checked (errcheck)
}

err = db.AddOrUpdateAccountDailyRun(uuid, save.Score, waveCompleted)
if err != nil {
log.Printf("failed to add or update daily run record: %s", err)
Expand Down
7 changes: 7 additions & 0 deletions api/savedata/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func Update(uuid []byte, slot int, save any) error {
return fmt.Errorf("client version out of date")
}

if save.VoucherCounts["0"] > 300 ||
save.VoucherCounts["1"] > 150 ||
save.VoucherCounts["2"] > 100 ||
save.VoucherCounts["3"] > 10 {
db.SetAccountBanned(uuid, true)

Check failure on line 49 in api/savedata/update.go

View workflow job for this annotation

GitHub Actions / Build (linux)

Error return value of `db.SetAccountBanned` is not checked (errcheck)

Check failure on line 49 in api/savedata/update.go

View workflow job for this annotation

GitHub Actions / Build (windows)

Error return value of `db.SetAccountBanned` is not checked (errcheck)
}

err = db.UpdateAccountStats(uuid, save.GameStats, save.VoucherCounts)
if err != nil {
return fmt.Errorf("failed to update account stats: %s", err)
Expand Down
9 changes: 9 additions & 0 deletions db/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ func UpdateAccountStats(uuid []byte, stats defs.GameStats, voucherCounts map[str
return nil
}

func SetAccountBanned(uuid []byte, banned bool) error {
_, err := handle.Exec("UPDATE accounts SET banned = ? WHERE uuid = ?", banned, uuid)
if err != nil {
return err
}

return nil
}

func FetchAndClaimAccountCompensations(uuid []byte) (map[int]int, error) {
var compensations = make(map[int]int)

Expand Down

0 comments on commit 5a4b38c

Please sign in to comment.