Sorted out extra load
turns out we were never exiting the loop even when all bots left. Games now shut down when there ever has been bots and they all leave (or are killed, I think).
This commit is contained in:
+3
-15
@@ -6,24 +6,12 @@ import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Failure struct {
|
||||
Reason string `json:"reason"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
func NewFailure(reason string) *Failure {
|
||||
return &Failure{
|
||||
Reason: reason,
|
||||
Type: "failure",
|
||||
}
|
||||
}
|
||||
|
||||
func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Config, error) {
|
||||
var err error
|
||||
|
||||
err = websocket.JSON.Send(ws, bot.NewIdRequest(id))
|
||||
if err != nil {
|
||||
return nil, errors.New("generic servr error")
|
||||
return nil, errors.New("generic server error")
|
||||
}
|
||||
|
||||
var clientid bot.ClientID
|
||||
@@ -34,7 +22,7 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi
|
||||
if v, msg := clientid.Valid(); !v {
|
||||
websocket.JSON.Send(
|
||||
ws,
|
||||
NewFailure(msg),
|
||||
bot.NewFailure(msg),
|
||||
)
|
||||
return nil, errors.New(msg)
|
||||
}
|
||||
@@ -42,7 +30,7 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*bot.Confi
|
||||
gameParam := bot.NewGameParam(width, height)
|
||||
err = websocket.JSON.Send(ws, gameParam)
|
||||
if err != nil {
|
||||
websocket.JSON.Send(ws, NewFailure("generic server error"))
|
||||
websocket.JSON.Send(ws, bot.NewFailure("generic server error"))
|
||||
return nil, err
|
||||
}
|
||||
switch clientid.Type {
|
||||
|
||||
Reference in New Issue
Block a user