From d3070ad501ec311e1e04d7daca99b5e7677b2f1e Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Wed, 22 Jan 2014 22:14:22 -0800 Subject: [PATCH] send the client max points for the game --- game.go | 13 +++++++++++++ protocol.go | 13 +++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/game.go b/game.go index cfaf4c4..97e95a6 100644 --- a/game.go +++ b/game.go @@ -357,3 +357,16 @@ func (g *game) sendGameOver(eg *GameOver) { s.send <- eg } } + +// returns a GameParam object popuplated by info from the game. This is +// used during client/server initial negociation. +func (g *game) gameParam() *GameParam { + return &GameParam{ + BoardSize: BoardSize{ + Width: g.width, + Height: g.height, + }, + MaxPoints: g.maxPoints, + Type: "gameparam", + } +} diff --git a/protocol.go b/protocol.go index 0b46b73..d6bea26 100644 --- a/protocol.go +++ b/protocol.go @@ -71,20 +71,13 @@ type BoardSize struct { } type GameParam struct { + // TODO: should have information about max points in here BoardSize BoardSize `json:"boardsize"` + MaxPoints int `json:"max_points"` Type string `json:"type"` } // > [OK | FULL | NOT AUTH], board size, game params -func NewGameParam(w, h float32) *GameParam { - return &GameParam{ - BoardSize: BoardSize{ - Width: w, - Height: h, - }, - Type: "gameparam", - } -} type Handshake struct { ID string `json:"id"` @@ -197,7 +190,7 @@ func addPlayer(ws *websocket.Conn) { return } - gameParam := NewGameParam(game.width, game.height) + gameParam := game.gameParam() err = websocket.JSON.Send(ws, gameParam) if err != nil { log.Printf("%s %s game param parse error", gid.Id, player_id)