send the client calculated values for stats
This commit is contained in:
+15
-5
@@ -214,12 +214,12 @@ func addPlayer(ws *websocket.Conn) {
|
||||
|
||||
// TODO: verify conf's type
|
||||
if conf.Valid(game.maxPoints) {
|
||||
log.Printf("Config is Valid, continuing")
|
||||
_ = websocket.JSON.Send(ws, NewHandshake(player_id, true))
|
||||
break
|
||||
} else {
|
||||
log.Printf("Config is INVALID, abort")
|
||||
_ = websocket.JSON.Send(ws, NewHandshake(player_id, false))
|
||||
log.Printf("%s: Config is INVALID, abort", player_id)
|
||||
_ = websocket.JSON.Send(ws, NewFailure("invalid config"))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +227,15 @@ func addPlayer(ws *websocket.Conn) {
|
||||
Robots: []*Robot{},
|
||||
send: make(chan Message),
|
||||
ws: ws,
|
||||
Id: idg.Hash(),
|
||||
Id: player_id,
|
||||
}
|
||||
|
||||
convertedStats := map[string]Stats{}
|
||||
for name, stats := range conf.Stats {
|
||||
dstat := DeriveStats(stats)
|
||||
convertedStats[name] = dstat
|
||||
r := Robot{
|
||||
Stats: DeriveStats(stats),
|
||||
Stats: dstat,
|
||||
Id: idg.Hash(),
|
||||
Name: name,
|
||||
Health: 10,
|
||||
@@ -244,6 +247,13 @@ func addPlayer(ws *websocket.Conn) {
|
||||
p.Robots = append(p.Robots, &r)
|
||||
}
|
||||
|
||||
err = websocket.JSON.Send(ws, &convertedStats)
|
||||
if err != nil {
|
||||
log.Printf("error sending convertedStats to client: %s", err)
|
||||
websocket.JSON.Send(ws, NewFailure("protocol error: convertedStats"))
|
||||
return
|
||||
}
|
||||
|
||||
game.register <- p
|
||||
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user