Small server refactor and rename

This commit is contained in:
Marc Di Luzio 2020-06-04 18:10:55 +01:00
parent da9d71bcc0
commit 6f248f1bd2
2 changed files with 7 additions and 14 deletions

View file

@ -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

View file

@ -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 {