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 22, 2024
2 parents 5a4b38c + 568697b commit e3f064c
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 167 deletions.
2 changes: 1 addition & 1 deletion api/savedata/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Get(uuid []byte, datatype, slot int) (any, error) {
return nil, fmt.Errorf("failed to fetch compensations: %s", err)
}

needsUpdate := false
var needsUpdate bool
for compensationType, amount := range compensations {
system.VoucherCounts[strconv.Itoa(compensationType)] += amount
if amount > 0 {
Expand Down
80 changes: 1 addition & 79 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ package db

import (
"database/sql"
"encoding/hex"
"fmt"
"log"
"os"
"time"

_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -55,7 +53,7 @@ func Init(username, password, protocol, address, database string) error {

err = setupDb(tx)
if err != nil {
_ = tx.Rollback()
tx.Rollback()

Check failure on line 56 in db/db.go

View workflow job for this annotation

GitHub Actions / Build (linux)

Error return value of `tx.Rollback` is not checked (errcheck)

Check failure on line 56 in db/db.go

View workflow job for this annotation

GitHub Actions / Build (windows)

Error return value of `tx.Rollback` is not checked (errcheck)
log.Fatal(err)
}

Expand All @@ -64,82 +62,6 @@ func Init(username, password, protocol, address, database string) error {
log.Fatal(err)
}

// TODO temp code
_, err = os.Stat("userdata")
if err != nil {
if !os.IsNotExist(err) { // not found, do not migrate
log.Fatalf("failed to stat userdata directory: %s", err)
}

return nil
}

entries, err := os.ReadDir("userdata")
if err != nil {
log.Fatal(err)
}

for _, entry := range entries {
if !entry.IsDir() {
continue
}

uuidString := entry.Name()
uuid, err := hex.DecodeString(uuidString)
if err != nil {
log.Printf("failed to decode uuid: %s", err)
continue
}

var count int
err = handle.QueryRow("SELECT COUNT(*) FROM systemSaveData WHERE uuid = ?", uuid).Scan(&count)
if err != nil || count != 0 {
continue
}

// store new system data
systemData, err := LegacyReadSystemSaveData(uuid)
if err != nil {
log.Printf("failed to read system save data for %v: %s", uuidString, err)
continue
}

err = StoreSystemSaveData(uuid, systemData)
if err != nil {
log.Fatalf("failed to store system save data for %v: %s\n", uuidString, err)
}

// delete old system data
err = os.Remove("userdata/" + uuidString + "/system.pzs")
if err != nil {
log.Fatalf("failed to remove legacy system save data for %v: %s", uuidString, err)
}

for i := 0; i < 5; i++ {
sessionData, err := LegacyReadSessionSaveData(uuid, i)
if err != nil {
log.Printf("failed to read session save data %v for %v: %s", i, uuidString, err)
continue
}

// store new session data
err = StoreSessionSaveData(uuid, sessionData, i)
if err != nil {
log.Fatalf("failed to store session save data for %v: %s\n", uuidString, err)
}

// delete old session data
filename := "session"
if i != 0 {
filename += fmt.Sprintf("%d", i)
}
err = os.Remove(fmt.Sprintf("userdata/%s/%s.pzs", uuidString, filename))
if err != nil {
log.Fatalf("failed to remove legacy session save data %v for %v: %s", i, uuidString, err)
}
}
}

return nil
}

Expand Down
84 changes: 0 additions & 84 deletions db/legacy.go

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22

require (
github.com/go-sql-driver/mysql v1.7.1
github.com/klauspost/compress v1.17.4
github.com/robfig/cron/v3 v3.0.1
golang.org/x/crypto v0.16.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
Expand Down

0 comments on commit e3f064c

Please sign in to comment.