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) { func listGames(w http.ResponseWriter, req *http.Request) {
games.RLock() games.RLock()
defer games.RUnlock() defer games.RUnlock()
ids := make([]string, 0) type gl struct {
for id, _ := range games.m { Id string `json:"id"`
ids = append(ids, 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 { if err := json.NewEncoder(w).Encode(ids); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)