// accept handles the initial negotiation phase for connecting to the // server. This is basically in 4 parts: // // * PASS // * NICK // * USER // // On success a RPL_WELCOME response is returned to the new client. func (s *Server) accept(conn net.Conn) bool { r := bufio.NewReader(conn) line, err := r.ReadBytes('\n') if err != nil { log.Println(err) return false } parsed := message.Parse(string(line)) if parsed.Command != "PASS" { return false } if !parsed.Params.Any() { conn.Write([]byte(errors.NeedMoreParams(s.Name(), "PASS").String())) return false } password := parsed.Params.Get(0) if password != "test" { return false } client := NewClient("", conn, s) s.clients.Add(client) return true }
func (c *conn) receiver() { r := bufio.NewReader(c.conn) for { line, err := r.ReadBytes('\n') if err != nil { c.handler.OnError(err) break } c.handler.OnReceive(message.Parse(string(line))) } }