From 013906e0bbc6884d336843e5cc17324be39a8dd4 Mon Sep 17 00:00:00 2001 From: gekigek99 <53654579+gekigek99@users.noreply.github.com> Date: Thu, 16 Mar 2023 12:30:02 +0100 Subject: [PATCH] config: added EnableQuery in config file --- README.md | 3 ++- lib/config/config.go | 23 +++++++++++++++++++++-- lib/model/model.go | 1 + minecraft-server-hibernation.go | 4 +--- msh-config.json | 1 + 5 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b424dd8c..1f448fcf 100644 --- a/README.md +++ b/README.md @@ -100,10 +100,11 @@ Set the logging level for debug purposes Ports configuration - _MshPort and MshPortQuery must be different from the respective ones in `server.properties`_ -- _msh enables query handling if `enable-query=true` in `server.properties`_ +- _query handling is enabled if `EnableQuery: true` in `msh-config.json` or `enable-query=true` in `server.properties`_ ```yaml "MshPort": 25555 # port to which players can join "MshPortQuery": 25555 # port to which stats query requests are performed from clients +"EnableQuery": true # enable query handling ``` TimeBeforeStoppingEmptyServer sets the time (after the last player disconnected) that msh waits before hibernating the minecraft server diff --git a/lib/config/config.go b/lib/config/config.go index 4c9d7fda..cca169ed 100644 --- a/lib/config/config.go +++ b/lib/config/config.go @@ -195,6 +195,7 @@ func (c *Configuration) loadRuntime(confdef *Configuration) *errco.MshLog { flag.IntVar(&c.Msh.MshPortQuery, "portquery", c.Msh.MshPortQuery, "Specify msh port for queries.") flag.IntVar(&ServPort, "servport", ServPort, "Specify the minecraft server port.") flag.IntVar(&ServPortQuery, "servportquery", ServPortQuery, "Specify minecraft server port for queries.") + flag.BoolVar(&c.Msh.EnableQuery, "enablequery", c.Msh.EnableQuery, "Enables queries handling.") flag.Int64Var(&c.Msh.TimeBeforeStoppingEmptyServer, "timeout", c.Msh.TimeBeforeStoppingEmptyServer, "Specify time to wait before stopping minecraft server.") flag.BoolVar(&c.Msh.SuspendAllow, "suspendallow", c.Msh.SuspendAllow, "Enables minecraft server process suspension.") flag.IntVar(&c.Msh.SuspendRefresh, "suspendrefresh", c.Msh.SuspendRefresh, "Specify how often the suspended minecraft server process must be refreshed.") @@ -324,8 +325,26 @@ func (c *Configuration) loadRuntime(confdef *Configuration) *errco.MshLog { servstats.Stats.SetMajorError(logMsh) } - errco.NewLogln(errco.TYPE_INF, errco.LVL_3, errco.ERROR_NIL, "msh connection proxy setup: %s:%d --> %s:%d", MshHost, MshPort, ServHost, ServPort) - errco.NewLogln(errco.TYPE_INF, errco.LVL_3, errco.ERROR_NIL, "msh stats query proxy setup: %s:%d --> %s:%d", MshHost, MshPortQuery, ServHost, ServPortQuery) + errco.NewLogln(errco.TYPE_INF, errco.LVL_3, errco.ERROR_NIL, "msh connection proxy setup: %10s:%5d --> %10s:%5d", MshHost, MshPort, ServHost, ServPort) + + // check if queries are enabled by config, start arguments or ms config + queriesStatus := "queries disabled" + if c.Msh.EnableQuery { + queriesStatus = "queries enabled by msh config or start arguments" + } else if msConfigQueryEnabled, logMsh := c.ParsePropertiesBool("enable-query"); logMsh != nil { + queriesStatus = "queries disabled by error" + c.Msh.EnableQuery = false + logMsh.Log(true) + } else if msConfigQueryEnabled { + queriesStatus = "queries enabled by minecraft server config" + c.Msh.EnableQuery = true + } + + if c.Msh.EnableQuery { + errco.NewLogln(errco.TYPE_INF, errco.LVL_3, errco.ERROR_NIL, "msh stats query proxy setup: %10s:%5d --> %10s:%5d (%s)", MshHost, MshPortQuery, ServHost, ServPortQuery, queriesStatus) + } else { + errco.NewLogln(errco.TYPE_INF, errco.LVL_3, errco.ERROR_NIL, "%s", queriesStatus) + } // load ms version/protocol c.Server.Version, c.Server.Protocol, logMsh = c.getVersionInfo() diff --git a/lib/model/model.go b/lib/model/model.go index 7716528e..7841e5de 100644 --- a/lib/model/model.go +++ b/lib/model/model.go @@ -19,6 +19,7 @@ type Configuration struct { ID string `json:"ID"` MshPort int `json:"MshPort"` MshPortQuery int `json:"MshPortQuery"` + EnableQuery bool `json:"EnableQuery"` TimeBeforeStoppingEmptyServer int64 `json:"TimeBeforeStoppingEmptyServer"` SuspendAllow bool `json:"SuspendAllow"` // specify if msh should suspend java server process SuspendRefresh int `json:"SuspendRefresh"` // specify if msh should refresh java server process suspension and every how many seconds diff --git a/minecraft-server-hibernation.go b/minecraft-server-hibernation.go index 368c4b78..c39fa1d1 100644 --- a/minecraft-server-hibernation.go +++ b/minecraft-server-hibernation.go @@ -56,9 +56,7 @@ func main() { // ---------------- connections ---------------- // // launch query handler - if queryEnabled, logMsh := config.ConfigRuntime.ParsePropertiesBool("enable-query"); logMsh != nil { - logMsh.Log(true) - } else if queryEnabled { + if config.ConfigRuntime.Msh.EnableQuery { go conn.HandlerQuery() } diff --git a/msh-config.json b/msh-config.json index fec46839..aac197fc 100644 --- a/msh-config.json +++ b/msh-config.json @@ -16,6 +16,7 @@ "ID": "", "MshPort": 25555, "MshPortQuery": 25555, + "EnableQuery": true, "TimeBeforeStoppingEmptyServer": 30, "SuspendAllow": false, "SuspendRefresh": -1,