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:
parent
00373be3da
commit
f645c42eb3
33
protocol.go
33
protocol.go
@ -200,11 +200,36 @@ func addPlayer(ws *websocket.Conn) {
|
||||
return
|
||||
}
|
||||
|
||||
gameParam := game.gameParam()
|
||||
err = websocket.JSON.Send(ws, gameParam)
|
||||
err = websocket.JSON.Send(ws,
|
||||
[]string{"json", "jsonz", "gob"},
|
||||
)
|
||||
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 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()
|
||||
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
|
||||
} else {
|
||||
log.Printf("%s -> %s: sent %+v", gid.Id, player_id, gameParam)
|
||||
|
Loading…
Reference in New Issue
Block a user