func cmdWho(source interface{}, params [][]byte) { c := source.(*Client) channame := string(params[0]) if channame[0] == '#' { channame = channame[1:] } var ch *core.Channel if ch = core.FindChannel("", channame); ch == nil { c.SendLineTo(nil, "403", "#%s :No such channel.", channame) return } // If the user isn't on the channel, don't let them check unless they // can view private channel data. if m := ch.GetMember(c.u); m == nil { if ok, err := perm.CheckChanViewData(me, c.u, ch, "members"); !ok { c.SendLineTo(nil, "482", "#%s :%s", ch.Name(), err) return } } it := ch.Users() c.WriteBlock(func() []byte { if it == nil { return nil } user := it.User() var prefixes string if user.Data("away") == "" { prefixes += "H" } else { prefixes += "G" } if user.Data("op") != "" { prefixes += "*" } prefixes += ChanModes.GetPrefixes(it) servername := core.Global.Data("name") result := fmt.Sprintf(":%s 352 %s #%s %s %s %s %s %s :0 %s\r\n", servername, c.u.Nick(), channame, user.GetIdent(), user.GetHostname(), servername, user.Nick(), prefixes, user.Data("realname")) it = it.ChanNext() return []byte(result) }) c.SendLineTo(nil, "315", "%s :End of /WHO list.", params[0]) }
func cmdNames(source interface{}, params [][]byte) { c := source.(*Client) channame := string(params[0]) if len(channame) > 0 && channame[0] == '#' { channame = channame[1:] } var ch *core.Channel if ch = core.FindChannel("", channame); ch == nil { c.SendLineTo(nil, "403", "#%s :No such channel.", channame) return } // If the user isn't on the channel, don't let them check unless they // can view private channel data. // Otherwise, get their prefixes. var myprefix string if m := ch.GetMember(c.u); m == nil { if ok, err := perm.CheckChanViewData(me, c.u, ch, "members"); !ok { c.SendLineTo(nil, "482", "#%s :%s", ch.Name(), err) return } myprefix = "=" } else { myprefix = ChanModes.GetPrefixes(m) } it := ch.Users() c.WriteBlock(func() []byte { if it == nil { return nil } names := fmt.Sprintf(":%s 353 %s %s #%s :", core.Global.Data("name"), c.u.Nick(), myprefix, channame) for ; it != nil; it = it.ChanNext() { name := ChanModes.GetPrefixes(it) + it.User().Nick() if len(names)+len(name) > 508 { break } names += " " + name } names += "\r\n" return []byte(names) }) c.SendLineTo(nil, "366", "#%s :End of /NAMES list", channame) }