|
|
@ -172,6 +172,8 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
log.Printf("game %s: unable to send player_id to player %s", gid.Id, player_id) |
|
|
|
websocket.JSON.Send(ws, NewFailure("send error")) |
|
|
|
return |
|
|
|
} else { |
|
|
|
log.Printf("game %s: sent player id: %s", gid.Id, player_id) |
|
|
|
} |
|
|
|
|
|
|
|
var clientid ClientID |
|
|
@ -180,6 +182,8 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
log.Printf("unable to parse ClientID: gid: %s, player: %s", gid.Id, player_id) |
|
|
|
websocket.JSON.Send(ws, NewFailure("parse error")) |
|
|
|
return |
|
|
|
} else { |
|
|
|
log.Printf("game %s: recieved: %+v", gid.Id, clientid) |
|
|
|
} |
|
|
|
if v, msg := clientid.Valid(); !v { |
|
|
|
log.Printf("clientid is invalid: %+v", clientid) |
|
|
@ -196,6 +200,8 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
log.Printf("%s %s game param parse error", gid.Id, player_id) |
|
|
|
websocket.JSON.Send(ws, NewFailure("game param parse error")) |
|
|
|
return |
|
|
|
} else { |
|
|
|
log.Printf("%s -> %s: sent %+v", gid.Id, player_id, gameParam) |
|
|
|
} |
|
|
|
|
|
|
|
switch clientid.Type { |
|
|
@ -204,7 +210,7 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
for { |
|
|
|
log.Printf("%s Waiting for client to send conf ...", player_id) |
|
|
|
err = websocket.JSON.Receive(ws, &conf) |
|
|
|
log.Printf("%s: conf received: %+v", player_id, conf) |
|
|
|
log.Printf("%s: conf received: %s", player_id, conf.ID) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Printf("%s %s config parse error", gid.Id, player_id) |
|
|
@ -214,6 +220,7 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
|
|
|
|
// TODO: verify conf's type
|
|
|
|
if conf.Valid(game.maxPoints) { |
|
|
|
log.Printf("%s -> %s: valid client config", gid.Id, player_id) |
|
|
|
_ = websocket.JSON.Send(ws, NewHandshake(player_id, true)) |
|
|
|
break |
|
|
|
} else { |
|
|
@ -225,10 +232,11 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
|
|
|
|
p := &player{ |
|
|
|
Robots: []*Robot{}, |
|
|
|
send: make(chan Message), |
|
|
|
send: make(chan Message, 16), |
|
|
|
ws: ws, |
|
|
|
Id: player_id, |
|
|
|
} |
|
|
|
log.Printf("%s: made a player: %s", gid.Id, p.Id) |
|
|
|
|
|
|
|
convertedStats := map[string]Stats{} |
|
|
|
for name, stats := range conf.Stats { |
|
|
@ -259,14 +267,21 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
log.Printf("error sending convertedStats to client: %s", err) |
|
|
|
websocket.JSON.Send(ws, NewFailure("protocol error: convertedStats")) |
|
|
|
return |
|
|
|
} else { |
|
|
|
log.Printf("%s -> %s: sent stats payload", gid.Id, p.Id) |
|
|
|
} |
|
|
|
|
|
|
|
log.Printf("%s, %s: about to register this player", gid.Id, p.Id) |
|
|
|
game.register <- p |
|
|
|
log.Printf("%s, %s: registered player", gid.Id, p.Id) |
|
|
|
|
|
|
|
defer func() { |
|
|
|
log.Printf("%s, %s: about to unregister this player", gid.Id, p.Id) |
|
|
|
game.unregister <- p |
|
|
|
log.Printf("%s, %s: unregistered player", gid.Id, p.Id) |
|
|
|
}() |
|
|
|
go p.sender() |
|
|
|
log.Printf("%s -> %s: p.sender went", gid.Id, p.Id) |
|
|
|
p.recv() |
|
|
|
log.Printf( |
|
|
|
"%s (player): %v (robot) has been disconnected from %s (game)", |
|
|
@ -276,14 +291,21 @@ func addPlayer(ws *websocket.Conn) { |
|
|
|
) |
|
|
|
case "spectator": |
|
|
|
s := &Spectator{ |
|
|
|
send: make(chan Message), |
|
|
|
send: make(chan Message, 16), |
|
|
|
ws: ws, |
|
|
|
Id: player_id, |
|
|
|
} |
|
|
|
log.Printf("%s, %s: about to register this spectator", gid.Id, s.Id) |
|
|
|
game.sregister <- s |
|
|
|
log.Printf("%s, %s: registered spectator", gid.Id, s.Id) |
|
|
|
defer func() { |
|
|
|
log.Printf("%s, %s: about to unregister this spectator", gid.Id, s.Id) |
|
|
|
game.sunregister <- s |
|
|
|
log.Printf("%s, %s: unregistered spectator", gid.Id, s.Id) |
|
|
|
}() |
|
|
|
s.sender() |
|
|
|
log.Printf("game %s: spectator %+v has been disconnected from this game\n", s) |
|
|
|
go s.sender() |
|
|
|
log.Printf("%s -> %s: s.sender went", gid.Id, s.Id) |
|
|
|
s.recv() |
|
|
|
log.Printf("game %s: spectator %+v has been disconnected from this game", gid.Id, s) |
|
|
|
} |
|
|
|
} |