<commit_before>// Copyright (c) 2016-2017 <NAME> <<EMAIL>>
// released under the MIT license

package ircbnc

import (
	"fmt"
	"net"
	"time"

	"code.cloudfoundry.org/bytefmt"

	"log"

	"github.com/goshuirc/irc-go/ircmsg"
)

// Listener is a listener for a client connected directly to us.
type Listener struct {
	Socket Socket

	Manager     *Manager
	ConnectTime time.Time
	ClientNick  string
	Source      string
	Registered  bool
	regLocks    map[string]bool

	User             *User
	ServerConnection *ServerConnection
}

// RunSocketReader reads lines from the listener socket and dispatches them as appropriate.
func (listener *Listener) RunSocketReader() {
	for {
		line, err := listener.Socket.Read()
		if err != nil {
			break
		}
		listener.processIncomingLine(line)
	}
}

// NewListener creates a new Listener.
func NewListener(m *Manager, conn net.Conn) {
	now := time.Now()
	listener := &Listener{
		Manager:     m,
		ClientNick:  "*",
		ConnectTime: now,
		Source:      m.Source,
		regLocks: map[string]bool{
			"CAP":  true,
			"NICK": false,
			"USER": false,
		},
	}

	maxSendQBytes, _ := bytefmt.ToBytes("32k")
	listener.Socket = NewSocket(conn, maxSendQBytes)
	go listener.Socket.RunSocketWriter()
	go listener.RunSocketReader()
}

// tryRegistration dumps the registration blob and all if it hasn't been sent already.
func (listener *Listener) tryRegistration() {
	if listener.Registered {
		return<commit_msg>listener: force registration only after listener is properly registered<commit_after>// Copyright (c) 2016-2017 <NAME> <<EMAIL>>
// released under the MIT license

package ircbnc

import (
	"fmt"
	"net"
	"time"

	"code.cloudfoundry.org/bytefmt"

	"log"

	"github.com/goshuirc/irc-go/ircmsg"
)

// Listener is a listener for a client connected directly to us.
type Listener struct {
	Socket Socket

	Manager     *Manager
	ConnectTime time.Time
	ClientNick  string
	Source      string
	Registered  bool
	regLocks    map[string]bool

	User             *User
	ServerConnection *ServerConnection
}

// RunSocketReader reads lines from the listener socket and dispatches them as appropriate.
func (listener *Listener) RunSocketReader() {
	for {
		line, err := listener.Socket.Read()
		if err != nil {
			break
		}
		listener.processIncomingLine(line)
	}
}

// NewListener creates a new Listener.
func NewListener(m *Manager, conn net.Conn) {
	now := time.Now()
	listener := &Listener{
		Manager:     m,
		ClientNick:  "*",
		ConnectTime: now,
		Source:      m.Source,
		regLocks: map[string]bool{
			"CAP":      true,
			"NICK":     false,
			"USER":     false,
			"LISTENER": false,
		},
	}

	maxSendQBytes, _ := bytefmt.ToBytes("32k")
	listener.Socket = NewSocket(conn, maxSendQBytes)
	go listener.Socket.RunSocketWriter()
	go listener.RunSocketReader()
}

// tryRegistration dumps the registration blob and all if it hasn't been sent already.
func (listener *Listener) tryRegistration() {
	if listener.Registered {
		return
{'fraction_non_alphanumeric': 0.10820895522388059, 'fraction_numerical': 0.0067842605156037995, 'mean_word_length': 3.579192546583851, 'pattern_counts': {'":': 7, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2044866', 'n_tokens_mistral': 1033, 'n_tokens_neox': 953, 'n_words': 279}