Playtime from PlaytimeHistory's database (SAW_PT_DSN)
A public Playtime tab and player-drawer playtime, and staff-only figures (who's on, staff activity, disconnect reasons, countries, names, sessions) for @css/generic on the staff panel and on the public site when signed in. Hidden unless SAW_PT_DSN is set and its tables are there.
This commit is contained in:
parent
daa7ec2dbc
commit
6d0fc6e463
18 changed files with 2238 additions and 12 deletions
28
main.go
28
main.go
|
|
@ -22,6 +22,7 @@ import (
|
|||
"github.com/go-sql-driver/mysql"
|
||||
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/live"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/playtime"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/push"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/rcon"
|
||||
"git.zio.sh/cs2/simpleadmin-web/internal/saconfig"
|
||||
|
|
@ -158,6 +159,14 @@ func run() error {
|
|||
poller := live.NewPoller(rc, time.Duration(max(pollSecs, 2))*time.Second)
|
||||
go poller.Run(ctx)
|
||||
|
||||
pt, err := openPlaytime()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pt != nil {
|
||||
defer pt.Close()
|
||||
}
|
||||
|
||||
joinAddr := env("SAW_JOIN_ADDRESS", srv.Address)
|
||||
app, err := web.New(web.Config{
|
||||
BaseURL: baseURL,
|
||||
|
|
@ -169,6 +178,7 @@ func run() error {
|
|||
AndroidPackage: env("SAW_ANDROID_PACKAGE", ""),
|
||||
AndroidCerts: strings.Split(env("SAW_ANDROID_CERT_SHA256", ""), ","),
|
||||
Push: pushSender(ctx, st, baseURL),
|
||||
Playtime: pt,
|
||||
}, st, rc, poller, sacfg)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -222,6 +232,24 @@ func pushSender(ctx context.Context, st *store.Store, baseURL string) *push.Send
|
|||
return &push.Sender{Keys: keys, Subject: baseURL, Client: &http.Client{Timeout: 15 * time.Second}}
|
||||
}
|
||||
|
||||
// openPlaytime opens PlaytimeHistory's database (SAW_PT_DSN), or returns nil when it isn't set.
|
||||
// It doesn't connect yet: if that database is down, playtime is hidden until it's back.
|
||||
func openPlaytime() (*playtime.Store, error) {
|
||||
dsn := env("SAW_PT_DSN", "")
|
||||
if dsn == "" {
|
||||
return nil, nil
|
||||
}
|
||||
server, err := envInt("SAW_PT_SERVER_ID", 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pt, err := playtime.Open(dsn, server)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("SAW_PT_DSN: %w", err)
|
||||
}
|
||||
return pt, nil
|
||||
}
|
||||
|
||||
// openDB connects with SAW_DB_DSN, or with the DatabaseConfig in CS2-SimpleAdmin.json.
|
||||
func openDB(sacfg *saconfig.File) (*sql.DB, error) {
|
||||
var cfg *mysql.Config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue