diff --git a/protocol.go b/protocol.go index 4e76d92..959b4df 100644 --- a/protocol.go +++ b/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)