Skip to content

Commit

Permalink
config: added EnableQuery in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
gekigek99 committed Mar 16, 2023
1 parent 3467f9e commit 013906e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions lib/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions minecraft-server-hibernation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
1 change: 1 addition & 0 deletions msh-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"ID": "",
"MshPort": 25555,
"MshPortQuery": 25555,
"EnableQuery": true,
"TimeBeforeStoppingEmptyServer": 30,
"SuspendAllow": false,
"SuspendRefresh": -1,
Expand Down

0 comments on commit 013906e

Please sign in to comment.