Browse Source

Implemented Fraser's suggestion

Typically client offers supported encodings, then the server chooses the
optimal one.
master
Stephen McQuay 6 years ago
parent
commit
e6c7abc969
1 changed files with 25 additions and 11 deletions
  1. +25
    -11
      protocol.go

+ 25
- 11
protocol.go View File

@ -200,23 +200,37 @@ func addPlayer(ws *websocket.Conn) {
return
}
err = websocket.JSON.Send(ws,
[]string{"json", "jsonz", "gob"},
)
reqEncs := []string{}
err = websocket.JSON.Receive(ws, &reqEncs)
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"))
log.Printf("%s %s unable to parse requested encodings", gid.Id, player_id)
websocket.JSON.Send(ws, NewFailure("encoding recieve error"))
return
}
prefEncs := []string{
"gob",
"json",
}
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"))
encodingLoops:
for _, prefEnc := range prefEncs {
for _, reqEnc := range reqEncs {
if reqEnc == prefEnc {
encoding = prefEnc
log.Println("selected following encoding:", encoding)
break encodingLoops
}
}
}
if encoding == "" {
log.Printf("%s %s unable to negociate encoding", gid.Id, player_id)
websocket.JSON.Send(
ws,
NewFailure("no overlap on supported encodings; I suggest using json"),
)
return
}
log.Printf("negociated encoding: %s", encoding)
// TODO: use this negociated encoding
gameParam := game.gameParam()
gp := struct {

Loading…
Cancel
Save