func (g *Game) handleGameJoin(ctx context.Context, m message.Message, send messageSender) error {
	_, ok := g.players[m.PlayerName]
	var err error
	switch {
	case ok:
		err = g.handleBoardRefresh(ctx, m, send)
	case g.status != game.NotStarted:
		err = gameWarning("cannot join game that has been started")
	case len(g.players) >= g.MaxPlayers:
		err = gameWarning("no room for another player in game")
	case len(g.unusedTiles) < g.NumNewTiles:
		err = gameWarning("not enough tiles to join the game")
	default:
		err = g.handleAddPlayer(ctx, m, send)
	}
	if err != nil {
		// kick the player here, returning an error will not remove them from the game
		m2 := message.Message{
			Type:       message.LeaveGame,
			PlayerName: m.PlayerName,
			Info:       err.Error(),
			Addr:       m.Addr,
		}
		send(m2)
		return err
	}
	return nil
}
// handleGameJoin adds the player from the message to the game.
handleGameJoin adds the player from the message to the game.
// handleGameJoin adds the player from the message to the game .
func (g *Game) handleGameJoin(ctx context.Context, m message.Message, send messageSender) error {
	_, ok := g.players[m.PlayerName]
	var err error
	switch {
	case ok:
		err = g.handleBoardRefresh(ctx, m, send)
	case g.status != game.NotStarted:
		err = gameWarning("cannot join game that has been started")
	case len(g.players) >= g.MaxPlayers:
		err = gameWarning("no room for another player in game")
	case len(g.unusedTiles) < g.NumNewTiles:
		err = gameWarning("not enough tiles to join the game")
	default:
		err = g.handleAddPlayer(ctx, m, send)
	}
	if err != nil {
		m2 := message.Message{
			Type:       message.LeaveGame,
			PlayerName: m.PlayerName,
			Info:       err.Error(),
			Addr:       m.Addr,
		}
		send(m2)
		return err
	}
	return nil
}
func ( g * Game ) handleGameJoin ( ctx context . Context , m message . Message , send messageSender ) error { _ , ok := g . players [ m . PlayerName ] var err error switch { case ok : err = g . handleBoardRefresh ( ctx , m , send ) case g . status != game . NotStarted : err = gameWarning ( " " ) case len ( g . players ) >= g . MaxPlayers : err = gameWarning ( " " ) case len ( g . unusedTiles ) < g . NumNewTiles : err = gameWarning ( " " ) default : err = g . handleAddPlayer ( ctx , m , send ) } if err != nil { m2 := message . Message { Type : message . LeaveGame , PlayerName : m . PlayerName , Info : err . Error ( ) , Addr : m . Addr , } send ( m2 ) return err } return nil }
handleGameJoin adds the player from the message to the game.
handleGameJoin adds the player from the message to the game .
// kick the player here, returning an error will not remove them from the game