MCPcopy Create free account
hub / github.com/ZeppelinMC/Zeppelin / New

Function New

server/server.go:31–88  ·  view source on GitHub ↗

Creates a new server instance using the specified config, returns an error if unable to bind listener

(cfg properties.ServerProperties, world *world.World)

Source from the content-addressed store, hash-verified

29
30// Creates a new server instance using the specified config, returns an error if unable to bind listener
31func New(cfg properties.ServerProperties, world *world.World) (*Server, error) {
32 var ip = nnet.ParseIP(cfg.ServerIp)
33 if ip == nil {
34 ip = nnet.IPv4(0, 0, 0, 0)
35 }
36
37 lcfg := net.Config{
38 IP: ip,
39 Port: int(cfg.ServerPort),
40 CompressionThreshold: int32(cfg.NetworkCompressionThreshold),
41 Encrypt: cfg.EnableEncryption || cfg.OnlineMode,
42 Authenticate: cfg.OnlineMode,
43 AcceptTransfers: cfg.AcceptTransfers,
44 }
45 if !cfg.OnlineMode {
46 log.Warnln("Server is not enforcing authentication. The server will let anyone log as any username and potentially harm the server. Proceed with caution")
47 }
48
49 listener, err := lcfg.New()
50 server := &Server{
51 listener: listener,
52 cfg: cfg,
53 World: world,
54 Players: state.NewPlayerEntityManager(),
55 stopLoop: make(chan struct{}),
56 playerList: player.NewPlayerList(0),
57 }
58 server.icon, err = os.ReadFile("server-icon.png")
59 if err == nil {
60 img, err := png.Decode(bytes.NewReader(server.icon))
61 if err != nil {
62 log.Warn("Server icon must be a 64x64 image in the PNG format")
63 }
64 b := img.Bounds()
65 if b.Dx() != 64 || b.Dy() != 64 {
66 log.Warn("Server icon must be a 64x64 image in the PNG format")
67 }
68 }
69
70 //server.Console = &Console{Server: server}
71 //server.World.Broadcast.AddDummy(server.Console)
72 server.listener.SetStatusProvider(server.provideStatus)
73
74 if server.cfg.EnforceSecureProfile && !cfg.OnlineMode {
75 server.cfg.EnforceSecureProfile = false
76 }
77
78 compstr := "compress everything"
79 if cfg.NetworkCompressionThreshold > 0 {
80 compstr = fmt.Sprintf("compress everything starting from %d bytes", cfg.NetworkCompressionThreshold)
81 } else if cfg.NetworkCompressionThreshold < 0 {
82 compstr = "no compression"
83 }
84
85 log.Infolnf("Network compression threshold is %d (%s)", cfg.NetworkCompressionThreshold, compstr)
86 //server.createTicker()
87 return server, err
88}

Callers 1

mainFunction · 0.92

Calls 8

NewMethod · 0.95
WarnlnFunction · 0.92
NewPlayerEntityManagerFunction · 0.92
NewPlayerListFunction · 0.92
WarnFunction · 0.92
InfolnfFunction · 0.92
DecodeMethod · 0.65
SetStatusProviderMethod · 0.45

Tested by

no test coverage detected