Added encoding negociation step into protocol.

This is the first step involved in letting go clients talk gob to the game
server.

Still missing: actually use the client's prefered encoding
This commit is contained in:
Stephen McQuay 2014-03-09 23:58:56 -07:00
parent 00373be3da
commit f645c42eb3

View File

@ -200,11 +200,36 @@ func addPlayer(ws *websocket.Conn) {
return return
} }
gameParam := game.gameParam() err = websocket.JSON.Send(ws,
err = websocket.JSON.Send(ws, gameParam) []string{"json", "jsonz", "gob"},
)
if err != nil { if err != nil {
log.Printf("%s %s game param parse error", gid.Id, player_id) log.Printf("%s %s unable to send supported encodings msg", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("game param parse error")) websocket.JSON.Send(ws, NewFailure("encoding send error"))
return
}
var encoding string
err = websocket.JSON.Receive(ws, &encoding)
if err != nil {
log.Printf("%s %s unable to parse encoding", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("encoding recieve error"))
return
}
log.Printf("negociated encoding: %s", encoding)
// TODO: use this negociated encoding
gameParam := game.gameParam()
gp := struct {
GameParam
Encoding string `json:"encoding"`
}{
GameParam: *gameParam,
Encoding: encoding,
}
err = websocket.JSON.Send(ws, gp)
if err != nil {
log.Printf("%s %s game param send error", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("game param send error"))
return return
} else { } else {
log.Printf("%s -> %s: sent %+v", gid.Id, player_id, gameParam) log.Printf("%s -> %s: sent %+v", gid.Id, player_id, gameParam)