Public rank change log: sa_rank_log, written on rank changes, listed on the Staff page

This commit is contained in:
Astra 2026-09-29 16:56:37 +01:00
parent 861692c534
commit 611b79cdba
11 changed files with 346 additions and 17 deletions

View file

@ -5,6 +5,7 @@ package main
import (
"context"
"database/sql"
_ "embed"
"errors"
"fmt"
"log/slog"
@ -27,6 +28,11 @@ import (
"git.zio.sh/cs2/simpleadmin-web/internal/web"
)
// rankLogSQL creates sa_rank_log, the rank history (see the file).
//
//go:embed sql/rank-log.sql
var rankLogSQL string
func env(key, def string) string {
if v := strings.TrimSpace(os.Getenv(key)); v != "" {
return v
@ -127,6 +133,9 @@ func run() error {
return errors.New("sa_servers lists several servers; set SAW_SERVER_ID to this server's id")
}
st = store.New(db, loc, srv.ID, timeMode)
if err := st.EnsureRankLog(ctx, rankLogSQL); err != nil {
slog.Warn("couldn't create sa_rank_log; rank changes won't be logged until sql/rank-log.sql is run", "err", err)
}
rconAddr := env("SAW_RCON_ADDR", srv.Address)
rconPass := env("SAW_RCON_PASSWORD", srv.RconPassword)