Browse Source

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
master
Stephen McQuay 6 years ago
parent
commit
f645c42eb3
1 changed files with 28 additions and 3 deletions
  1. +28
    -3
      protocol.go

+ 28
- 3
protocol.go View File

@ -200,11 +200,36 @@ func addPlayer(ws *websocket.Conn) {
return
}
err = websocket.JSON.Send(ws,
[]string{"json", "jsonz", "gob"},
)
if err != nil {
log.Printf("%s %s unable to send supported encodings msg", gid.Id, player_id)
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()
err = websocket.JSON.Send(ws, 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 parse error", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("game param parse error"))
log.Printf("%s %s game param send error", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("game param send error"))
return
} else {
log.Printf("%s -> %s: sent %+v", gid.Id, player_id, gameParam)

Loading…
Cancel
Save