added simple, non-leaking game stop url

This commit is contained in:
sm
2013-09-08 09:32:24 -07:00
parent b7087adb78
commit f175e45c63
4 changed files with 33 additions and 4 deletions
+7 -2
View File
@@ -7,6 +7,8 @@ import (
"time"
)
const maxPlayer = 128
type game struct {
id string
players map[*player]bool
@@ -26,7 +28,7 @@ func NewGame(id string, width, height float64) *game {
g := &game{
id: id,
register: make(chan *player),
unregister: make(chan *player),
unregister: make(chan *player, maxPlayer),
projectiles: make(map[*bot.Projectile]bool),
splosions: make(map[*bot.Splosion]bool),
players: make(map[*player]bool),
@@ -36,7 +38,7 @@ func NewGame(id string, width, height float64) *game {
spectators: make(map[*Spectator]bool),
sregister: make(chan *Spectator),
sunregister: make(chan *Spectator),
kill: make(chan bool, 128),
kill: make(chan bool, maxPlayer),
}
return g
}
@@ -50,6 +52,9 @@ func (g *game) run() {
case <-g.kill:
log.Printf("game %s: received kill signal, dying gracefully", g.id)
games.Lock()
for player := range g.players {
close(player.send)
}
delete(games.m, g.id)
games.Unlock()
return