Skip to content

ServerConfig

The ServerConfig table stores per-server operational settings such as the server name, password, MOTD (Message of the Day), and whitelist toggle. Unlike most platform tables, ServerConfig has local scope — each game server subscribes only to its own row, and changes take effect immediately through SpacetimeDB's reactive subscription model.


Scope

🔵 Local — Each game server subscribes to the single row matching its own server_id. Changes pushed by admin reducers are delivered in real time to the affected server only.


Schema

Column Type Constraints Description
server_id String Primary Key References the server's entry in ServerRegistry
server_name String Display name shown to players in the server browser
max_players u32 Maximum number of concurrent players allowed
password_hash String Hashed server password (empty string if no password)
whitelist_enabled bool Whether the whitelist is actively enforced
motd String Message of the Day displayed to players on connection

Rust Definition

#[spacetimedb::table(public, name = server_config)]
pub struct ServerConfig {
    #[primary_key]
    pub server_id: String,
    pub server_name: String,
    pub max_players: u32,
    pub password_hash: String,
    pub whitelist_enabled: bool,
    pub motd: String,
}

Usage Patterns

Game Hook Subscription

Each game server's hook subscribes to its own configuration row using a filtered query:

SELECT * FROM server_config WHERE server_id = 'us-east-pvp-1'

When an administrator changes the MOTD via the panel, the update flows through SpacetimeDB's subscription pipeline directly to the affected server — no polling required. The game hook receives an on_update callback and applies the new setting immediately.

Configuration Flow

The typical lifecycle of a configuration change:

  1. Admin opens the panel and modifies the MOTD for server us-east-pvp-1.
  2. Panel calls panel_set_motd (wrapper reducer).
  3. Wrapper validates panel session, then delegates to admin_set_motd.
  4. admin_set_motd updates the motd column in ServerConfig.
  5. SpacetimeDB pushes the row update to the subscribing game hook.
  6. Game hook applies the new MOTD in-game.

Password Protection

The password_hash column stores a hashed representation of the server password. When a player attempts to connect to a password-protected server, the game hook compares the player-supplied password against the stored hash. An empty string ("") indicates no password is set.

Whitelist Toggle

The whitelist_enabled boolean works in conjunction with the WhitelistEntry table. When true, the game hook checks incoming connections against the whitelist. When false, the whitelist table data is ignored and all players may connect (subject to other restrictions like bans).


Relationship to ServerRegistry

ServerConfig and ServerRegistry share the same server_id primary key but serve different purposes:

Aspect ServerRegistry ServerConfig
Scope 🌍 Global 🔵 Local
Updated by server_heartbeat (from server) Admin reducers (from panel/gateway)
Purpose Cluster-wide directory and metrics Per-server operational settings
Subscribers Panel, gateway, all servers Only the owning game server

Reducer Operation
admin_set_password Updates password_hash
admin_toggle_whitelist Toggles whitelist_enabled
admin_set_max_players Updates max_players
admin_set_motd Updates motd
panel_set_password Panel wrapper → admin_set_password
panel_toggle_whitelist Panel wrapper → admin_toggle_whitelist
panel_set_max_players Panel wrapper → admin_set_max_players
panel_set_motd Panel wrapper → admin_set_motd

Subscriber Query Purpose
Game Hook SELECT * FROM server_config WHERE server_id = '{self}' Real-time config sync

For full subscription architecture, see Subscriptions.



  • ServerRegistry — Cluster-wide server directory (shares server_id PK)
  • WhitelistEntry — Whitelist records enforced when whitelist_enabled = true
  • Reducers — Admin and panel reducers that modify this table