aboutsummaryrefslogtreecommitdiff
path: root/pkg/atlas
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-11-20 03:24:54 -0500
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-11-20 06:12:13 -0500
commitd02c7b58e7c25c548de413b74592b82fc30322a3 (patch)
tree7d220061c6846f0150364dac1fd1dd8c88828514 /pkg/atlas
parentb4aa149e815c271180a69d94a6954ecceebaab8e (diff)
downloadAtlas-d02c7b58e7c25c548de413b74592b82fc30322a3.tar.gz
Atlas-d02c7b58e7c25c548de413b74592b82fc30322a3.zip
pkg/atlas: Add ATLAS_API0_REGION_MAP config option, use pkg/regionmap by default
Diffstat (limited to 'pkg/atlas')
-rw-r--r--pkg/atlas/config.go4
-rw-r--r--pkg/atlas/server.go18
2 files changed, 22 insertions, 0 deletions
diff --git a/pkg/atlas/config.go b/pkg/atlas/config.go
index 4f411bc..149c9ab 100644
--- a/pkg/atlas/config.go
+++ b/pkg/atlas/config.go
@@ -100,6 +100,10 @@ type Config struct {
// allowed.
API0_MinimumLauncherVersion string `env:"ATLAS_API0_MINIMUM_LAUNCHER_VERSION"`
+ // 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"`
+
// The time after registration for a gameserver to complete verification by.
API0_ServerList_VerifyTime time.Duration `env:"ATLAS_API0_SERVERLIST_VERIFY_TIME=10s"`
diff --git a/pkg/atlas/server.go b/pkg/atlas/server.go
index 2e90af2..7b25dad 100644
--- a/pkg/atlas/server.go
+++ b/pkg/atlas/server.go
@@ -21,12 +21,14 @@ import (
"github.com/VictoriaMetrics/metrics"
"github.com/klauspost/compress/gzip"
+ "github.com/pg9182/ip2x/ip2location"
"github.com/r2northstar/atlas/db/atlasdb"
"github.com/r2northstar/atlas/db/pdatadb"
"github.com/r2northstar/atlas/pkg/api/api0"
"github.com/r2northstar/atlas/pkg/cloudflare"
"github.com/r2northstar/atlas/pkg/memstore"
"github.com/r2northstar/atlas/pkg/origin"
+ "github.com/r2northstar/atlas/pkg/regionmap"
"github.com/rs/zerolog"
"github.com/rs/zerolog/hlog"
"golang.org/x/mod/semver"
@@ -254,6 +256,11 @@ func NewServer(c *Config) (*Server, error) {
} else {
return nil, fmt.Errorf("initialize ip2location: %w", err)
}
+ if m, err := configureRegionMap(c); err == nil {
+ s.API0.GetRegion = m
+ } else {
+ return nil, fmt.Errorf("initialize region map: %w", err)
+ }
s.MetricsSecret = c.MetricsSecret
@@ -631,6 +638,17 @@ func configureIP2Location(c *Config) (*ip2locationMgr, error) {
return mgr, mgr.Load(c.IP2Location)
}
+func configureRegionMap(c *Config) (func(netip.Addr, ip2location.Record) (string, error), error) {
+ switch m := c.API0_RegionMap; m {
+ case "", "none":
+ return nil, nil
+ case "default":
+ return regionmap.GetRegion, nil
+ default:
+ return nil, fmt.Errorf("unknown region map type %q", m)
+ }
+}
+
// 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.