send back more information on /game/list/

This commit is contained in:
Stephen McQuay 2013-09-05 23:31:24 -07:00
parent 45cc67a5f1
commit f9b646e50c

18
http.go
View File

@ -33,9 +33,21 @@ func startGame(w http.ResponseWriter, req *http.Request) {
func listGames(w http.ResponseWriter, req *http.Request) {
games.RLock()
defer games.RUnlock()
ids := make([]string, 0)
for id, _ := range games.m {
ids = append(ids, id)
type gl struct {
Id string `json:"id"`
Players []string `json:"players"`
}
ids := make([]gl, 0)
for id, g := range games.m {
players := make([]string, 0)
for p, _ := range g.players {
// XXX: change this to be the user-provided bot name?
players = append(players, p.Robot.Id)
}
ids = append(ids, gl{
Id: id,
Players: players,
})
}
if err := json.NewEncoder(w).Encode(ids); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)