Skip to content

Commit

Permalink
server/server.go: Fixed race checker error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Nov 23, 2024
1 parent 414ed1b commit d5c7ba7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 9 additions & 1 deletion server/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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()

Expand Down
12 changes: 3 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit d5c7ba7

Please sign in to comment.