You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
1.4 KiB
83 lines
1.4 KiB
package main |
|
|
|
import ( |
|
"bufio" |
|
"encoding/json" |
|
"io/ioutil" |
|
"os" |
|
"os/signal" |
|
"strings" |
|
"syscall" |
|
"time" |
|
|
|
"github.com/rudi9719/loggy" |
|
) |
|
|
|
var ( |
|
// Logging Setup |
|
logOpts = loggy.LogOpts{ |
|
UseStdout: true, |
|
Level: 5, |
|
OutFile: "Minedall.log", |
|
} |
|
log = loggy.NewLogger(logOpts) |
|
config Config |
|
onlineUsers []User |
|
serverRebooting = false |
|
) |
|
|
|
func loadConfig() { |
|
var c Config |
|
confFile, _ := ioutil.ReadFile("config.json") |
|
err := json.Unmarshal([]byte(confFile), &c) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
return |
|
} |
|
config = c |
|
} |
|
func saveConfig() { |
|
file, err := json.Marshal(config) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} |
|
err = ioutil.WriteFile("config.json", file, 0766) |
|
if err != nil { |
|
log.LogErrorType(err) |
|
} else { |
|
log.LogInfo("Config saved.") |
|
} |
|
} |
|
|
|
func main() { |
|
loadConfig() |
|
if config.DiscordToken == "" { |
|
time.Sleep(5 * time.Second) |
|
return |
|
} |
|
|
|
config.StartTime = time.Now() |
|
go configureDiscord() |
|
go configureMinecraft() |
|
go dbSetup() |
|
// Wait here until CTRL-C or other term signal is received. |
|
log.LogInfo("Minedall is now running. Press CTRL-C to exit.") |
|
|
|
sc := make(chan os.Signal, 1) |
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) |
|
reader := bufio.NewReader(os.Stdin) |
|
for { |
|
text, _ := reader.ReadString('\n') |
|
if strings.Contains(text, "stop") { |
|
saveConfig() |
|
mcExit() |
|
discordExit() |
|
return |
|
} |
|
mcCommand(text) |
|
} |
|
<-sc |
|
|
|
mcExit() |
|
discordExit() |
|
}
|
|
|