func sendSignon(u *user.User, ircd *IRCd) {
	log.Info.Printf("[%s] ** Registered\n", u.ID())
	u.SetType(user.RegisteredAsUser)

	destIDs := []string{u.ID()}
	// RPL_WELCOME
	msg := parser.NewNumeric(parser.RPL_WELCOME).Message()
	msg.Args[1] = "Welcome to the " + Config.Network.Name + " network, " + u.Nick() + "!"
	msg.DestIDs = destIDs
	ircd.ToClient <- msg

	// RPL_YOURHOST
	msg = parser.NewNumeric(parser.RPL_YOURHOST).Message()
	msg.Args[1] = "Your host is " + Config.Name + ", running " + REPO_VERSION
	msg.DestIDs = destIDs
	ircd.ToClient <- msg

	// RPL_CREATED
	// RPL_MYINFO
	// RPL_ISUPPORT

	// RPL_LUSERCLIENT
	// RPL_LUSEROP
	// RPL_LUSERUNKNOWN
	// RPL_LUSERCHANNELS
	// RPL_LUSERME

	// RPL_LOCALUSERS
	// RPL_GLOBALUSERS

	// RPL_NOMOTD
	msg = parser.NewNumeric(parser.ERR_NOMOTD).Message()
	msg.DestIDs = destIDs
	ircd.ToClient <- msg

	msg = &parser.Message{
		Command: parser.CMD_MODE,
		Prefix:  "*",
		Args: []string{
			"*",
			"+i",
		},
		DestIDs: destIDs,
	}
	ircd.ToClient <- msg
}
// Handle the NICK, USER, SERVER, and PASS messages
func ConnReg(hook string, msg *parser.Message, ircd *IRCd) {
	var err os.Error
	var u *user.User
	var s *server.Server

	switch len(msg.SenderID) {
	case 3:
		s = server.Get(msg.SenderID, true)
	case 9:
		u = user.Get(msg.SenderID)
	}

	switch msg.Command {
	case parser.CMD_NICK:
		// NICK <nick>
		if u != nil {
			nick := msg.Args[0]
			err = u.SetNick(nick)
		}
	case parser.CMD_USER:
		// USER <user> . . :<real name>
		if u != nil {
			username, realname := msg.Args[0], msg.Args[3]
			err = u.SetUser(username, realname)
		}
	case parser.CMD_PASS:
		if s != nil {
			if len(msg.Args) != 4 {
				return
			}
			// PASS <password> TS <ver> <pfx>
			err = s.SetPass(msg.Args[0], msg.Args[2], msg.Args[3])
		}
	case parser.CMD_CAPAB:
		if s != nil {
			err = s.SetCapab(msg.Args[0])
		}
	case parser.CMD_SERVER:
		if s != nil {
			err = s.SetServer(msg.Args[0], msg.Args[1])
		}
	default:
		log.Warn.Printf("Unknown command %q", msg)
	}

	if u != nil {
		if err != nil {
			switch err := err.(type) {
			case *parser.Numeric:
				msg := err.Message()
				msg.DestIDs = append(msg.DestIDs, u.ID())
				ircd.ToClient <- msg
				return
			default:
				msg := &parser.Message{
					Command: parser.CMD_ERROR,
					Args:    []string{err.String()},
					DestIDs: []string{u.ID()},
				}
				ircd.ToClient <- msg
				return
			}
		}

		nickname, username, realname, _ := u.Info()
		if nickname != "*" && username != "" {
			// Notify servers
			for sid := range server.Iter() {
				ircd.ToServer <- &parser.Message{
					Prefix:  Config.SID,
					Command: parser.CMD_UID,
					Args: []string{
						nickname,
						"1",
						u.TS(),
						"+i",
						username,
						"some.host",
						"127.0.0.1",
						u.ID(),
						realname,
					},
					DestIDs: []string{sid},
				}
			}

			// Process signon
			sendSignon(u, ircd)
			return
		}
	}

	if s != nil {
		if err != nil {
			switch err := err.(type) {
			case *parser.Numeric:
				msg := err.Message()
				msg.DestIDs = append(msg.DestIDs, s.ID())
				ircd.ToServer <- msg
				return
			default:
				msg := &parser.Message{
					Command: parser.CMD_ERROR,
					Args:    []string{err.String()},
					DestIDs: []string{s.ID()},
				}
				ircd.ToServer <- msg
				return
			}
		}

		sid, serv, pass, capab := s.Info()
		if sid != "" && serv != "" && pass != "" && len(capab) > 0 {
			// Notify servers
			for sid := range server.Iter() {
				ircd.ToServer <- &parser.Message{
					Prefix:  Config.SID,
					Command: parser.CMD_SID,
					Args: []string{
						serv,
						"2",
						sid,
						"some server",
					},
					DestIDs: []string{sid},
				}
			}

			sendServerSignon(s, ircd)
			Burst(s, ircd)
		}
	}
}