use user-provided name in /game/list/ output
This commit is contained in:
parent
f8378cf89b
commit
13c0cd047b
18
http.go
18
http.go
@ -25,7 +25,6 @@ func startGame(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
games.Lock()
|
games.Lock()
|
||||||
games.m[new_game_name] = _g
|
games.m[new_game_name] = _g
|
||||||
log.Printf("%+v", games)
|
|
||||||
games.Unlock()
|
games.Unlock()
|
||||||
|
|
||||||
w.Write([]byte(fmt.Sprintf(`{"id": "%s"}`, new_game_name)))
|
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) {
|
func listGames(w http.ResponseWriter, req *http.Request) {
|
||||||
games.RLock()
|
games.RLock()
|
||||||
defer games.RUnlock()
|
defer games.RUnlock()
|
||||||
|
type pout struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
}
|
||||||
type gl struct {
|
type gl struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Players []string `json:"players"`
|
Players []pout `json:"players"`
|
||||||
}
|
}
|
||||||
ids := make([]gl, 0)
|
ids := make([]gl, 0)
|
||||||
for id, g := range games.m {
|
for id, g := range games.m {
|
||||||
players := make([]string, 0)
|
players := make([]pout, 0)
|
||||||
for p, _ := range g.players {
|
for p, _ := range g.players {
|
||||||
// XXX: change this to be the user-provided bot name?
|
// 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{
|
ids = append(ids, gl{
|
||||||
Id: id,
|
Id: id,
|
||||||
@ -104,13 +110,13 @@ func addPlayer(ws *websocket.Conn) {
|
|||||||
Robot: bot.Robot{
|
Robot: bot.Robot{
|
||||||
Stats: conf.Stats,
|
Stats: conf.Stats,
|
||||||
Id: id,
|
Id: id,
|
||||||
|
Name: conf.Name,
|
||||||
Health: conf.Stats.Hp,
|
Health: conf.Stats.Hp,
|
||||||
Scanners: make([]bot.Scanner, 0)},
|
Scanners: make([]bot.Scanner, 0)},
|
||||||
send: make(chan *bot.Boardstate),
|
send: make(chan *bot.Boardstate),
|
||||||
ws: ws,
|
ws: ws,
|
||||||
}
|
}
|
||||||
p.reset()
|
p.reset()
|
||||||
log.Printf("game: %+v", game)
|
|
||||||
game.register <- p
|
game.register <- p
|
||||||
defer func() {
|
defer func() {
|
||||||
game.unregister <- p
|
game.unregister <- p
|
||||||
|
@ -48,7 +48,6 @@ func (p *player) recv() {
|
|||||||
if msg.Stats.Speed > 0 {
|
if msg.Stats.Speed > 0 {
|
||||||
p.Robot.Stats = msg.Stats
|
p.Robot.Stats = msg.Stats
|
||||||
p.Robot.Health = p.Robot.Stats.Hp
|
p.Robot.Health = p.Robot.Stats.Hp
|
||||||
log.Printf("%+v", p.Robot.Stats)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Printf("player %s: recv close", p.Robot.Id)
|
log.Printf("player %s: recv close", p.Robot.Id)
|
||||||
|
@ -49,6 +49,7 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi
|
|||||||
_ = websocket.JSON.Send(ws, bot.NewHandshake(id, false))
|
_ = websocket.JSON.Send(ws, bot.NewHandshake(id, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
conf.Name = clientid.Name
|
||||||
return &conf, nil
|
return &conf, nil
|
||||||
case "spectator":
|
case "spectator":
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user