mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-21 23:22:34 +01:00
Add zero-dependency SQLite mode so users can run Erupe without
PostgreSQL. A transparent db.DB wrapper auto-translates PostgreSQL
SQL ($N placeholders, now(), ::casts, ILIKE, public. prefix,
TRUNCATE) for SQLite at runtime — all 28 repo files use the wrapper
with no per-query changes needed.
Setup wizard gains two new steps: quest file detection with download
link, and gameplay presets (solo/small/community/rebalanced). The API
server gets a /dashboard endpoint with auto-refreshing stats.
CI release workflow now builds and pushes Docker images to GHCR
alongside binary artifacts on tag push.
Key changes:
- common/db: DB/Tx wrapper with 6 SQL translation rules
- server/migrations/sqlite: full SQLite schema (0001-0005)
- config: Database.Driver field ("postgres" or "sqlite")
- main.go: SQLite connection with WAL mode, single writer
- server/setup: quest check + preset selection steps
- server/api: /dashboard with live stats
- .github/workflows: Docker in release, deduplicate docker.yml
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package channelserver
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// GoocooRepository centralizes all database access for the goocoo table.
|
|
type GoocooRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewGoocooRepository creates a new GoocooRepository.
|
|
func NewGoocooRepository(db *dbutil.DB) *GoocooRepository {
|
|
return &GoocooRepository{db: db}
|
|
}
|
|
|
|
// validGoocooSlot validates the slot index to prevent SQL injection.
|
|
func validGoocooSlot(slot uint32) error {
|
|
if slot > 4 {
|
|
return fmt.Errorf("invalid goocoo slot index: %d", slot)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// EnsureExists creates a goocoo record if it doesn't already exist.
|
|
func (r *GoocooRepository) EnsureExists(charID uint32) error {
|
|
_, err := r.db.Exec("INSERT INTO goocoo (id) VALUES ($1) ON CONFLICT DO NOTHING", charID)
|
|
return err
|
|
}
|
|
|
|
// GetSlot reads a single goocoo slot by character ID and slot index (0-4).
|
|
func (r *GoocooRepository) GetSlot(charID uint32, slot uint32) ([]byte, error) {
|
|
if err := validGoocooSlot(slot); err != nil {
|
|
return nil, err
|
|
}
|
|
var data []byte
|
|
err := r.db.QueryRow(fmt.Sprintf("SELECT goocoo%d FROM goocoo WHERE id=$1", slot), charID).Scan(&data)
|
|
return data, err
|
|
}
|
|
|
|
// ClearSlot sets a goocoo slot to NULL.
|
|
func (r *GoocooRepository) ClearSlot(charID uint32, slot uint32) error {
|
|
if err := validGoocooSlot(slot); err != nil {
|
|
return err
|
|
}
|
|
_, err := r.db.Exec(fmt.Sprintf("UPDATE goocoo SET goocoo%d=NULL WHERE id=$1", slot), charID)
|
|
return err
|
|
}
|
|
|
|
// SaveSlot writes data to a goocoo slot.
|
|
func (r *GoocooRepository) SaveSlot(charID uint32, slot uint32, data []byte) error {
|
|
if err := validGoocooSlot(slot); err != nil {
|
|
return err
|
|
}
|
|
_, err := r.db.Exec(fmt.Sprintf("UPDATE goocoo SET goocoo%d=$1 WHERE id=$2", slot), data, charID)
|
|
return err
|
|
}
|