From 13c0cd047b22b46b60c54bfd7135d7680f1f0a75 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Thu, 26 Sep 2013 21:51:57 -0700 Subject: [PATCH] use user-provided name in /game/list/ output --- http.go | 18 ++++++++++++------ player.go | 1 - protocol.go | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/http.go b/http.go index 843c056..d231762 100644 --- a/http.go +++ b/http.go @@ -25,7 +25,6 @@ func startGame(w http.ResponseWriter, req *http.Request) { games.Lock() games.m[new_game_name] = _g - log.Printf("%+v", games) games.Unlock() w.Write([]byte(fmt.Sprintf(`{"id": "%s"}`, new_game_name))) @@ -52,16 +51,23 @@ func stopGame(w http.ResponseWriter, req *http.Request) { func listGames(w http.ResponseWriter, req *http.Request) { games.RLock() defer games.RUnlock() + type pout struct { + Name string `json:"name"` + Id string `json:"id"` + } type gl struct { - Id string `json:"id"` - Players []string `json:"players"` + Id string `json:"id"` + Players []pout `json:"players"` } ids := make([]gl, 0) for id, g := range games.m { - players := make([]string, 0) + players := make([]pout, 0) for p, _ := range g.players { // XXX: change this to be the user-provided bot name? - players = append(players, p.Robot.Id) + players = append(players, pout{ + Name: p.Robot.Name, + Id: p.Robot.Id, + }) } ids = append(ids, gl{ Id: id, @@ -104,13 +110,13 @@ func addPlayer(ws *websocket.Conn) { Robot: bot.Robot{ Stats: conf.Stats, Id: id, + Name: conf.Name, Health: conf.Stats.Hp, Scanners: make([]bot.Scanner, 0)}, send: make(chan *bot.Boardstate), ws: ws, } p.reset() - log.Printf("game: %+v", game) game.register <- p defer func() { game.unregister <- p diff --git a/player.go b/player.go index e50a377..e6da4d8 100644 --- a/player.go +++ b/player.go @@ -48,7 +48,6 @@ func (p *player) recv() { if msg.Stats.Speed > 0 { p.Robot.Stats = msg.Stats p.Robot.Health = p.Robot.Stats.Hp - log.Printf("%+v", p.Robot.Stats) } } log.Printf("player %s: recv close", p.Robot.Id) diff --git a/protocol.go b/protocol.go index 350d5a4..20204dc 100644 --- a/protocol.go +++ b/protocol.go @@ -49,6 +49,7 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi _ = websocket.JSON.Send(ws, bot.NewHandshake(id, false)) } } + conf.Name = clientid.Name return &conf, nil case "spectator": return nil, nil