Small server refactor and rename
This commit is contained in:
parent
da9d71bcc0
commit
6f248f1bd2
2 changed files with 7 additions and 14 deletions
|
@ -176,7 +176,7 @@ func HandleSpawn(s *Server, b io.ReadCloser, w io.Writer) error {
|
||||||
fmt.Printf("\tspawn data: %v\n", data)
|
fmt.Printf("\tspawn data: %v\n", data)
|
||||||
|
|
||||||
// Create a new instance
|
// Create a new instance
|
||||||
if pos, _, err := s.SpawnPrimary(id); err != nil {
|
if pos, _, err := s.SpawnPrimaryForAccount(id); err != nil {
|
||||||
response.Error = err.Error()
|
response.Error = err.Error()
|
||||||
} else {
|
} else {
|
||||||
response.Success = true
|
response.Success = true
|
||||||
|
|
|
@ -92,9 +92,10 @@ func (s *Server) Initialise() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new router
|
// Set up the handlers
|
||||||
s.CreateRoutes()
|
for _, route := range Routes {
|
||||||
fmt.Printf("Routes Created\n")
|
s.router.HandleFunc(route.path, s.wrapHandler(route.method, route.handler))
|
||||||
|
}
|
||||||
|
|
||||||
// Add to our sync
|
// Add to our sync
|
||||||
s.sync.Add(1)
|
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
|
// SpawnPrimaryForAccount spawns the primary instance for an account
|
||||||
func (s *Server) CreateRoutes() {
|
func (s *Server) SpawnPrimaryForAccount(accountid uuid.UUID) (game.Vector, uuid.UUID, error) {
|
||||||
// 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) {
|
|
||||||
inst := uuid.New()
|
inst := uuid.New()
|
||||||
s.world.Spawn(inst)
|
s.world.Spawn(inst)
|
||||||
if pos, err := s.world.GetPosition(inst); err != nil {
|
if pos, err := s.world.GetPosition(inst); err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue