Exemplo n.º 1
0
// Local PARTs only
func Part(hook string, msg *parser.Message, ircd *IRCd) {
	reason := "Leaving"
	if len(msg.Args) > 1 {
		reason = msg.Args[1]
	}

	leftchans := []string{}

	for _, channame := range strings.Split(msg.Args[0], ",") {
		channel, err := channel.Get(channame, false)
		if num, ok := err.(*parser.Numeric); ok {
			ircd.ToClient <- num.Message(msg.SenderID)
			continue
		}

		members, err := channel.Part(msg.SenderID)
		if num, ok := err.(*parser.Numeric); ok {
			ircd.ToClient <- num.Message(msg.SenderID)
			continue
		}

		notify := []string{}
		for _, uid := range members {
			if uid[:3] == Config.SID {
				notify = append(notify, uid)
			}
		}

		if len(notify) > 0 {
			ircd.ToClient <- &parser.Message{
				Prefix:  msg.SenderID,
				Command: parser.CMD_PART,
				Args: []string{
					channel.Name(),
				},
				DestIDs: notify,
			}
		}

		leftchans = append(leftchans, channame)
	}

	// Forward to other servers
	if len(leftchans) > 0 {
		leftstr := strings.Join(leftchans, ",")
		for sid := range server.Iter() {
			ircd.ToServer <- &parser.Message{
				Prefix:  msg.SenderID,
				Command: parser.CMD_PART,
				Args: []string{
					leftstr,
					reason,
				},
				DestIDs: []string{sid},
			}
		}
	}
}
Exemplo n.º 2
0
// Server PART
func SPart(hook string, msg *parser.Message, ircd *IRCd) {
	chanlist, reason := strings.Split(msg.Args[0], ","), msg.Args[1]

	// Forward on to other servers
	for fwd := range server.Iter() {
		if fwd != msg.SenderID {
			log.Debug.Printf("Forwarding PART from %s to %s", msg.SenderID, fwd)
			fmsg := msg.Dup()
			fmsg.DestIDs = []string{fwd}
		}
	}

	for _, channame := range chanlist {
		channel, err := channel.Get(channame, false)
		if num, ok := err.(*parser.Numeric); ok {
			ircd.ToServer <- num.Error(msg.SenderID)
			return
		}

		chanusers, err := channel.Part(msg.Prefix)
		if num, ok := err.(*parser.Numeric); ok {
			ircd.ToServer <- num.Error(msg.SenderID)
			return
		}

		notify := []string{}
		for _, uid := range chanusers {
			if uid[:3] == Config.SID {
				notify = append(notify, uid)
			}
		}

		if len(notify) > 0 {
			ircd.ToClient <- &parser.Message{
				Prefix:  msg.Prefix,
				Command: parser.CMD_PART,
				Args: []string{
					channel.Name(),
					reason,
				},
				DestIDs: notify,
			}
		}
	}
}