func (r *Runner) handleAddSocket(ctx context.Context, wg *sync.WaitGroup, sm message.Socket, socketOut chan<- message.Message) (*Socket, error) {
	if r.numSockets() >= r.MaxSockets {
		return nil, fmt.Errorf("no room for another socket")
	}
	if len(sm.PlayerName) == 0 {
		return nil, fmt.Errorf("player name required")
	}
	if len(r.playerSockets[sm.PlayerName]) >= r.MaxPlayerSockets {
		return nil, fmt.Errorf("player has reached quota of sockets, close an existing one")
	}
	conn, err := r.upgradeFunc(sm.ResponseWriter, sm.Request)
	if err != nil {
		return nil, fmt.Errorf("upgrading to websocket connection: %w", err)
	}
	s, err := r.SocketConfig.NewSocket(r.log, sm.PlayerName, conn)
	if err != nil {
		return nil, fmt.Errorf("creating socket in runner: %v", err)
	}
	socketIn := make(chan message.Message)
	s.Run(ctx, wg, socketIn, socketOut)
	if r.hasSocket(s.Addr) {
		return nil, fmt.Errorf("socket already exists with address of %v", s.Addr)
	}
	playerSockets, ok := r.playerSockets[sm.PlayerName]
	switch {
	case ok:
		playerSockets[s.Addr] = socketIn
	default:
		r.playerSockets[sm.PlayerName] = map[message.Addr]chan<- message.Message{
			s.Addr: socketIn,
		}
	}
	return s, nil
}
// handleAddSocket runs and adds a socket for the player to the runner.
handleAddSocket runs and adds a socket for the player to the runner.
// handleAddSocket runs and adds a socket for the player to the runner .
func (r *Runner) handleAddSocket(ctx context.Context, wg *sync.WaitGroup, sm message.Socket, socketOut chan<- message.Message) (*Socket, error) {
	if r.numSockets() >= r.MaxSockets {
		return nil, fmt.Errorf("no room for another socket")
	}
	if len(sm.PlayerName) == 0 {
		return nil, fmt.Errorf("player name required")
	}
	if len(r.playerSockets[sm.PlayerName]) >= r.MaxPlayerSockets {
		return nil, fmt.Errorf("player has reached quota of sockets, close an existing one")
	}
	conn, err := r.upgradeFunc(sm.ResponseWriter, sm.Request)
	if err != nil {
		return nil, fmt.Errorf("upgrading to websocket connection: %w", err)
	}
	s, err := r.SocketConfig.NewSocket(r.log, sm.PlayerName, conn)
	if err != nil {
		return nil, fmt.Errorf("creating socket in runner: %v", err)
	}
	socketIn := make(chan message.Message)
	s.Run(ctx, wg, socketIn, socketOut)
	if r.hasSocket(s.Addr) {
		return nil, fmt.Errorf("socket already exists with address of %v", s.Addr)
	}
	playerSockets, ok := r.playerSockets[sm.PlayerName]
	switch {
	case ok:
		playerSockets[s.Addr] = socketIn
	default:
		r.playerSockets[sm.PlayerName] = map[message.Addr]chan<- message.Message{
			s.Addr: socketIn,
		}
	}
	return s, nil
}
func ( r * Runner ) handleAddSocket ( ctx context . Context , wg * sync . WaitGroup , sm message . Socket , socketOut chan <- message . Message ) ( * Socket , error ) { if r . numSockets ( ) >= r . MaxSockets { return nil , fmt . Errorf ( " " ) } if len ( sm . PlayerName ) == 0 { return nil , fmt . Errorf ( " " ) } if len ( r . playerSockets [ sm . PlayerName ] ) >= r . MaxPlayerSockets { return nil , fmt . Errorf ( " " ) } conn , err := r . upgradeFunc ( sm . ResponseWriter , sm . Request ) if err != nil { return nil , fmt . Errorf ( " " , err ) } s , err := r . SocketConfig . NewSocket ( r . log , sm . PlayerName , conn ) if err != nil { return nil , fmt . Errorf ( " " , err ) } socketIn := make ( chan message . Message ) s . Run ( ctx , wg , socketIn , socketOut ) if r . hasSocket ( s . Addr ) { return nil , fmt . Errorf ( " " , s . Addr ) } playerSockets , ok := r . playerSockets [ sm . PlayerName ] switch { case ok : playerSockets [ s . Addr ] = socketIn default : r . playerSockets [ sm . PlayerName ] = map [ message . Addr ] chan <- message . Message { s . Addr : socketIn , } } return s , nil }
handleAddSocket runs and adds a socket for the player to the runner.
handleAddSocket runs and adds a socket for the player to the runner .