(ts time.Time)
| 149 | } |
| 150 | |
| 151 | func (srv *Server) Start(ts time.Time) { |
| 152 | if slices.Index(os.Args, "--no-plugins") == -1 { |
| 153 | if runtime.GOOS == "darwin" || runtime.GOOS == "linux" || runtime.GOOS == "freebsd" { |
| 154 | log.Infoln("Loading plugins") |
| 155 | srv.loadPlugins() |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | log.Info("Preparing world spawn... ") |
| 160 | ow := srv.World.Dimension("minecraft:overworld") |
| 161 | var chunks int32 |
| 162 | |
| 163 | spawnCX, spawnCZ := srv.World.Data.SpawnX>>4, srv.World.Data.SpawnZ>>4 |
| 164 | for x := spawnCX - srv.cfg.ViewDistance; x < spawnCX+srv.cfg.ViewDistance; x++ { |
| 165 | for z := spawnCZ - srv.cfg.ViewDistance; z < spawnCZ+srv.cfg.ViewDistance; z++ { |
| 166 | _, err := ow.GetChunk(x, z) |
| 167 | if err == nil { |
| 168 | chunks++ |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | fmt.Printf("cached %d chunks\n\r", chunks) |
| 174 | |
| 175 | srv.timeStart = ts |
| 176 | log.Infolnf("Done! (%s)", time.Since(ts)) |
| 177 | for { |
| 178 | conn, err := srv.listener.Accept() |
| 179 | if err != nil { |
| 180 | if !srv.closed { |
| 181 | log.Errorln("Server error: ", err) |
| 182 | } |
| 183 | <-srv.stopLoop |
| 184 | return |
| 185 | } |
| 186 | if srv.onConnectionIntercept != nil { |
| 187 | var stop bool |
| 188 | srv.onConnectionIntercept(conn, &stop) |
| 189 | if stop { |
| 190 | continue |
| 191 | } |
| 192 | } |
| 193 | srv.handleNewConnection(conn) |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func (srv *Server) handleNewConnection(conn *net.Conn) { |
| 198 | log.Infolnf("%sPlayer attempting to connect: %s (%s)", log.FormatAddr(srv.cfg.LogIPs, conn.RemoteAddr()), conn.Username(), conn.UUID()) |
no test coverage detected