From 6f248f1bd26f2a766ce9a34b50d809f68e3cff02 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Thu, 4 Jun 2020 18:10:55 +0100 Subject: [PATCH] Small server refactor and rename --- pkg/server/routes.go | 2 +- pkg/server/server.go | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pkg/server/routes.go b/pkg/server/routes.go index c18018d..1e503d1 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -176,7 +176,7 @@ func HandleSpawn(s *Server, b io.ReadCloser, w io.Writer) error { fmt.Printf("\tspawn data: %v\n", data) // Create a new instance - if pos, _, err := s.SpawnPrimary(id); err != nil { + if pos, _, err := s.SpawnPrimaryForAccount(id); err != nil { response.Error = err.Error() } else { response.Success = true diff --git a/pkg/server/server.go b/pkg/server/server.go index 6d2eb69..dc94a21 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -92,9 +92,10 @@ func (s *Server) Initialise() error { } } - // Create a new router - s.CreateRoutes() - fmt.Printf("Routes Created\n") + // Set up the handlers + for _, route := range Routes { + s.router.HandleFunc(route.path, s.wrapHandler(route.method, route.handler)) + } // Add to our sync s.sync.Add(1) @@ -160,16 +161,8 @@ func (s *Server) wrapHandler(method string, handler Handler) func(w http.Respons } } -// CreateRoutes sets up the server mux -func (s *Server) CreateRoutes() { - // Set up the handlers - for _, route := range Routes { - s.router.HandleFunc(route.path, s.wrapHandler(route.method, route.handler)) - } -} - -// SpawnPrimary spawns the primary instance for an account -func (s *Server) SpawnPrimary(accountid uuid.UUID) (game.Vector, uuid.UUID, error) { +// SpawnPrimaryForAccount spawns the primary instance for an account +func (s *Server) SpawnPrimaryForAccount(accountid uuid.UUID) (game.Vector, uuid.UUID, error) { inst := uuid.New() s.world.Spawn(inst) if pos, err := s.world.GetPosition(inst); err != nil {