func SQuit(hook string, msg *parser.Message, ircd *IRCd) { split, reason := msg.Args[0], msg.Args[1] if split == Config.SID { split = msg.SenderID } // Forward for sid := range server.Iter() { if sid != msg.SenderID { msg := msg.Dup() msg.DestIDs = []string{sid} ircd.ToServer <- msg } } if server.IsLocal(split) { ircd.ToServer <- &parser.Message{ Command: parser.CMD_ERROR, Args: []string{ "SQUIT: " + reason, }, } } sids := server.Unlink(split) peers := user.Netsplit(sids) notify := channel.Netsplit(Config.SID, peers) log.Debug.Printf("NET SPLIT: %s", split) log.Debug.Printf(" - SIDs: %v", sids) log.Debug.Printf(" - Peers: %v", peers) log.Debug.Printf(" - Notify: %v", notify) for uid, peers := range notify { if len(peers) > 0 { ircd.ToClient <- &parser.Message{ Prefix: uid, Command: parser.CMD_QUIT, Args: []string{ "*.net *.split", }, DestIDs: peers, } } } // Delete all of the peers if len(peers) > 0 { ircd.ToClient <- &parser.Message{ Command: parser.INT_DELUSER, DestIDs: peers, } } }
// 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) } } }