use user-provided name in /game/list/ output

This commit is contained in:
Stephen McQuay 2013-09-26 21:51:57 -07:00
parent f8378cf89b
commit 13c0cd047b
3 changed files with 13 additions and 7 deletions

16
http.go
View File

@ -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"`
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

View File

@ -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)

View File

@ -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