-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathminecraft-server-hibernation.go
81 lines (68 loc) · 2.01 KB
/
minecraft-server-hibernation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"net"
"msh/lib/config"
"msh/lib/conn"
"msh/lib/errco"
"msh/lib/input"
"msh/lib/progmgr"
"msh/lib/servctrl"
"msh/lib/utility"
)
// contains intro to script and program
var intro []string = []string{
" _ __ ___ ___| |__ ",
"| '_ ` _ \\/ __| '_ \\ ",
"| | | | | \\__ \\ | | | " + progmgr.MshVersion,
"|_| |_| |_|___/_| |_| " + progmgr.MshCommit,
"Copyright (C) 2019-2023 gekigek99",
"github: https://github.com/gekigek99",
"remember to give a star to this repository!",
}
func main() {
// print program intro
// not using errco.NewLogln since log time is not needed
fmt.Println(utility.Boxify(intro))
// load configuration from msh config file
logMsh := config.LoadConfig()
if logMsh != nil {
logMsh.Log(true)
progmgr.AutoTerminate()
}
// launch msh manager
go progmgr.MshMgr()
// wait for the initial update check
<-progmgr.ReqSent
// if ms suspension is allowed, pre-warm the server
if config.ConfigRuntime.Msh.SuspendAllow {
errco.NewLogln(errco.TYPE_INF, errco.LVL_1, errco.ERROR_NIL, "minecraft server will now pre-warm (SuspendAllow is enabled)...")
logMsh = servctrl.WarmMS()
if logMsh != nil {
logMsh.Log(true)
}
}
// launch GetInput()
go input.GetInput()
// ---------------- connections ---------------- //
// launch query handler
if config.ConfigRuntime.Msh.EnableQuery {
go conn.HandlerQuery()
}
// open a tcp listener
listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", config.MshHost, config.MshPort))
if err != nil {
errco.NewLogln(errco.TYPE_ERR, errco.LVL_3, errco.ERROR_CLIENT_LISTEN, err.Error())
progmgr.AutoTerminate()
}
// infinite cycle to handle new clients.
errco.NewLogln(errco.TYPE_INF, errco.LVL_1, errco.ERROR_NIL, "%-40s %10s:%5d ...", "listening for new clients connections on", config.MshHost, config.MshPort)
for {
clientConn, err := listener.Accept()
if err != nil {
errco.NewLogln(errco.TYPE_ERR, errco.LVL_3, errco.ERROR_CLIENT_ACCEPT, err.Error())
continue
}
go conn.HandlerClientConn(clientConn)
}
}