Added encoding negociation to protocol
This commit is contained in:
parent
ed39916f17
commit
21705cc16e
@ -1,8 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bitbucket.org/hackerbots/vector"
|
||||
"fmt"
|
||||
|
||||
"bitbucket.org/hackerbots/vector"
|
||||
)
|
||||
|
||||
type ClientConfig struct {
|
||||
@ -22,6 +23,7 @@ type GameParam struct {
|
||||
MaxPoints int `json:"max_points"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
Encoding string `json:"encoding"`
|
||||
}
|
||||
|
||||
type StatsRequest struct {
|
||||
|
23
robot.go
23
robot.go
@ -1,14 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bitbucket.org/hackerbots/vector"
|
||||
"code.google.com/p/go.net/websocket"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
"bitbucket.org/hackerbots/vector"
|
||||
"code.google.com/p/go.net/websocket"
|
||||
)
|
||||
|
||||
const maxSpeed = 100
|
||||
@ -86,6 +87,22 @@ func (r *robot) negociate() (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
encodings := []string{}
|
||||
err = websocket.JSON.Receive(r.ws, &encodings)
|
||||
log.Printf("%+v", encodings)
|
||||
desiredEncoding := "json"
|
||||
for _, encoding := range encodings {
|
||||
if "gob" == encoding {
|
||||
desiredEncoding = encoding
|
||||
break
|
||||
}
|
||||
}
|
||||
err = websocket.JSON.Send(r.ws, desiredEncoding)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = websocket.JSON.Receive(r.ws, &r.game)
|
||||
if r.game.Type != "gameparam" {
|
||||
return errors.New("didn't receive a good gameparam")
|
||||
@ -93,6 +110,8 @@ func (r *robot) negociate() (err error) {
|
||||
if *verbose {
|
||||
log.Printf("%s: game parameters: %+v", r.name, r.game)
|
||||
}
|
||||
// TODO: do something with r.game.Protocol
|
||||
log.Printf("game params: %+v", r.game)
|
||||
|
||||
conf := ClientConfig{
|
||||
ID: r.game.Name,
|
||||
|
Loading…
Reference in New Issue
Block a user