logging and infinite melee

This commit is contained in:
Stephen McQuay 2013-09-27 00:03:32 -07:00
parent 13c0cd047b
commit 472e2011b9
3 changed files with 9 additions and 7 deletions

View File

@ -45,7 +45,6 @@ func NewGame(id string, width, height float64) *game {
} }
func (g *game) run() { func (g *game) run() {
started := false
var t0, t1 time.Time var t0, t1 time.Time
payload := bot.NewBoardstate() payload := bot.NewBoardstate()
for { for {
@ -61,7 +60,6 @@ func (g *game) run() {
return return
case p := <-g.register: case p := <-g.register:
g.players[p] = true g.players[p] = true
started = true
case p := <-g.unregister: case p := <-g.unregister:
delete(g.players, p) delete(g.players, p)
close(p.send) close(p.send)
@ -74,9 +72,6 @@ func (g *game) run() {
// XXX: This is very racy!! It was at bottom of loop and empty // XXX: This is very racy!! It was at bottom of loop and empty
// stuff was going out // stuff was going out
payload.EmptySlices() payload.EmptySlices()
if started && len(g.players) == 0 {
g.kill <- true
}
g.turn++ g.turn++
payload.Turn = g.turn payload.Turn = g.turn

View File

@ -123,7 +123,7 @@ func addPlayer(ws *websocket.Conn) {
}() }()
go p.sender() go p.sender()
p.recv() p.recv()
log.Printf("game %s: %v has been disconnect from this game\n", gid, p.Robot.Id) log.Printf("game %s: player %v has been disconnected from this game\n", gid.Id, p.Robot.Id)
} else { } else {
s := &Spectator{ s := &Spectator{
send: make(chan *bot.Boardstate), send: make(chan *bot.Boardstate),
@ -134,6 +134,6 @@ func addPlayer(ws *websocket.Conn) {
game.sunregister <- s game.sunregister <- s
}() }()
s.sender() s.sender()
log.Printf("%+v has been disconnect from this game\n", s) log.Printf("game %s: spectator %+v has been disconnected from this game\n", s)
} }
} }

View File

@ -4,6 +4,7 @@ import (
"bitbucket.org/hackerbots/bot" "bitbucket.org/hackerbots/bot"
"code.google.com/p/go.net/websocket" "code.google.com/p/go.net/websocket"
"errors" "errors"
"log"
) )
func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Config, error) { func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Config, error) {
@ -20,12 +21,14 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi
return nil, errors.New("could not parse id") return nil, errors.New("could not parse id")
} }
if v, msg := clientid.Valid(); !v { if v, msg := clientid.Valid(); !v {
log.Printf("clientid is invalid: %+v", clientid)
websocket.JSON.Send( websocket.JSON.Send(
ws, ws,
bot.NewFailure(msg), bot.NewFailure(msg),
) )
return nil, errors.New(msg) return nil, errors.New(msg)
} }
log.Printf("clientid: %+v", clientid)
gameParam := bot.NewGameParam(width, height) gameParam := bot.NewGameParam(width, height)
err = websocket.JSON.Send(ws, gameParam) err = websocket.JSON.Send(ws, gameParam)
@ -33,11 +36,15 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi
websocket.JSON.Send(ws, bot.NewFailure("generic server error")) websocket.JSON.Send(ws, bot.NewFailure("generic server error"))
return nil, err return nil, err
} }
log.Printf("gameparam: %+v", gameParam)
switch clientid.Type { switch clientid.Type {
case "robot": case "robot":
var conf bot.Config var conf bot.Config
log.Printf("got here?")
for { for {
log.Printf("%s Waiting for client to send conf ...", id)
err = websocket.JSON.Receive(ws, &conf) err = websocket.JSON.Receive(ws, &conf)
log.Printf("conf received: %+v", conf)
if err != nil { if err != nil {
return nil, err return nil, err
} }