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
41 lines
1.7 KiB
Go
41 lines
1.7 KiB
Go
package channelserver
|
|
|
|
import (
|
|
dbutil "erupe-ce/common/db"
|
|
)
|
|
|
|
// SessionRepository centralizes all database access for sign_sessions and servers tables.
|
|
type SessionRepository struct {
|
|
db *dbutil.DB
|
|
}
|
|
|
|
// NewSessionRepository creates a new SessionRepository.
|
|
func NewSessionRepository(db *dbutil.DB) *SessionRepository {
|
|
return &SessionRepository{db: db}
|
|
}
|
|
|
|
// ValidateLoginToken validates that the given token, session ID, and character ID
|
|
// correspond to a valid sign session. Returns an error if the token is invalid.
|
|
func (r *SessionRepository) ValidateLoginToken(token string, sessionID uint32, charID uint32) error {
|
|
var t string
|
|
return r.db.QueryRow("SELECT token FROM sign_sessions ss INNER JOIN public.users u on ss.user_id = u.id WHERE token=$1 AND ss.id=$2 AND u.id=(SELECT c.user_id FROM characters c WHERE c.id=$3)", token, sessionID, charID).Scan(&t)
|
|
}
|
|
|
|
// BindSession associates a sign session token with a server and character.
|
|
func (r *SessionRepository) BindSession(token string, serverID uint16, charID uint32) error {
|
|
_, err := r.db.Exec("UPDATE sign_sessions SET server_id=$1, char_id=$2 WHERE token=$3", serverID, charID, token)
|
|
return err
|
|
}
|
|
|
|
// ClearSession removes the server and character association from a sign session.
|
|
func (r *SessionRepository) ClearSession(token string) error {
|
|
_, err := r.db.Exec("UPDATE sign_sessions SET server_id=NULL, char_id=NULL WHERE token=$1", token)
|
|
return err
|
|
}
|
|
|
|
// UpdatePlayerCount updates the current player count for a server.
|
|
func (r *SessionRepository) UpdatePlayerCount(serverID uint16, count int) error {
|
|
_, err := r.db.Exec("UPDATE servers SET current_players=$1 WHERE server_id=$2", count, serverID)
|
|
return err
|
|
}
|