mirror of
https://github.com/tiennm99/noitu.git
synced 2026-10-15 14:16:31 +00:00
fix(server): name the player on every played word, and bound the process
PlayedWord.player_id was declared and read by the client but never set by the server, so a room of three or four never showed who played each word. The chain byline now comes from the room, with a producer-side test. The process also gains the ceilings it was missing: a cap on live rooms and on open sockets, a per-connection frame-rate limit so a payload-less frame is no longer free, and an opt-in trusted-proxy list so the join limiter can tell players apart behind the documented reverse proxy instead of putting them in one bucket. The typed word is sanitized before the engine stores it, since every seat is shown it; a room exiting on its idle clock releases the sessions still bound to it; the dictionary builder escapes its SQLite path like the store does and renames over the old database instead of deleting it first.
This commit is contained in:
1 parent
a5052fca3f
commit
442ced32cc
14 files changed
+494
-54
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -36,6 +37,9 @@ type config struct {
|
||||
grace time.Duration
|
||||
allowedOrigins []string
|
||||
webDir string
|
||||
trustedProxies []string
|
||||
maxRooms int
|
||||
maxConnections int
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -74,6 +78,9 @@ func run() error {
|
||||
GraceFor: cfg.grace,
|
||||
AllowedOrigins: cfg.allowedOrigins,
|
||||
WebDir: cfg.webDir,
|
||||
TrustedProxies: cfg.trustedProxies,
|
||||
MaxRooms: cfg.maxRooms,
|
||||
MaxConnections: cfg.maxConnections,
|
||||
})
|
||||
|
||||
srv := &http.Server{
|
||||
@@ -114,9 +121,27 @@ func loadConfig() config {
|
||||
grace: envDuration("NOITU_GRACE", defaultGrace),
|
||||
allowedOrigins: envList("NOITU_ALLOWED_ORIGINS"),
|
||||
webDir: env("NOITU_WEB_DIR", ""),
|
||||
trustedProxies: envList("NOITU_TRUSTED_PROXIES"),
|
||||
maxRooms: envInt("NOITU_MAX_ROOMS", 0),
|
||||
maxConnections: envInt("NOITU_MAX_CONNECTIONS", 0),
|
||||
}
|
||||
}
|
||||
|
||||
// envInt falls back loudly, like envDuration. Zero means "use the built-in
|
||||
// default", so it is what an unset or invalid value becomes.
|
||||
func envInt(key string, fallback int) int {
|
||||
raw := strings.TrimSpace(os.Getenv(key))
|
||||
if raw == "" {
|
||||
return fallback
|
||||
}
|
||||
n, err := strconv.Atoi(raw)
|
||||
if err != nil || n < 0 {
|
||||
slog.Warn("ignoring invalid integer", "key", key, "value", raw, "using", fallback)
|
||||
return fallback
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func env(key, fallback string) string {
|
||||
if v := strings.TrimSpace(os.Getenv(key)); v != "" {
|
||||
return v
|
||||
|
||||
Reference in new issue
Block a user