Merge pull request #19 from mdiluz/clean-proto

De-scope and proto clean
This commit is contained in:
Marc Di Luzio 2020-07-10 09:38:33 +01:00 committed by GitHub
commit 3665a62c6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 994 additions and 2071 deletions

View file

@ -8,7 +8,6 @@ RUN go mod download
# Build the executables
RUN go build -o rove -ldflags="-X 'github.com/mdiluz/rove/pkg/version.Version=$(git describe --always --long --dirty --tags)'" cmd/rove/main.go
RUN go build -o rove-server -ldflags="-X 'github.com/mdiluz/rove/pkg/version.Version=$(git describe --always --long --dirty --tags)'" cmd/rove-server/main.go
RUN go build -o rove-server-rest-proxy cmd/rove-server-rest-proxy/main.go
CMD [ "./rove-server" ]

View file

@ -1,8 +0,0 @@
FROM quay.io/goswagger/swagger:latest
LABEL maintainer="Marc Di Luzio <marc.diluzio@gmail.com>"
WORKDIR /app
COPY . .
CMD [ "serve", "pkg/rove/rove.swagger.json", "--no-open" ]

View file

@ -20,8 +20,6 @@ gen:
@echo Generating rove server gRPC and gateway
protoc --proto_path proto --go_out=plugins=grpc,paths=source_relative:pkg/ proto/rove/rove.proto
protoc --proto_path proto --grpc-gateway_out=paths=source_relative:pkg/ proto/rove/rove.proto
@echo Generating rove server swagger
protoc --proto_path proto --swagger_out=logtostderr=true:pkg/ proto/rove/rove.proto
test:
@echo Unit tests

View file

@ -1,150 +0,0 @@
// +build integration
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"testing"
"github.com/google/uuid"
"github.com/mdiluz/rove/pkg/rove"
"github.com/stretchr/testify/assert"
)
// Server is a simple wrapper to a server path
type Server string
// Request performs a HTTP
func (s Server) Request(method, path string, in, out interface{}) error {
u := url.URL{
Scheme: "http",
Host: fmt.Sprintf("%s:8080", string(s)),
Path: path,
}
client := &http.Client{}
// Marshal the input
marshalled, err := json.Marshal(in)
if err != nil {
return err
}
// Set up the request
req, err := http.NewRequest(method, u.String(), bytes.NewReader(marshalled))
if err != nil {
return err
}
// Do the POST
req.Header.Set("Content-Type", "application/json")
if resp, err := client.Do(req); err != nil {
return err
} else if resp.StatusCode != http.StatusOK {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response body to code %d", resp.StatusCode)
}
return fmt.Errorf("http returned status %d: %s", resp.StatusCode, string(body))
} else {
return json.NewDecoder(resp.Body).Decode(out)
}
}
var serv = Server(os.Getenv("ROVE_HTTP"))
func TestServer_ServerStatus(t *testing.T) {
req := &rove.ServerStatusRequest{}
resp := &rove.ServerStatusResponse{}
if err := serv.Request("GET", "server-status", req, resp); err != nil {
log.Fatal(err)
}
}
func TestServer_Register(t *testing.T) {
req := &rove.RegisterRequest{Name: uuid.New().String()}
resp := &rove.RegisterResponse{}
err := serv.Request("POST", "register", req, resp)
assert.NoError(t, err, "First register attempt should pass")
err = serv.Request("POST", "register", req, resp)
assert.Error(t, err, "Second identical register attempt should fail")
}
func TestServer_Command(t *testing.T) {
acc := uuid.New().String()
var resp rove.RegisterResponse
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &resp)
assert.NoError(t, err, "First register attempt should pass")
req := &rove.CommandRequest{
Account: &rove.Account{
Name: resp.Account.Name,
},
Commands: []*rove.Command{
{
Command: "move",
Bearing: "NE",
},
},
}
assert.Error(t, serv.Request("POST", "command", req, &rove.CommandResponse{}), "Commands should fail with no secret")
req.Account.Secret = resp.Account.Secret
assert.NoError(t, serv.Request("POST", "command", req, &rove.CommandResponse{}), "Commands should pass")
}
func TestServer_Radar(t *testing.T) {
acc := uuid.New().String()
var reg rove.RegisterResponse
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &reg)
assert.NoError(t, err, "First register attempt should pass")
resp := &rove.RadarResponse{}
req := &rove.RadarRequest{
Account: &rove.Account{
Name: reg.Account.Name,
},
}
assert.Error(t, serv.Request("POST", "radar", req, resp), "Radar should fail without secret")
req.Account.Secret = reg.Account.Secret
assert.NoError(t, serv.Request("POST", "radar", req, resp), "Radar should pass")
assert.NotZero(t, resp.Range, "Radar should return valid range")
w := int(resp.Range*2 + 1)
assert.Equal(t, w*w, len(resp.Tiles), "radar should return correct number of tiles")
assert.Equal(t, w*w, len(resp.Objects), "radar should return correct number of objects")
}
func TestServer_Status(t *testing.T) {
acc := uuid.New().String()
var reg rove.RegisterResponse
err := serv.Request("POST", "register", &rove.RegisterRequest{Name: acc}, &reg)
assert.NoError(t, err, "First register attempt should pass")
resp := &rove.StatusResponse{}
req := &rove.StatusRequest{
Account: &rove.Account{
Name: reg.Account.Name,
},
}
assert.Error(t, serv.Request("POST", "status", req, resp), "Status should fail without secret")
req.Account.Secret = reg.Account.Secret
assert.NoError(t, serv.Request("POST", "status", req, resp), "Status should pass")
assert.NotZero(t, resp.Range, "Rover should return valid range")
assert.NotZero(t, len(resp.Name), "Rover should return valid name")
assert.NotZero(t, resp.Position, "Rover should return valid position")
assert.NotZero(t, resp.Integrity, "Rover should have positive integrity")
}

View file

@ -1,51 +0,0 @@
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"strconv"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"google.golang.org/grpc"
"github.com/mdiluz/rove/pkg/rove"
)
func main() {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
defer cancel()
var endpoint = os.Getenv("ROVE_GRPC")
if len(endpoint) == 0 {
endpoint = "localhost:9090"
}
var iport int
var port = os.Getenv("PORT")
if len(port) == 0 {
iport = 8080
} else {
var err error
iport, err = strconv.Atoi(port)
if err != nil {
log.Fatal("$PORT not valid int")
}
}
// Create a new mux and register it with the gRPC endpoint
fmt.Printf("Hosting reverse-proxy on %d for %s\n", iport, endpoint)
mux := runtime.NewServeMux()
opts := []grpc.DialOption{grpc.WithInsecure()}
if err := rove.RegisterRoveHandlerFromEndpoint(ctx, mux, endpoint, opts); err != nil {
log.Fatal(err)
}
// Start the HTTP server and proxy calls to gRPC endpoint when needed
if err := http.ListenAndServe(fmt.Sprintf(":%d", iport), mux); err != nil {
log.Fatal(err)
}
}

View file

@ -79,18 +79,36 @@ func (s *Server) Status(ctx context.Context, req *rove.StatusRequest) (response
i, q := s.world.RoverCommands(resp)
var incoming, queued []*rove.Command
for _, i := range i {
incoming = append(incoming, &rove.Command{
c := &rove.Command{
Command: i.Command,
Bearing: i.Bearing,
Message: i.Message,
})
}
switch i.Command {
case rove.CommandType_move:
c.Data = &rove.Command_Bearing{
Bearing: i.Bearing,
}
case rove.CommandType_broadcast:
c.Data = &rove.Command_Message{
Message: i.Message,
}
}
incoming = append(incoming, c)
}
for _, q := range q {
queued = append(queued, &rove.Command{
c := &rove.Command{
Command: q.Command,
Bearing: q.Bearing,
Message: q.Message,
})
}
switch q.Command {
case rove.CommandType_move:
c.Data = &rove.Command_Bearing{
Bearing: q.Bearing,
}
case rove.CommandType_broadcast:
c.Data = &rove.Command_Message{
Message: q.Message,
}
}
queued = append(queued, c)
}
var logs []*rove.Log
for _, log := range rover.Logs {
@ -171,9 +189,16 @@ func (s *Server) Command(ctx context.Context, req *rove.CommandRequest) (*rove.C
var cmds []game.Command
for _, c := range req.Commands {
cmds = append(cmds, game.Command{
Bearing: c.Bearing,
Command: c.Command})
n := game.Command{
Command: c.Command,
}
switch c.Command {
case rove.CommandType_move:
n.Bearing = c.GetBearing()
case rove.CommandType_broadcast:
n.Message = c.GetMessage()
}
cmds = append(cmds, n)
}
if err := s.world.Enqueue(resp, cmds...); err != nil {

View file

@ -12,7 +12,6 @@ import (
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/bearing"
"github.com/mdiluz/rove/pkg/game"
"github.com/mdiluz/rove/pkg/objects"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/version"
@ -222,8 +221,8 @@ func InnerMain(command string, args ...string) error {
}
commands = append(commands,
&rove.Command{
Command: game.CommandMove,
Bearing: args[i],
Command: rove.CommandType_move,
Data: &rove.Command_Bearing{Bearing: args[i]},
},
)
case "broadcast":
@ -235,15 +234,15 @@ func InnerMain(command string, args ...string) error {
}
commands = append(commands,
&rove.Command{
Command: game.CommandBroadcast,
Message: []byte(args[i]),
Command: rove.CommandType_broadcast,
Data: &rove.Command_Message{Message: []byte(args[i])},
},
)
default:
// By default just use the command literally
commands = append(commands,
&rove.Command{
Command: args[i],
Command: rove.CommandType(rove.CommandType_value[args[i]]),
},
)
}

View file

@ -4,16 +4,6 @@ volumes:
persistent-data:
services:
rove-docs:
build:
context: .
dockerfile: Dockerfile.docs
image: rove-docs:latest
ports:
- "80:80"
environment:
- PORT=80
rove-server:
build:
context: .
@ -30,29 +20,15 @@ services:
- persistent-data:/mnt/rove-server:rw
command: [ "./rove-server"]
rove:
depends_on: [ rove-server, rove-docs ]
build:
context: .
dockerfile: Dockerfile
image: rove:latest
ports:
- "8080:8080"
environment:
- PORT=8080
- ROVE_GRPC=rove-server:9090
command: [ "./script/wait-for-it.sh", "rove-server:9090", "--", "./rove-server-rest-proxy" ]
rove-tests:
depends_on: [ rove ]
depends_on: [ rove-server ]
build:
context: .
dockerfile: Dockerfile
image: rove:latest
environment:
- ROVE_HTTP=rove
- ROVE_GRPC=rove-server
command: [ "./script/wait-for-it.sh", "rove:8080", "--", "go", "test", "-v", "./...", "--tags=integration", "-cover", "-coverprofile=/mnt/coverage-data/c.out", "-count", "1" ]
command: [ "./script/wait-for-it.sh", "rove-server:9090", "--", "go", "test", "-v", "./...", "--tags=integration", "-cover", "-coverprofile=/mnt/coverage-data/c.out", "-count", "1" ]
volumes:
- /tmp/coverage-data:/mnt/coverage-data:rw

View file

@ -1,25 +1,10 @@
package game
const (
// CommandMove Moves the rover in the chosen bearing
CommandMove = "move"
// CommandStash Will attempt to stash the object at the current location
CommandStash = "stash"
// CommandRepair Will attempt to repair the rover with an inventory object
CommandRepair = "repair"
// CommandRecharge Will use one tick to charge the rover
CommandRecharge = "recharge"
// CommandBroadcast will broadcast a message to nearby rovers within range
CommandBroadcast = "broadcast"
)
import "github.com/mdiluz/rove/pkg/rove"
// Command represends a single command to execute
type Command struct {
Command string `json:"command"`
Command rove.CommandType `json:"command"`
// Used in the move command
Bearing string `json:"bearing,omitempty"`

View file

@ -3,6 +3,7 @@ package game
import (
"testing"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/vector"
"github.com/stretchr/testify/assert"
)
@ -20,7 +21,7 @@ func TestCommand_Move(t *testing.T) {
assert.NoError(t, err, "Failed to set position for rover")
// Try the move command
moveCommand := Command{Command: CommandMove, Bearing: "N"}
moveCommand := Command{Command: rove.CommandType_move, Bearing: "N"}
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to execute move command")
// Tick the world
@ -46,7 +47,7 @@ func TestCommand_Recharge(t *testing.T) {
assert.NoError(t, err, "Failed to set position for rover")
// Move to use up some charge
moveCommand := Command{Command: CommandMove, Bearing: "N"}
moveCommand := Command{Command: rove.CommandType_move, Bearing: "N"}
assert.NoError(t, world.Enqueue(a, moveCommand), "Failed to queue move command")
// Tick the world
@ -56,7 +57,7 @@ func TestCommand_Recharge(t *testing.T) {
rover, _ := world.GetRover(a)
assert.Equal(t, rover.MaximumCharge-1, rover.Charge)
chargeCommand := Command{Command: CommandRecharge}
chargeCommand := Command{Command: rove.CommandType_recharge}
assert.NoError(t, world.Enqueue(a, chargeCommand), "Failed to queue recharge command")
// Tick the world

View file

@ -12,6 +12,7 @@ import (
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/bearing"
"github.com/mdiluz/rove/pkg/objects"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/vector"
)
@ -429,11 +430,11 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
// First validate the commands
for _, c := range commands {
switch c.Command {
case CommandMove:
case rove.CommandType_move:
if _, err := bearing.FromString(c.Bearing); err != nil {
return fmt.Errorf("unknown bearing: %s", c.Bearing)
}
case CommandBroadcast:
case rove.CommandType_broadcast:
if len(c.Message) > 3 {
return fmt.Errorf("too many characters in message (limit 3): %d", len(c.Message))
}
@ -442,9 +443,9 @@ func (w *World) Enqueue(rover string, commands ...Command) error {
return fmt.Errorf("invalid message character: %c", b)
}
}
case CommandStash:
case CommandRepair:
case CommandRecharge:
case rove.CommandType_stash:
case rove.CommandType_repair:
case rove.CommandType_recharge:
// Nothing to verify
default:
return fmt.Errorf("unknown command: %s", c.Command)
@ -508,19 +509,19 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
log.Printf("Executing command: %+v for %s\n", *c, rover)
switch c.Command {
case CommandMove:
case rove.CommandType_move:
if dir, err := bearing.FromString(c.Bearing); err != nil {
return err
} else if _, err := w.MoveRover(rover, dir); err != nil {
return err
}
case CommandStash:
case rove.CommandType_stash:
if _, err := w.RoverStash(rover); err != nil {
return err
}
case CommandRepair:
case rove.CommandType_repair:
r, err := w.GetRover(rover)
if err != nil {
return err
@ -532,12 +533,12 @@ func (w *World) ExecuteCommand(c *Command, rover string) (err error) {
r.AddLogEntryf("repaired self to %d", r.Integrity)
w.Rovers[rover] = r
}
case CommandRecharge:
case rove.CommandType_recharge:
_, err := w.RoverRecharge(rover)
if err != nil {
return err
}
case CommandBroadcast:
case rove.CommandType_broadcast:
if err := w.RoverBroadcast(rover, c.Message); err != nil {
return err
}

View file

@ -6,6 +6,7 @@ import (
"github.com/mdiluz/rove/pkg/atlas"
"github.com/mdiluz/rove/pkg/bearing"
"github.com/mdiluz/rove/pkg/objects"
"github.com/mdiluz/rove/pkg/rove"
"github.com/mdiluz/rove/pkg/vector"
"github.com/stretchr/testify/assert"
)
@ -272,7 +273,7 @@ func TestWorld_RoverRepair(t *testing.T) {
assert.NoError(t, err, "couldn't get rover info")
assert.Equal(t, originalInfo.Integrity-1, newinfo.Integrity, "rover should have lost integrity")
err = world.ExecuteCommand(&Command{Command: CommandRepair}, a)
err = world.ExecuteCommand(&Command{Command: rove.CommandType_repair}, a)
assert.NoError(t, err, "Failed to repair rover")
newinfo, err = world.GetRover(a)
@ -286,7 +287,7 @@ func TestWorld_RoverRepair(t *testing.T) {
assert.NoError(t, err, "Failed to stash")
assert.Equal(t, objects.SmallRock, o, "Failed to get correct object")
err = world.ExecuteCommand(&Command{Command: CommandRepair}, a)
err = world.ExecuteCommand(&Command{Command: rove.CommandType_repair}, a)
assert.NoError(t, err, "Failed to repair rover")
newinfo, err = world.GetRover(a)

File diff suppressed because it is too large Load diff

View file

@ -1,459 +0,0 @@
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
// source: rove/rove.proto
/*
Package rove is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
*/
package rove
import (
"context"
"io"
"net/http"
"github.com/golang/protobuf/descriptor"
"github.com/golang/protobuf/proto"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/grpc-ecosystem/grpc-gateway/utilities"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/status"
)
// Suppress "imported and not used" errors
var _ codes.Code
var _ io.Reader
var _ status.Status
var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = descriptor.ForMessage
func request_Rove_ServerStatus_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ServerStatusRequest
var metadata runtime.ServerMetadata
msg, err := client.ServerStatus(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Rove_ServerStatus_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ServerStatusRequest
var metadata runtime.ServerMetadata
msg, err := server.ServerStatus(ctx, &protoReq)
return msg, metadata, err
}
func request_Rove_Register_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq RegisterRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Register(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Rove_Register_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq RegisterRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Register(ctx, &protoReq)
return msg, metadata, err
}
func request_Rove_Command_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CommandRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Command(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Rove_Command_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CommandRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Command(ctx, &protoReq)
return msg, metadata, err
}
func request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq RadarRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Radar(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Rove_Radar_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq RadarRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Radar(ctx, &protoReq)
return msg, metadata, err
}
func request_Rove_Status_0(ctx context.Context, marshaler runtime.Marshaler, client RoveClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq StatusRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Status(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Rove_Status_0(ctx context.Context, marshaler runtime.Marshaler, server RoveServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq StatusRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Status(ctx, &protoReq)
return msg, metadata, err
}
// RegisterRoveHandlerServer registers the http handlers for service Rove to "mux".
// UnaryRPC :call RoveServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
func RegisterRoveHandlerServer(ctx context.Context, mux *runtime.ServeMux, server RoveServer) error {
mux.Handle("GET", pattern_Rove_ServerStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Rove_ServerStatus_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_ServerStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Rove_Register_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Command_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Rove_Command_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Command_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Rove_Radar_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Radar_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Rove_Status_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
// RegisterRoveHandlerFromEndpoint is same as RegisterRoveHandler but
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
func RegisterRoveHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
conn, err := grpc.Dial(endpoint, opts...)
if err != nil {
return err
}
defer func() {
if err != nil {
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
return
}
go func() {
<-ctx.Done()
if cerr := conn.Close(); cerr != nil {
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
}
}()
}()
return RegisterRoveHandler(ctx, mux, conn)
}
// RegisterRoveHandler registers the http handlers for service Rove to "mux".
// The handlers forward requests to the grpc endpoint over "conn".
func RegisterRoveHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
return RegisterRoveHandlerClient(ctx, mux, NewRoveClient(conn))
}
// RegisterRoveHandlerClient registers the http handlers for service Rove
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "RoveClient".
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "RoveClient"
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
// "RoveClient" to call the correct interceptors.
func RegisterRoveHandlerClient(ctx context.Context, mux *runtime.ServeMux, client RoveClient) error {
mux.Handle("GET", pattern_Rove_ServerStatus_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Rove_ServerStatus_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_ServerStatus_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Register_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Rove_Register_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Register_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Command_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Rove_Command_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Command_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Radar_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Rove_Radar_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Radar_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_Rove_Status_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Rove_Status_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Rove_Status_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_Rove_ServerStatus_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"server-status"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Rove_Register_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"register"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Rove_Command_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"command"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Rove_Radar_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"radar"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_Rove_Status_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"status"}, "", runtime.AssumeColonVerbOpt(true)))
)
var (
forward_Rove_ServerStatus_0 = runtime.ForwardResponseMessage
forward_Rove_Register_0 = runtime.ForwardResponseMessage
forward_Rove_Command_0 = runtime.ForwardResponseMessage
forward_Rove_Radar_0 = runtime.ForwardResponseMessage
forward_Rove_Status_0 = runtime.ForwardResponseMessage
)

View file

@ -1,440 +0,0 @@
{
"swagger": "2.0",
"info": {
"title": "Rove",
"description": "Rove is an asychronous nomadic game about exploring a planet as part of a loose community",
"version": "version not set"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/command": {
"post": {
"summary": "Send commands to rover",
"description": "Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent",
"operationId": "Rove_Command",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveCommandResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveCommandRequest"
}
}
],
"tags": [
"Rove"
]
}
},
"/radar": {
"post": {
"summary": "Get radar information",
"description": "Gets the radar output for the given rover",
"operationId": "Rove_Radar",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveRadarResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveRadarRequest"
}
}
],
"tags": [
"Rove"
]
}
},
"/register": {
"post": {
"summary": "Register an account",
"description": "Tries to register an account with the given name",
"operationId": "Rove_Register",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveRegisterResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveRegisterRequest"
}
}
],
"tags": [
"Rove"
]
}
},
"/server-status": {
"get": {
"summary": "Server status",
"description": "Responds with various details about the current server status",
"operationId": "Rove_ServerStatus",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveServerStatusResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"tags": [
"Rove"
]
}
},
"/status": {
"post": {
"summary": "Get rover information",
"description": "Gets information for the account's rover",
"operationId": "Rove_Status",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/roveStatusResponse"
}
},
"default": {
"description": "An unexpected error response",
"schema": {
"$ref": "#/definitions/gatewayruntimeError"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/roveStatusRequest"
}
}
],
"tags": [
"Rove"
]
}
}
},
"definitions": {
"gatewayruntimeError": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"$ref": "#/definitions/protobufAny"
}
}
}
},
"protobufAny": {
"type": "object",
"properties": {
"type_url": {
"type": "string"
},
"value": {
"type": "string",
"format": "byte"
}
}
},
"roveAccount": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"secret": {
"type": "string"
}
}
},
"roveCommand": {
"type": "object",
"properties": {
"command": {
"type": "string",
"title": "The command to execute\n\"move\" - Move the rover in a direction, requires bearing\n\"stash\" - Stashes item at current location in rover inventory\n\"repair\" - Repairs the rover using an inventory object\n\"recharge\" - Waits a tick to add more charge to the rover\n\"broadcast\" - Broadcasts a message to nearby rovers"
},
"bearing": {
"type": "string",
"title": "A bearing, example: NE"
},
"message": {
"type": "string",
"format": "byte",
"title": "A simple message, must be composed of printable ASCII glyphs (32-126)\nmaximum of three characters"
}
}
},
"roveCommandRequest": {
"type": "object",
"properties": {
"account": {
"$ref": "#/definitions/roveAccount",
"title": "The account to execute these commands"
},
"commands": {
"type": "array",
"items": {
"$ref": "#/definitions/roveCommand"
},
"title": "The set of desired commands"
}
}
},
"roveCommandResponse": {
"type": "object",
"title": "Empty placeholder"
},
"roveLog": {
"type": "object",
"properties": {
"time": {
"type": "string",
"title": "The unix timestamp of the log"
},
"text": {
"type": "string",
"title": "The text of the log"
}
}
},
"roveRadarRequest": {
"type": "object",
"properties": {
"account": {
"$ref": "#/definitions/roveAccount",
"title": "The account for this request"
}
}
},
"roveRadarResponse": {
"type": "object",
"properties": {
"range": {
"type": "integer",
"format": "int32",
"title": "The range in tiles from the rover of the radar data"
},
"tiles": {
"type": "string",
"format": "byte",
"title": "A 1D array representing range*2 + 1 squared set of tiles, origin bottom left and in row-\u003ecolumn order"
},
"objects": {
"type": "string",
"format": "byte",
"title": "A similar array to the tile array, but containing objects"
}
}
},
"roveRegisterRequest": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "The desired account name"
}
}
},
"roveRegisterResponse": {
"type": "object",
"properties": {
"account": {
"$ref": "#/definitions/roveAccount",
"title": "The registered account information"
}
},
"title": "Empty placeholder"
},
"roveServerStatusResponse": {
"type": "object",
"properties": {
"version": {
"type": "string",
"title": "The version of the server in v{major}.{minor}-{delta}-{sha} form"
},
"ready": {
"type": "boolean",
"format": "boolean",
"title": "Whether the server is ready to accept requests"
},
"tickRate": {
"type": "integer",
"format": "int32",
"title": "The tick rate of the server in minutes (how many minutes per tick)"
},
"currentTick": {
"type": "integer",
"format": "int32",
"title": "The current tick of the server"
},
"next_tick": {
"type": "string",
"title": "The time the next tick will occur"
}
}
},
"roveStatusRequest": {
"type": "object",
"properties": {
"account": {
"$ref": "#/definitions/roveAccount",
"title": "The account for this request"
}
}
},
"roveStatusResponse": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "The name of the rover"
},
"position": {
"$ref": "#/definitions/roveVector",
"title": "Position of the rover in world coordinates"
},
"range": {
"type": "integer",
"format": "int32",
"title": "The range of this rover's radar and broadcasting"
},
"inventory": {
"type": "string",
"format": "byte",
"title": "The items in the rover inventory"
},
"capacity": {
"type": "integer",
"format": "int32",
"title": "The capacity of the inventory"
},
"integrity": {
"type": "integer",
"format": "int32",
"title": "The current health of the rover"
},
"maximumIntegrity": {
"type": "integer",
"format": "int32",
"title": "The maximum health of the rover"
},
"charge": {
"type": "integer",
"format": "int32",
"title": "The energy stored in the rover"
},
"maximumCharge": {
"type": "integer",
"format": "int32",
"title": "The max energy the rover can store"
},
"incomingCommands": {
"type": "array",
"items": {
"$ref": "#/definitions/roveCommand"
},
"title": "The set of currently incoming commands for this tick"
},
"queuedCommands": {
"type": "array",
"items": {
"$ref": "#/definitions/roveCommand"
},
"title": "The set of currently queued commands"
},
"logs": {
"type": "array",
"items": {
"$ref": "#/definitions/roveLog"
},
"title": "The most recent logs"
}
}
},
"roveVector": {
"type": "object",
"properties": {
"x": {
"type": "integer",
"format": "int32"
},
"y": {
"type": "integer",
"format": "int32"
}
}
}
}
}

View file

@ -2,201 +2,217 @@ syntax = "proto3";
// Rove
//
// Rove is an asychronous nomadic game about exploring a planet as part of a loose community
// Rove is an asychronous nomadic game about exploring a planet as part of a
// loose community
package rove;
option go_package = "github.com/mdiluz/rove/pkg/rove";
import "google/api/annotations.proto";
// The Rove server hosts a single game session and world with multiple players
service Rove {
// Server status
//
// Responds with various details about the current server status
rpc ServerStatus(ServerStatusRequest) returns (ServerStatusResponse) {
option (google.api.http) = {
get: "/server-status"
};
}
// Server status
// Responds with various details about the current server status
rpc ServerStatus(ServerStatusRequest) returns (ServerStatusResponse) {}
// Register an account
//
// Tries to register an account with the given name
rpc Register(RegisterRequest) returns (RegisterResponse) {
option (google.api.http) = {
post: "/register"
body: "*"
};
}
// Register an account
// Tries to register an account with the given name
rpc Register(RegisterRequest) returns (RegisterResponse) {}
// Send commands to rover
//
// Sending commands to this endpoint will queue them to be executed during the following ticks, in the order sent
rpc Command(CommandRequest) returns (CommandResponse) {
option (google.api.http) = {
post: "/command"
body: "*"
};
}
// Send commands to rover
// Sending commands to this endpoint will queue them to be executed during the
// following ticks, in the order sent. Commands sent within the same tick will
// overwrite until the tick has finished and the commands are queued
rpc Command(CommandRequest) returns (CommandResponse) {}
// Get radar information
//
// Gets the radar output for the given rover
rpc Radar(RadarRequest) returns (RadarResponse) {
option (google.api.http) = {
post: "/radar"
body: "*"
};
}
// Get radar information
// Gets the radar output for the given rover
rpc Radar(RadarRequest) returns (RadarResponse) {}
// Get rover information
//
// Gets information for the account's rover
rpc Status(StatusRequest) returns (StatusResponse) {
option (google.api.http) = {
post: "/status"
body: "*"
};
}
// Get rover information
// Gets information for the account's rover
rpc Status(StatusRequest) returns (StatusResponse) {}
}
message Command {
// The command to execute
// "move" - Move the rover in a direction, requires bearing
// "stash" - Stashes item at current location in rover inventory
// "repair" - Repairs the rover using an inventory object
// "recharge" - Waits a tick to add more charge to the rover
// "broadcast" - Broadcasts a message to nearby rovers
string command = 1;
//
// ServerStatus
//
// ServerStatusRequest is an empty placeholder
message ServerStatusRequest {}
// ServerStatusResponse is a response with useful server information
message ServerStatusResponse {
// The version of the server in v{major}.{minor}-{delta}-{sha} form
string version = 1;
// Whether the server is ready to accept requests
bool ready = 2;
// The tick rate of the server in minutes (how many minutes per tick)
int32 tickRate = 3;
// The current tick of the server
int32 currentTick = 4;
// The time the next tick will occur
string next_tick = 5;
}
//
// Register
//
// RegisterRequest contains data to register an account
message RegisterRequest {
// The desired account name
string name = 1;
}
// Account describes a registered account
message Account {
// The account name
string name = 1;
// The account secret value, given when creating the account
string secret = 2;
}
// RegisterResponse is the response given to registering an account
message RegisterResponse {
// The registered account information
Account account = 1;
}
//
// Command
//
// CommandType defines the type of a command to give to the rover
enum CommandType {
none = 0;
// Move the rover in a direction, requires bearing
move = 1;
// Stashes item at current location in rover inventory
stash = 2;
// Repairs the rover using an inventory object
repair = 3;
// Waits a tick to add more charge to the rover
recharge = 4;
// Broadcasts a message to nearby rovers
broadcast = 5;
}
// Command is a single command for a rover
message Command {
// The command type
CommandType command = 1;
oneof data {
// A bearing, example: NE
// Used with MOVE
string bearing = 2;
// A simple message, must be composed of printable ASCII glyphs (32-126)
// maximum of three characters
// Used with BROADCAST
bytes message = 3;
}
}
// CommandRequest describes a set of commands to be requested for the rover
message CommandRequest {
// The account to execute these commands
Account account = 1;
// The account to execute these commands
Account account = 1;
// The set of desired commands
repeated Command commands = 2;
// The set of desired commands
repeated Command commands = 2;
}
// Empty placeholder
// CommandResponse is an empty placeholder
message CommandResponse {}
message Error {
// An explanation for the HTTP error returned
string error = 1;
}
//
// Radar
//
// RadarRequest is the data needed to request the radar for a rover
message RadarRequest {
// The account for this request
Account account = 1;
// The account for this request
Account account = 1;
}
// RadarResponse describes radar information
message RadarResponse {
// The range in tiles from the rover of the radar data
int32 range = 1;
// The range in tiles from the rover of the radar data
int32 range = 1;
// A 1D array representing range*2 + 1 squared set of tiles, origin bottom left and in row->column order
bytes tiles = 2;
// A 1D array representing range*2 + 1 squared set of tiles, origin bottom
// left and in row->column order
bytes tiles = 2;
// A similar array to the tile array, but containing objects
bytes objects = 3;
// A similar array to the tile array, but containing objects
bytes objects = 3;
}
message RegisterRequest {
// The desired account name
string name = 1;
}
// Empty placeholder
message RegisterResponse{
// The registered account information
Account account = 1;
}
//
// Status
//
// StatusRequest is information needed to request rover status
message StatusRequest {
// The account for this request
Account account = 1;
// The account for this request
Account account = 1;
}
// Log is a single log item
message Log {
// The unix timestamp of the log
string time = 1;
// The unix timestamp of the log
string time = 1;
// The text of the log
string text = 2;
}
message StatusResponse {
// The name of the rover
string name = 1;
// Position of the rover in world coordinates
Vector position = 2;
// The range of this rover's radar and broadcasting
int32 range = 3;
// The items in the rover inventory
bytes inventory = 4;
// The capacity of the inventory
int32 capacity = 5;
// The current health of the rover
int32 integrity = 6;
// The maximum health of the rover
int32 maximumIntegrity = 7;
// The energy stored in the rover
int32 charge = 8;
// The max energy the rover can store
int32 maximumCharge = 9;
// The set of currently incoming commands for this tick
repeated Command incomingCommands = 10;
// The set of currently queued commands
repeated Command queuedCommands = 11;
// The most recent logs
repeated Log logs = 12;
}
// Empty placeholder
message ServerStatusRequest {}
message ServerStatusResponse {
// The version of the server in v{major}.{minor}-{delta}-{sha} form
string version = 1;
// Whether the server is ready to accept requests
bool ready = 2;
// The tick rate of the server in minutes (how many minutes per tick)
int32 tickRate = 3;
// The current tick of the server
int32 currentTick = 4;
// The time the next tick will occur
string next_tick = 5;
// The text of the log
string text = 2;
}
// Vector describes a point or vector in 2D space
message Vector {
int32 x = 1;
int32 y = 2;
int32 x = 1;
int32 y = 2;
}
message Account {
string name = 1;
string secret = 2;
// StatusResponse is the response given to a status request
message StatusResponse {
// The name of the rover
string name = 1;
// Position of the rover in world coordinates
Vector position = 2;
// The range of this rover's radar and broadcasting
int32 range = 3;
// The items in the rover inventory
bytes inventory = 4;
// The capacity of the inventory
int32 capacity = 5;
// The current health of the rover
int32 integrity = 6;
// The maximum health of the rover
int32 maximumIntegrity = 7;
// The energy stored in the rover
int32 charge = 8;
// The max energy the rover can store
int32 maximumCharge = 9;
// The set of currently incoming commands for this tick
repeated Command incomingCommands = 10;
// The set of currently queued commands
repeated Command queuedCommands = 11;
// The most recent logs
repeated Log logs = 12;
}

View file

@ -28,14 +28,6 @@ apps:
WORDS_FILE : "$SNAP/data/words_alpha.txt"
DATA_PATH : $SNAP_USER_DATA
rove-rest-server:
command: bin/rove-server-rest-proxy
plugs:
- network
- network-bind
environment:
DATA_PATH : $SNAP_USER_DATA
parts:
go-rove:
plugin: go