Skip to content

Commit

Permalink
fixed configuration byte size mask bug
Browse files Browse the repository at this point in the history
  • Loading branch information
espidev committed Apr 2, 2018
1 parent c260c1e commit b8796a1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 60 deletions.
20 changes: 14 additions & 6 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
{
"instance_name": "Server",
"instance_port": 6921,
"sslencryption": false,
"cert_file_path": "./cert.crt",
"servers": [
{
"instance_name": "Server1",
"home_directory": "/home/devin/Flow/ECExp",
"command_to_run": "java -Xmx512M -Xms2G -XX:+UseG1GC -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -d64 -server -jar minecraft_server.jar",
"command_to_run": "java -Xmx2G -Xms512M -XX:+UseG1GC -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -d64 -server -jar minecraft_server.jar",
"max_lines": 2000,
"amount_of_lines_to_cut_on_max": 100,
"stop_process_command": "stop",
"server_unresponsive_kill_time_seconds": 20,
"unresponsive_kill_time_seconds": 20,
"minecraft_mode": true
},
{
"instance_name": "Server2",
"home_directory": "/home/devin/Flow/ECExp2",
"command_to_run": "java -Xmx2G -Xms512M -XX:+UseG1GC -XX:ParallelGCThreads=2 -XX:+AggressiveOpts -d64 -server -jar minecraft_server.jar",
"max_lines": 2000,
"amount_of_lines_to_cut_on_max": 100,
"stop_process_command": "stop",
"unresponsive_kill_time_seconds": 20,
"minecraft_mode": true
}
],
"users": [
{
"name": "default",
"password": "password"
},
{
"name": "defaults",
"password": "password"
}
]
}
41 changes: 0 additions & 41 deletions config.json.old

This file was deleted.

Binary file modified server
Binary file not shown.
29 changes: 19 additions & 10 deletions src/server/main/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"os"
"io"
"encoding/json"
"bytes"
"reflect"
"fmt"
"archive/zip"
"time"
"encoding/json"
"bytes"
)

/*
Expand All @@ -25,10 +25,12 @@ type Users struct {
*/

type InstanceConfig struct {
InstanceName string `json:"instance_name"`
InstancePort uint `json:"instance_port"`
Servers []ServerConfig `json:"servers"`
Users []Users `json:"users"`
InstanceName string `json:"instance_name"`
InstancePort uint `json:"instance_port"`
SSLEncryption bool `json:"sslencryption"`
CertFilePath string `json:"cert_file_path"`
Servers []ServerConfig `json:"servers"`
Users []Users `json:"users"`
}

/*
Expand All @@ -38,11 +40,11 @@ type InstanceConfig struct {
type ServerConfig struct {
InstanceName string `json:"instance_name"`
HomeDirectory string `json:"home_directory"`
CommandToRun string `json:"command_to_run"`
CommandToRun string `json:"command_to_run"`
MaxLines uint `json:"max_lines"`
AmountOfLinesToCutOnMax uint `json:"amount_of_lines_to_cut_on_max"`
StopProcessCommand string `json:"stop_process_command"`
ServerUnresponsiveKillTimeSeconds uint `json:"server_unresponsive_kill_time_seconds"`
UnresponsiveKillTimeSeconds uint `json:"unresponsive_kill_time_seconds"`
MinecraftMode bool `json:"minecraft_mode"`
}

Expand All @@ -54,6 +56,8 @@ func ConfigDefault() (InstanceConfig, ServerConfig, Users) {
con := InstanceConfig{}
con.InstanceName = "Server"
con.InstancePort = 6921
con.SSLEncryption = true
con.CertFilePath = "./cert.crt"

wi := ServerConfig{}
wi.InstanceName = "Server1"
Expand All @@ -62,7 +66,7 @@ func ConfigDefault() (InstanceConfig, ServerConfig, Users) {
wi.MaxLines = 2000
wi.AmountOfLinesToCutOnMax = 100
wi.StopProcessCommand = "stop"
wi.ServerUnresponsiveKillTimeSeconds = 20
wi.UnresponsiveKillTimeSeconds = 20
wi.MinecraftMode = true

users := Users{}
Expand Down Expand Up @@ -97,7 +101,11 @@ func LoadConfig() {
if err2 != nil {
logFatal(err2)
}
var text = make([]byte, 1024) //Read the file and set it to text
fi, e := os.Stat(configPath) //get size of file in bytes
if e != nil {
logFatal(e)
}
var text = make([]byte, fi.Size()+1) //Read the file and set it to text
for {
_, err = file.Read(text)
if err == io.EOF {
Expand All @@ -113,6 +121,7 @@ func LoadConfig() {
info("Extracted config contents!")
//Parse json
var config InstanceConfig

err3 := json.Unmarshal(text, &config)
if err3 != nil {
info(err3.Error())
Expand Down
4 changes: 2 additions & 2 deletions src/server/main/esticonsole.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func Shutdown() {

var maxKillTime uint
for _, server := range Servers { //get the longest unresponsive kill time period
if server.Settings.ServerUnresponsiveKillTimeSeconds > maxKillTime {
maxKillTime = server.Settings.ServerUnresponsiveKillTimeSeconds
if server.Settings.UnresponsiveKillTimeSeconds > maxKillTime {
maxKillTime = server.Settings.UnresponsiveKillTimeSeconds
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/server/main/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func ClientsStop() {
go func(server *Server) {
server.AutoStart = false
server.stop()
time.Sleep(time.Second * time.Duration(server.Settings.ServerUnresponsiveKillTimeSeconds))
time.Sleep(time.Second * time.Duration(server.Settings.UnresponsiveKillTimeSeconds))
if server.IsOnline {
server.Process.Process.Kill()
}
Expand Down

0 comments on commit b8796a1

Please sign in to comment.