atlas

package
v0.0.0-...-8e88d4a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 22, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package atlas runs the Atlas server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// The addresses to listen on (comma-separated).
	Addr []string `env:"ATLAS_ADDR?=:8080"`

	// The addresses to listen on with TLS (comma-separated).
	AddrTLS []string `env:"ATLAS_ADDR_HTTPS"`

	// The address to listen on and use to send connectionless packets. If the
	// port is 0, a random one is chosen.
	AddrUDP netip.AddrPort `env:"ATLAS_ADDR_UDP=:0"`

	// Whether to trust Cloudflare headers like CF-Connecting-IP.
	//
	// This is not safe to use unless you:
	//  - Set Host to prevent it from being accessed via other CF zones.
	//  - Use an IP whitelist, or client certificates with mTLS-only origin pull.
	Cloudflare bool `env:"ATLAS_CLOUDFLARE"`

	// Comma-separated list of case-insensitive hostnames to accept via the Host
	// header. If not provided, all hostnames are allowed.
	Host []string `env:"ATLAS_HOST"`

	// Comma-separated list of paths to SSL server certificates to use for SSL.
	// The .crt and .key extensions will be appended automatically. If not
	// provided, SSL is disabled. If a path begins with @, it is treated as a
	// systemd credential name (i.e., @mycert expands to
	// $CREDENTIALS_DIRECTORY/mycert.{crt,key}).
	ServerCerts []string `env:"ATLAS_SERVER_CERTS" sdcreds:"expand,list"`

	// The minimum log level (e.g., trace, debug, info, warn, error, fatal).
	//
	// Note that access logs for noisy HTTP endpoints are demoted to debug.
	LogLevel zerolog.Level `env:"ATLAS_LOG_LEVEL=debug"`

	// Whether to log to stdout.
	LogStdout bool `env:"ATLAS_LOG_STDOUT=true"`

	// Whether to use pretty logs.
	LogStdoutPretty bool `env:"ATLAS_LOG_STDOUT_PRETTY=true"`

	// The minimum log level for stdout.
	LogStdoutLevel zerolog.Level `env:"ATLAS_LOG_STDOUT_LEVEL=trace"`

	// The log file to output to, if provided. Reopened on SIGHUP.
	LogFile string `env:"ATLAS_LOG_FILE"`

	// The minimum log level for the log file.
	LogFileLevel zerolog.Level `env:"ATLAS_LOG_FILE_LEVEL=info"`

	// The permissions for the log file.
	LogFileChmod fs.FileMode `env:"ATLAS_LOG_FILE_CHMOD"`

	// The owner for the log file. Not supported on Windows.
	LogFileChown *UIDGID `env:"ATLAS_LOG_FILE_CHOWN"`

	// Maps source IP prefixes to another IP (useful for controlling server
	// registration IPs when running within a LAN and port forwarding during
	// development). Comma-separated list of prefix=ip (example:
	// 192.168.0.0/24=1.2.3.4).
	DevMapIP []string `env:"ATLAS_DEV_MAP_IP"`

	// The maximum number of gameservers to allow. If -1, no limit is applied.
	API0_MaxServers int `env:"ATLAS_API0_MAX_SERVERS=1000"`

	// The maximum number of gameservers to allow per IP. If -1, no limit is
	// applied.
	API0_MaxServersPerIP int `env:"ATLAS_API0_MAX_SERVERS_PER_IP=25"`

	// The amount of time for player masterserver auth tokens to be valid for.
	API0_TokenExpiryTime time.Duration `env:"ATLAS_API0_TOKEN_EXPIRY_TIME=24h"`

	// Don't check player masterserver auth tokens, disable stryder auth.
	API0_InsecureDevNoCheckPlayerAuth bool `env:"ATLAS_API0_INSECURE_DEV_NO_CHECK_PLAYER_AUTH"`

	// Whether to allow games to register via IPv6. Not recommended.
	API0_AllowGameServerIPv6 bool `env:"ATLAS_API0_ALLOW_GAME_SERVER_IPV6"`

	// Minimum launcher semver to allow for servers or authenticated clients.
	// Dev versions are always allowed. If not provided, all client versions are
	// allowed.
	API0_MinimumLauncherVersion string `env:"ATLAS_API0_MINIMUM_LAUNCHER_VERSION"`

	// Minimum launcher semver to allow for authenticated clients, replacing
	// ATLAS_API0_MINIMUM_LAUNCHER_VERSION. Dev versions are always allowed. If
	// not provided, API0_MinimumLauncherVersion is used.
	API0_MinimumLauncherVersionClient string `env:"ATLAS_API0_MINIMUM_LAUNCHER_VERSION_CLIENT"`

	// Minimum launcher semver to allow for servers, replacing
	// ATLAS_API0_MINIMUM_LAUNCHER_VERSION. Dev versions are always allowed. If
	// not provided, API0_MinimumLauncherVersion is used.
	API0_MinimumLauncherVersionServer string `env:"ATLAS_API0_MINIMUM_LAUNCHER_VERSION_SERVER"`

	// Region mapping to use for server list. If set to an empty string or
	// "none", region maps are disabled. Options: none, default.
	API0_RegionMap string `env:"ATLAS_API0_REGION_MAP?=default"`

	// Region mapping overrides. Comma-separated list of prefix=region.
	API0_RegionMap_Override []string `env:"ATLAS_API0_REGION_MAP_OVERRIDE"`

	// The time after registration for a gameserver to complete verification by.
	API0_ServerList_VerifyTime time.Duration `env:"ATLAS_API0_SERVERLIST_VERIFY_TIME=10s"`

	// The time since the last heartbeat for a gameserver to be marked as
	// dead.
	API0_ServerList_DeadTime time.Duration `env:"ATLAS_API0_SERVERLIST_DEAD_TIME=30s"`

	// The time since the last heartbeat for a gameserver to be discarded (i.e.,
	// it can't be added again without re-verifying).
	API0_ServerList_GhostTime time.Duration `env:"ATLAS_API0_SERVERLIST_GHOST_TIME=2m"`

	// Experimental option to use deterministic server ID generation based on
	// the provided secret and the server info. The secret is used to prevent
	// brute-forcing server IDs from the ID and known server info. If it begins
	// with @, it is treated as the name of a systemd credential to load.
	API0_ServerList_ExperimentalDeterministicServerIDSecret string `env:"ATLAS_API0_SERVERLIST_EXPERIMENTAL_DETERMINISTIC_SERVER_ID_SECRET" sdcreds:"load,trimspace"`

	// The storage to use for accounts:
	//  - memory
	//  - sqlite3:/path/to/atlas.db
	API0_Storage_Accounts string `env:"ATLAS_API0_STORAGE_ACCOUNTS=memory"`

	// The storage to use for pdata:
	//  - memory:compress
	//  - sqlite3:/path/to/pdata.db
	API0_Storage_Pdata string `env:"ATLAS_API0_STORAGE_PDATA=memory:compress"`

	// The source to use for mainmenupromos:
	//  - none
	//  - file:/path/to/mainmenupromos.json
	API0_MainMenuPromos string `env:"ATLAS_API0_MAINMENUPROMOS=none"`

	// If provided, the mainmenupromos will be merged with the provided source
	// (same syntax as API0_MAINEMENUPROMOS) if the client is older than the
	// API0_MinimumLauncherVersion.
	API0_MainMenuPromos_UpdateNeeded string `env:"ATLAS_API0_MAINMENUPROMOS_UPDATENEEDED=none"`

	// Sets the source used for resolving usernames. If not specified, "origin"
	// is used if OriginEmail is provided, otherwise, "none" is used.
	//  - none (don't get usernames)
	//  - eax (get the username from EAX)
	//  - stryder (get the username from Stryder)
	//  - stryder-eax (get the username from Stryder, but fall back to EAX on failure)
	//  - stryder-eax-debug (get the username from Stryder, but also check EAX and warn if it's different)
	UsernameSource string `env:"ATLAS_USERNAMESOURCE"`

	// Override the EAX EA App version. If specified, updates will not be
	// checked automatically.
	EAXUpdateVersion string `env:"EAX_UPDATE_VERSION"`

	// EAXUpdateInterval is the min interval at which to check for EA App
	// updates.
	EAXUpdateInterval time.Duration `env:"EAX_UPDATE_INTERVAL=24h"`

	// EAXUpdateBucket is the update bucket to use when checking for EA App
	// updates.
	EAXUpdateBucket int `env:"EAX_UPDATE_BUCKET=0"`

	// Secret token for accessing internal metrics. If it begins with @, it is
	// treated as the name of a systemd credential to load.
	MetricsSecret string `env:"ATLAS_METRICS_SECRET" sdcreds:"load,trimspace"`

	// The path to use for static website files. If a file named redirects.json
	// exists, it is read at startup, reloaded on SIGHUP, and used as a mapping
	// of top-level names to URLs. Custom error pages can be named
	// {status}.html.
	Web string `env:"ATLAS_WEB"`

	// For the Funny:tm:
	AllowJokes bool `env:"ATLAS_JOKES"`

	// The path to the IP2Location database, which should contain at least the
	// country and region fields. The database must not be modified while atlas
	// is running, but it can be replaced (and a reload can be triggered with
	// SIGHUP). If not provided, geolocation-dependent features like server
	// regions and geo metrics will not be enabled. If it doesn't include latlon
	// info, geo metrics will be disabled too.
	IP2Location string `env:"ATLAS_IP2LOCATION"`

	// For sd-notify.
	NotifySocket string `env:"NOTIFY_SOCKET"`
}

Config contains the configuration for Atlas. The env struct tag contains the environment variable name and the default value if missing, or empty (if not ?=). All string arrays are comma-separated.

func (*Config) UnmarshalEnv

func (c *Config) UnmarshalEnv(es []string, incremental bool) error

UnmarshalEnv unmarshals an array of environment variables into c, setting default values as appropriate. If incremental is true, default values will not be set for missing env vars, but only for empty ones.

type Server

type Server struct {
	Logger zerolog.Logger

	Addr          []string
	AddrTLS       []string
	AddrUDP       netip.AddrPort
	Handler       http.Handler
	Web           http.Handler
	Redirects     map[string]string
	NotifySocket  string
	MetricsSecret string
	API0          *api0.Handler
	Middleware    []func(http.Handler) http.Handler
	TLSConfig     *tls.Config
	// contains filtered or unexported fields
}

func NewServer

func NewServer(c *Config) (*Server, error)

NewServer configures a new server using c, which is assumed to be initialized to default or configured values (as done by UnmarshalEnv). It will perform any additional config checks as required.

func (*Server) HandleSIGHUP

func (s *Server) HandleSIGHUP()

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run runs the server, shutting it down gracefully when ctx is canceled, then waiting indefinitely for it to exit. It must only ever be called once, and the server is useless afterwards.

type UIDGID

type UIDGID [2]int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL