func (r *Runner) createGame(ctx context.Context, wg *sync.WaitGroup, m message.Message, out chan<- message.Message) {
	if err := r.validateCreateGame(m); err != nil {
		r.sendError(err, m.PlayerName, out)
		return
	}
	id := r.lastID + 1
	gameCfg := r.GameConfig
	gameCfg.Config = *m.Game.Config
	g, err := gameCfg.NewGame(r.log, id, r.WordValidator, r.userDao)
	if err != nil {
		r.sendError(err, m.PlayerName, out)
		return
	}
	r.lastID = id
	gIn := make(chan message.Message)
	g.Run(ctx, wg, gIn, out) // all games publish to the same "out" channel
	r.games[id] = gIn
	m.Type = message.JoinGame
	message.Send(m, gIn, r.Debug, r.log)
}
// createGame allocates a new game, adding it to the open games.
createGame allocates a new game, adding it to the open games.
// createGame allocates a new game adding it to the open games .
func (r *Runner) createGame(ctx context.Context, wg *sync.WaitGroup, m message.Message, out chan<- message.Message) {
	if err := r.validateCreateGame(m); err != nil {
		r.sendError(err, m.PlayerName, out)
		return
	}
	id := r.lastID + 1
	gameCfg := r.GameConfig
	gameCfg.Config = *m.Game.Config
	g, err := gameCfg.NewGame(r.log, id, r.WordValidator, r.userDao)
	if err != nil {
		r.sendError(err, m.PlayerName, out)
		return
	}
	r.lastID = id
	gIn := make(chan message.Message)
	g.Run(ctx, wg, gIn, out) 
	r.games[id] = gIn
	m.Type = message.JoinGame
	message.Send(m, gIn, r.Debug, r.log)
}
func ( r * Runner ) createGame ( ctx context . Context , wg * sync . WaitGroup , m message . Message , out chan <- message . Message ) { if err := r . validateCreateGame ( m ) ; err != nil { r . sendError ( err , m . PlayerName , out ) return } id := r . lastID + 1 gameCfg := r . GameConfig gameCfg . Config = * m . Game . Config g , err := gameCfg . NewGame ( r . log , id , r . WordValidator , r . userDao ) if err != nil { r . sendError ( err , m . PlayerName , out ) return } r . lastID = id gIn := make ( chan message . Message ) g . Run ( ctx , wg , gIn , out ) r . games [ id ] = gIn m . Type = message . JoinGame message . Send ( m , gIn , r . Debug , r . log ) }
createGame allocates a new game, adding it to the open games.
createGame allocates a new game adding it to the open games .
// all games publish to the same "out" channel