コード例 #1
0
func Burst(serv *server.Server, ircd *IRCd) {
	destIDs := []string{serv.ID()}
	sid := Config.SID
	var msg *parser.Message

	// SID/SERVER
	// UID/EUID
	for uid := range user.Iter() {
		u := user.Get(uid)
		nick, username, name, typ := u.Info()
		if typ != user.RegisteredAsUser {
			continue
		}
		msg = &parser.Message{
			Prefix:  sid,
			Command: parser.CMD_UID,
			Args: []string{
				nick,
				// hopcount
				"1",
				u.TS(),
				// umodes
				"+i",
				username,
				// visible hostname
				"some.host",
				// IP addr
				"127.0.0.1",
				uid,
				name,
			},
			DestIDs: destIDs,
		}
		ircd.ToServer <- msg
	}
	// Optional: ENCAP REALHOST, ENCAP LOGIN, AWAY
	// SJOIN
	for channame := range channel.Iter() {
		chanobj, _ := channel.Get(channame, false)
		msg = &parser.Message{
			Prefix:  sid,
			Command: parser.CMD_SJOIN,
			Args: []string{
				chanobj.TS(),
				channame,
				// modes, params...
				"+", // "+nt",
				strings.Join(chanobj.UserIDsWithPrefix(), " "),
			},
			DestIDs: destIDs,
		}
		ircd.ToServer <- msg
	}
	// Optional: BMAST
	// Optional: TB
}
コード例 #2
0
func sendServerSignon(s *server.Server, ircd *IRCd) {
	log.Info.Printf("{%s} ** Registered As Server\n", s.ID())
	s.SetType(server.RegisteredAsServer)

	destIDs := []string{s.ID()}

	var msg *parser.Message

	msg = &parser.Message{
		Command: parser.CMD_PASS,
		Args: []string{
			"testpass", // TODO
			"TS",
			"6",
			Config.SID,
		},
		DestIDs: destIDs,
	}
	ircd.ToServer <- msg

	msg = &parser.Message{
		Command: parser.CMD_CAPAB,
		Args: []string{
			//"QS EX CHW IE KLN KNOCK TB UNKLN CLUSTER ENCAP SERVICES RSFNC SAVE EUID EOPMOD BAN MLOCK",
			"QS ENCAP", // TODO
		},
		DestIDs: destIDs,
	}
	ircd.ToServer <- msg

	msg = &parser.Message{
		Command: parser.CMD_SERVER,
		Args: []string{
			Config.Name,
			"1",
			"IRCd",
		},
		DestIDs: destIDs,
	}
	ircd.ToServer <- msg
}
コード例 #3
0
// 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)
		}
	}
}