diff --git a/config.yml b/config.yml index 28aeff45..804e3ea8 100644 --- a/config.yml +++ b/config.yml @@ -1,12 +1,76 @@ -# This is a simplified config where the rest of the -# settings are omitted and will be set by default. +# The bind address to listen for Minecraft client connections. bind: 0.0.0.0:25565 +# Whether to use the proxy in online (authenticate players with Mojang API) or offline mode (not recommended). onlineMode: true -compression: - threshold: 256 +# Registers servers with the proxy by giving the address of backend server a custom reference name. servers: + # Server name: server address server1: localhost:25566 server2: localhost:25567 +# The list of servers to try (ordered) to connect a player to +# upon login or fallback when a player is kicked from a server. try: - server1 - server2 +# Configure the response for server list pings. +status: + favIconFile: server-icon.png + # The maximum players shown (is not the actual player limit!). + maxPlayers: 1000 + motd: §bA Gate Proxy Server! + # Whether to log ping requests in the console. + showPingRequests: false + # Whether the proxy should present itself as Forge/FML-compatible server. + announceForge: false +# Whether the proxy should support bungee plugin channels. +# (Disable this if your backend servers are untrusted.) +bungeePluginChannelEnabled: true +compression: + # The minimum size (in bytes) a packet must be before the proxy compresses it. + # The Minecraft vanilla server uses 256 by default. + threshold: 256 + # Indicates what zlib compression level Gate should use. + # It goes from -1 to 9 where zero means no compression and -1 the default. + level: -1 +# The time in milliseconds Gate waits to connect to a server before timing out. +connectionTimeout: 5000 +# The time in milliseconds Gate waits to receive data from a server before timing out. +# If you use Forge, you may need to increase this setting. +readTimeout: 30000 +# Whether to reconnect the player when disconnected from a server. +failoverOnUnexpectedServerDisconnect: true +# Enabled extra debug logging (only for debugging purposes). +debug: false +# This allows you to customize how player information such as IPs and UUIDs are forwarded to your server. +# See the documentation for more information. +forwarding: + # Options: legacy, none, velocity + mode: legacy +# The section for health checking when Gate runs in a Kubernetes pod. +# Refer to https://github.com/grpc-ecosystem/grpc-health-probe for more details. +# Gate is also delivered with a docker image where the health check service is enabled by default. +health: + enabled: false + bind: 0.0.0.0:8080 +# The quota settings allows rate-limiting IP (last block cut off) for certain operations. +# ops: The allowed operations per second. +# burst: The maximum operations per second (queue like). One burst unit per seconds is refilled. +# maxEntries: The maximum IPs to keep track of in cache for rate-limiting (if full, deletes oldest). +quota: + # Limit how many new connections can be established by the same IP range. + connections: + enabled: true + ops: 5 + burst: 10 + maxEntries: 1000 + # Limit how many login requests can be made by the same IP range. + logins: + enabled: true + burst: 3 + ops: 0.4 + maxentries: 1000 +# Whether and how Gate should reply to GameSpy 4 (Minecraft query protocol) requests. +query: + enabled: false + port: 25577 + showPlugins: false \ No newline at end of file diff --git a/internal/util/quotautil/quota.go b/internal/util/quotautil/quota.go index c1f8e5fd..9ceaa0cc 100644 --- a/internal/util/quotautil/quota.go +++ b/internal/util/quotautil/quota.go @@ -13,7 +13,7 @@ import ( // Information is kept in an LRU cache of size maxEntries. type Quota struct { eps float32 // allowed events per second - burst int // maximum event per second (queue) + burst int // maximum events per second (queue) mu sync.Mutex // protects cache cache *lru.Cache } diff --git a/pkg/config/config.go b/pkg/config/config.go index 3fff3802..f79a7ce4 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -38,9 +38,8 @@ type Config struct { BungeePluginChannelEnabled bool - Debug bool - ConfigAutoUpdate bool - Health HealthProbeService + Debug bool + Health HealthProbeService } type ( @@ -100,15 +99,15 @@ func init() { viper.SetDefault("bind", "0.0.0.0:25565") viper.SetDefault("onlineMode", true) viper.SetDefault("forwarding.mode", LegacyForwardingMode) - viper.SetDefault("announceForge", false) viper.SetDefault("status.motd", "§bA Gate Proxy Server!") viper.SetDefault("status.maxplayers", 1000) viper.SetDefault("status.faviconfile", "server-icon.png") + viper.SetDefault("status.announceForge", false) viper.SetDefault("status.showPingRequests", false) viper.SetDefault("compression.threshold", 256) - viper.SetDefault("compression.level", 1) + viper.SetDefault("compression.level", -1) viper.SetDefault("query.enabled", false) viper.SetDefault("query.port", 25577) @@ -130,7 +129,6 @@ func init() { viper.SetDefault("readtimeout", 30000) viper.SetDefault("BungeePluginChannelEnabled", true) viper.SetDefault("FailoverOnUnexpectedServerDisconnect", true) - viper.SetDefault("configautoupdate", false) viper.SetDefault("Health.enabled", false) viper.SetDefault("Health.bind", "0.0.0.0:8080") diff --git a/pkg/proxy/proxy.go b/pkg/proxy/proxy.go index 8ba0c018..60fcb090 100644 --- a/pkg/proxy/proxy.go +++ b/pkg/proxy/proxy.go @@ -88,6 +88,9 @@ func (p *Proxy) run() error { for name, addr := range p.config.Servers { p.Register(NewServerInfo(name, tcpAddr(addr))) } + if len(p.config.Servers) != 0 { + zap.S().Infof("Registered %d servers from the config", len(p.config.Servers)) + } errChan := make(chan error, 1) wg := new(sync.WaitGroup) @@ -153,8 +156,16 @@ func (p *Proxy) Servers() []RegisteredServer { // Register registers a server with the proxy. // // Returns the new registered server and true on success. -// On failure returns false and the already registered server with the same name. +// +// On failure either: +// - if name already exists, returns the already registered server and false +// - if the name or address specified in the info is invalid, returns nil and false. func (p *Proxy) Register(info ServerInfo) (RegisteredServer, bool) { + if !config.ValidServerName(info.Name()) || + config.ValidHostPort(info.Addr().String()) != nil { + return nil, false + } + name := strings.ToLower(info.Name()) p.mu.Lock()