From 25c0404514d89d17503c0685776f51a82297dd1a Mon Sep 17 00:00:00 2001 From: Evan Goode Date: Sun, 19 Jan 2025 22:55:37 -0500 Subject: [PATCH] config: allow unlimited max player count (-1) --- config.go | 4 ++-- config_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index afb118a..fd10102 100644 --- a/config.go +++ b/config.go @@ -182,8 +182,8 @@ func CleanConfig(config *Config) error { if _, err := os.Open(config.DataDirectory); err != nil { return fmt.Errorf("Couldn't open DataDirectory: %s", err) } - if config.DefaultMaxPlayerCount < 0 { - return errors.New("DefaultMaxPlayerCount must be >= 0") + if config.DefaultMaxPlayerCount < 0 && config.DefaultMaxPlayerCount != Constants.MaxPlayerCountUnlimited { + return fmt.Errorf("DefaultMaxPlayerCount must be >= 0, or %d to indicate unlimited players", Constants.MaxPlayerCountUnlimited) } if config.RegistrationExistingPlayer.Allow { if config.RegistrationExistingPlayer.Nickname == "" { diff --git a/config_test.go b/config_test.go index a5f85a6..7e7f396 100644 --- a/config_test.go +++ b/config_test.go @@ -51,6 +51,14 @@ func TestConfig(t *testing.T) { config.ListenAddress = "" assert.NotNil(t, CleanConfig(config)) + config = configTestConfig(sd) + config.DefaultMaxPlayerCount = Constants.MaxPlayerCountUseDefault + assert.NotNil(t, CleanConfig(config)) + + config = configTestConfig(sd) + config.DefaultMaxPlayerCount = Constants.MaxPlayerCountUnlimited + assert.Nil(t, CleanConfig(config)) + config = configTestConfig(sd) config.DataDirectory = "/tmp/DraslInvalidDataDirectoryNothingHere" assert.NotNil(t, CleanConfig(config))