forked from ZeppelinMC/Zeppelin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (59 loc) · 1.68 KB
/
main.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
package main
import (
"os"
"runtime"
"runtime/pprof"
"time"
"github.com/zeppelinmc/zeppelin/core_commands"
"github.com/zeppelinmc/zeppelin/log"
"github.com/zeppelinmc/zeppelin/server"
"github.com/zeppelinmc/zeppelin/server/command"
"github.com/zeppelinmc/zeppelin/server/world"
"github.com/zeppelinmc/zeppelin/util"
"golang.org/x/term"
)
var timeStart = time.Now()
func main() {
log.Infolnf("Zeppelin 1.21 Minecraft server with %s on platform %s-%s", runtime.Version(), runtime.GOOS, runtime.GOARCH)
if util.HasArgument("--cpuprof") {
f, _ := os.Create("zeppelin-cpu-profile")
pprof.StartCPUProfile(f)
log.Infoln("Started CPU profiler (writing to zeppelin-cpu-profile)")
}
cfg := loadConfig()
w, err := world.NewWorld(cfg.LevelName)
if err != nil {
log.Errorlnf("Error preparing level: %v", w)
return
}
log.Infof("Binding server to %s:%d\n", cfg.ServerIp, cfg.ServerPort)
rawTerminal := !util.HasArgument("--no-raw-terminal")
srv, err := server.New(cfg, w)
if err != nil {
log.Errorln("Error binding server:", err)
return
}
srv.CommandManager = command.NewManager(srv, core_commands.Commands...)
var oldState *term.State
if rawTerminal {
oldState, err = term.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
go terminalHandler(srv)
defer term.Restore(int(os.Stdin.Fd()), oldState)
} else {
go notRawTerminal(srv)
}
srv.Start(timeStart)
if util.HasArgument("--cpuprof") {
log.Infoln("Stopped CPU profiler")
pprof.StopCPUProfile()
}
if util.HasArgument("--memprof") {
log.InfolnClean("Writing memory profile to zeppelin-mem-profile")
f, _ := os.Create("zeppelin-mem-profile")
pprof.Lookup("allocs").WriteTo(f, 0)
f.Close()
}
}