From d9e97ea468a6a45d7455ee5d87eaa7aaf3dbec14 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 7 Jul 2020 22:46:34 +0100 Subject: [PATCH 1/4] Add some additional logging to requests and world resizes --- cmd/rove-server/internal/routes.go | 11 +++++++++-- pkg/atlas/atlas.go | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/rove-server/internal/routes.go b/cmd/rove-server/internal/routes.go index c8d04ef..8ec49bc 100644 --- a/cmd/rove-server/internal/routes.go +++ b/cmd/rove-server/internal/routes.go @@ -3,6 +3,7 @@ package internal import ( "context" "fmt" + "log" "github.com/mdiluz/rove/pkg/game" "github.com/mdiluz/rove/pkg/rove" @@ -18,8 +19,6 @@ func (s *Server) ServerStatus(context.Context, *rove.ServerStatusRequest) (*rove CurrentTick: int32(s.world.CurrentTicks), } - // TODO: Verify the accountant is up and ready too - // If there's a schedule, respond with it if len(s.schedule.Entries()) > 0 { response.NextTick = s.schedule.Entries()[0].Next.Format("15:04:05") @@ -30,6 +29,8 @@ func (s *Server) ServerStatus(context.Context, *rove.ServerStatusRequest) (*rove // Register registers a new account for a gRPC request func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove.RegisterResponse, error) { + log.Printf("Handling register request: %s\n", req.Name) + if len(req.Name) == 0 { return nil, fmt.Errorf("empty account name") } @@ -55,6 +56,8 @@ func (s *Server) Register(ctx context.Context, req *rove.RegisterRequest) (*rove // Status returns rover information for a gRPC request func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response *rove.StatusResponse, err error) { + log.Printf("Handling status request: %s\n", req.Account.Name) + if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil { return nil, err @@ -110,6 +113,8 @@ func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response // Radar returns the radar information for a rover func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.RadarResponse, error) { + log.Printf("Handling radar request: %s\n", req.Account.Name) + if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil { return nil, err @@ -140,6 +145,8 @@ func (s *Server) Radar(ctx context.Context, req *rove.RadarRequest) (*rove.Radar // Command issues commands to the world based on a gRPC request func (s *Server) Command(ctx context.Context, req *rove.CommandRequest) (*rove.CommandResponse, error) { + log.Printf("Handling command request: %s and %+v\n", req.Account.Name, req.Commands) + if valid, err := s.accountant.VerifySecret(req.Account.Name, req.Account.Secret); err != nil { return nil, err diff --git a/pkg/atlas/atlas.go b/pkg/atlas/atlas.go index 0840873..2e157b7 100644 --- a/pkg/atlas/atlas.go +++ b/pkg/atlas/atlas.go @@ -1,6 +1,7 @@ package atlas import ( + "log" "math/rand" "github.com/mdiluz/rove/pkg/maths" @@ -218,6 +219,9 @@ func (a *Atlas) worldSpaceToChunkWithGrow(v vector.Vector) int { Chunks: make([]Chunk, size.X*size.Y), } + // Log that we're resizing + log.Printf("Re-allocating world, old: %+v,%+v new: %+v,%+v\n", a.LowerBound, a.UpperBound, newAtlas.LowerBound, newAtlas.UpperBound) + // Copy all old chunks into the new atlas for chunk, chunkData := range a.Chunks { From 3e1e3a5456d5a3c676aa87130e8bc797474bd40e Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 7 Jul 2020 22:49:34 +0100 Subject: [PATCH 2/4] Amend to TestWorld_RadarFromRover to show the issue --- pkg/game/world_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/game/world_test.go b/pkg/game/world_test.go index 3e5939e..719312a 100644 --- a/pkg/game/world_test.go +++ b/pkg/game/world_test.go @@ -121,6 +121,12 @@ func TestWorld_RadarFromRover(t *testing.T) { // Test the expected values assert.Equal(t, byte(objects.Rover), objs[1+fullRange]) assert.Equal(t, byte(objects.Rover), objs[4+4*fullRange]) + + // Check the radar results are stable + radar1, objs1, err := world.RadarFromRover(a) + radar2, objs2, err := world.RadarFromRover(a) + assert.Equal(t, radar1, radar2) + assert.Equal(t, objs1, objs2) } func TestWorld_RoverStash(t *testing.T) { From 089f5e53374bc25b78d776310da63b7cf79b65d3 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 7 Jul 2020 22:57:55 +0100 Subject: [PATCH 3/4] Fix chunk empty chunk population in QueryPosition --- pkg/atlas/atlas.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/atlas/atlas.go b/pkg/atlas/atlas.go index 2e157b7..1c194af 100644 --- a/pkg/atlas/atlas.go +++ b/pkg/atlas/atlas.go @@ -84,6 +84,7 @@ func (a *Atlas) QueryPosition(v vector.Vector) (byte, objects.Object) { chunk := a.Chunks[c] if chunk.Tiles == nil { chunk.populate(a.ChunkSize) + a.Chunks[c] = chunk } i := a.chunkTileIndex(local) return chunk.Tiles[i], chunk.Objects[i] From 0386617c519441f82fc55c1de9eafd5515999901 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Tue, 7 Jul 2020 23:01:28 +0100 Subject: [PATCH 4/4] Add error checks in TestWorld_RadarFromRover --- pkg/game/world_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/game/world_test.go b/pkg/game/world_test.go index 719312a..0246785 100644 --- a/pkg/game/world_test.go +++ b/pkg/game/world_test.go @@ -124,7 +124,9 @@ func TestWorld_RadarFromRover(t *testing.T) { // Check the radar results are stable radar1, objs1, err := world.RadarFromRover(a) + assert.NoError(t, err) radar2, objs2, err := world.RadarFromRover(a) + assert.NoError(t, err) assert.Equal(t, radar1, radar2) assert.Equal(t, objs1, objs2) }