// Accept waits for and returns a connecting Peer
// You should keep calling this until it returns ErrClosed
// so it doesn't leak a goroutine
Accept waits for and returns a connecting Peer
You should keep calling this until it returns ErrClosed
so it doesn't leak a goroutine
// Accept waits for and returns a connecting Peer // You should keep calling this until it returns ErrClosed // so it doesn ' t leak a goroutine
func (l *Listener) Accept() (*Peer, error) {
	rp, err := l.Listener.Accept()
	if err != nil {
		return nil, err
	}
	clt := &Peer{Peer: rp}
	l.mu.Lock()
	l.peers[clt] = struct{}{}
	l.mu.Unlock()
	go func() {
		<-clt.Disco()
		l.mu.Lock()
		delete(l.peers, clt)
		l.mu.Unlock()
	}()
	clt.aoIDs = make(map[uint16]bool)
	clt.modChs = make(map[string]bool)
	maxPeers, ok := GetConfKey("player_limit").(int)
	if !ok {
		maxPeers = int(^uint(0) >> 1)
	}
	if GetPeerCount() >= maxPeers {
		data := []byte{
			0, ToClientAccessDenied,
			AccessDeniedTooManyUsers, 0, 0, 0, 0,
		}
		_, err := clt.Send(rudp.Pkt{Data: data})
		if err != nil {
			return nil, err
		}
		return nil, ErrPlayerLimitReached
	}
	connectedPeers++
	return clt, nil
}
func ( l * Listener ) Accept ( ) ( * Peer , error ) { rp , err := l . Listener . Accept ( ) if err != nil { return nil , err } clt := & Peer { Peer : rp } l . mu . Lock ( ) l . peers [ clt ] = struct { } { } l . mu . Unlock ( ) go func ( ) { <- clt . Disco ( ) l . mu . Lock ( ) delete ( l . peers , clt ) l . mu . Unlock ( ) } ( ) clt . aoIDs = make ( map [ uint16 ] bool ) clt . modChs = make ( map [ string ] bool ) maxPeers , ok := GetConfKey ( " " ) . ( int ) if ! ok { maxPeers = int ( ^ uint ( 0 ) >> 1 ) } if GetPeerCount ( ) >= maxPeers { data := [ ] byte { 0 , ToClientAccessDenied , AccessDeniedTooManyUsers , 0 , 0 , 0 , 0 , } _ , err := clt . Send ( rudp . Pkt { Data : data } ) if err != nil { return nil , err } return nil , ErrPlayerLimitReached } connectedPeers ++ return clt , nil }
Accept waits for and returns a connecting Peer
You should keep calling this until it returns ErrClosed
so it doesn't leak a goroutine
Accept waits for and returns a connecting Peer You should keep calling this until it returns ErrClosed so it doesn ' t leak a goroutine