From d5c7ba7977bce8b87aa5c3677d39e875a65d4135 Mon Sep 17 00:00:00 2001 From: Sandertv Date: Sat, 23 Nov 2024 23:29:14 +0100 Subject: [PATCH] server/server.go: Fixed race checker error. --- server/conf.go | 10 +++++++++- server/server.go | 12 +++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/server/conf.go b/server/conf.go index 10443c5e4..6bfa72e85 100644 --- a/server/conf.go +++ b/server/conf.go @@ -133,7 +133,7 @@ func (conf Config) New() *Server { conf.Resources = append(conf.Resources, pack) } } - // Copy resources so that the slice can't be edited afterwards. + // Copy resources so that the slice can't be edited afterward. conf.Resources = slices.Clone(conf.Resources) srv := &Server{ @@ -142,6 +142,14 @@ func (conf Config) New() *Server { p: make(map[uuid.UUID]*onlinePlayer), world: &world.World{}, nether: &world.World{}, end: &world.World{}, } + for _, lf := range conf.Listeners { + l, err := lf(conf) + if err != nil { + conf.Log.Error("create listener: " + err.Error()) + } + srv.listeners = append(srv.listeners, l) + } + world_finaliseBlockRegistry() recipe_registerVanilla() diff --git a/server/server.go b/server/server.go index a8db716b1..98bfc7943 100644 --- a/server/server.go +++ b/server/server.go @@ -139,7 +139,7 @@ func (srv *Server) Accept() iter.Seq[*player.Player] { ret := false <-inc.w.Exec(func(tx *world.Tx) { - p := tx.AddEntity(inc.p.handle).(*player.Player) + p := tx.AddEntity(inc.p.handle).(*player.Player) // TODO: This requires that the session already has `s.ent` set. This only happens in inc.s.Spawn though... inc.conf.Finalise(p) inc.s.Spawn(p, tx) ret = !yield(p) @@ -359,14 +359,8 @@ func (srv *Server) startListening() { srv.makeBlockEntries() srv.makeItemComponents() - srv.wg.Add(len(srv.conf.Listeners)) - for _, lf := range srv.conf.Listeners { - l, err := lf(srv.conf) - if err != nil { - srv.conf.Log.Error("create listener: " + err.Error()) - return - } - srv.listeners = append(srv.listeners, l) + srv.wg.Add(len(srv.listeners)) + for _, l := range srv.listeners { go srv.listen(l) } }