2009-11-29 20:23:15 +00:00
|
|
|
package irc
|
|
|
|
|
|
|
|
// this file contains the basic set of event handlers
|
|
|
|
// to manage tracking an irc connection etc.
|
|
|
|
|
|
|
|
import (
|
2009-12-17 21:30:18 +00:00
|
|
|
"strings"
|
|
|
|
"strconv"
|
2009-11-29 20:23:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Add an event handler for a specific IRC command
|
2009-12-17 21:30:18 +00:00
|
|
|
func (conn *Conn) AddHandler(name string, f func(*Conn, *Line)) {
|
|
|
|
n := strings.ToUpper(name)
|
2009-11-29 20:23:15 +00:00
|
|
|
if e, ok := conn.events[n]; ok {
|
|
|
|
if len(e) == cap(e) {
|
|
|
|
// crap, we're full. expand e by another 10 handler slots
|
2009-12-17 21:30:18 +00:00
|
|
|
ne := make([]func(*Conn, *Line), len(e), len(e)+10)
|
|
|
|
for i := 0; i < len(e); i++ {
|
|
|
|
ne[i] = e[i]
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
e = ne
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
e = e[0 : len(e)+1]
|
|
|
|
e[len(e)-1] = f
|
2009-11-29 20:23:15 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
e := make([]func(*Conn, *Line), 1, 10)
|
|
|
|
e[0] = f
|
|
|
|
conn.events[n] = e
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// loops through all event handlers for line.Cmd, running each in a goroutine
|
2009-12-17 17:22:31 +00:00
|
|
|
func (conn *Conn) dispatchEvent(line *Line) {
|
|
|
|
// seems that we end up dispatching an event with a nil line when receiving
|
|
|
|
// EOF from the server. Until i've tracked down why....
|
|
|
|
if line == nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.dispatchEvent(): buh? line == nil :-(")
|
2009-12-17 17:22:31 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2009-11-29 20:23:15 +00:00
|
|
|
// So, I think CTCP and (in particular) CTCP ACTION are better handled as
|
|
|
|
// separate events as opposed to forcing people to have gargantuan PRIVMSG
|
|
|
|
// handlers to cope with the possibilities.
|
2009-12-17 21:14:01 +00:00
|
|
|
if line.Cmd == "PRIVMSG" && len(line.Text) > 2 &&
|
|
|
|
line.Text[0] == '\001' && line.Text[len(line.Text)-1] == '\001' {
|
2009-11-29 20:23:15 +00:00
|
|
|
// WOO, it's a CTCP message
|
2009-12-17 21:30:18 +00:00
|
|
|
t := strings.Split(line.Text[1:len(line.Text)-1], " ", 2)
|
2009-11-29 20:23:15 +00:00
|
|
|
if c := strings.ToUpper(t[0]); c == "ACTION" {
|
|
|
|
// make a CTCP ACTION it's own event a-la PRIVMSG
|
2009-12-17 21:30:18 +00:00
|
|
|
line.Cmd = c
|
2009-11-29 20:23:15 +00:00
|
|
|
} else {
|
|
|
|
// otherwise, dispatch a generic CTCP event that
|
|
|
|
// contains the type of CTCP in line.Args[0]
|
2009-12-17 21:30:18 +00:00
|
|
|
line.Cmd = "CTCP"
|
|
|
|
a := make([]string, len(line.Args)+1)
|
|
|
|
a[0] = c
|
|
|
|
for i := 0; i < len(line.Args); i++ {
|
|
|
|
a[i+1] = line.Args[i]
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
line.Args = a
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
|
|
|
if len(t) > 1 {
|
2009-12-17 21:30:18 +00:00
|
|
|
// for some CTCP messages this could make more sense
|
2009-11-29 20:23:15 +00:00
|
|
|
// in line.Args[], but meh. MEH, I say.
|
2009-12-17 21:30:18 +00:00
|
|
|
line.Text = t[1]
|
2009-11-29 20:23:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if funcs, ok := conn.events[line.Cmd]; ok {
|
|
|
|
for _, f := range funcs {
|
|
|
|
go f(conn, line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// sets up the internal event handlers to do useful things with lines
|
|
|
|
// XXX: is there a better way of doing this?
|
2009-12-17 17:22:31 +00:00
|
|
|
// Turns out there may be but it's not actually implemented in the language yet
|
2009-12-17 21:30:18 +00:00
|
|
|
// according to the people on freenode/#go-nuts ... :-(
|
2009-12-17 17:22:31 +00:00
|
|
|
// see: http://golang.org/doc/go_spec.html#Method_expressions for details
|
|
|
|
// I think this means we should be able to do something along the lines of:
|
|
|
|
// conn.AddHandler("event", (*Conn).h_handler);
|
|
|
|
// where h_handler is declared in the irc package as:
|
|
|
|
// func (conn *Conn) h_handler(line *Line) {}
|
|
|
|
// in the future, but for now the compiler throws a hissy fit.
|
|
|
|
func (conn *Conn) setupEvents() {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.events = make(map[string][]func(*Conn, *Line))
|
2009-12-17 17:22:31 +00:00
|
|
|
|
2009-11-29 20:23:15 +00:00
|
|
|
// Basic ping/pong handler
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.AddHandler("PING", func(conn *Conn, line *Line) { conn.Raw("PONG :" + line.Text) })
|
2009-11-29 20:23:15 +00:00
|
|
|
|
|
|
|
// Handler to trigger a "CONNECTED" event on receipt of numeric 001
|
2009-12-17 17:22:31 +00:00
|
|
|
conn.AddHandler("001", func(conn *Conn, line *Line) {
|
|
|
|
// we're connected!
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.connected = true
|
|
|
|
conn.dispatchEvent(&Line{Cmd: "CONNECTED"})
|
2009-12-17 17:22:31 +00:00
|
|
|
// and we're being given our hostname (from the server's perspective)
|
|
|
|
if ridx := strings.LastIndex(line.Text, " "); ridx != -1 {
|
2009-12-17 21:30:18 +00:00
|
|
|
h := line.Text[ridx+1 : len(line.Text)]
|
2009-12-17 17:22:31 +00:00
|
|
|
if idx := strings.Index(h, "@"); idx != -1 {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.Me.Host = h[idx+1 : len(h)]
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-11-29 20:23:15 +00:00
|
|
|
|
2009-12-17 17:22:31 +00:00
|
|
|
// XXX: do we need 005 protocol support message parsing here?
|
|
|
|
// probably in the future, but I can't quite be arsed yet.
|
|
|
|
/*
|
2009-12-17 21:30:18 +00:00
|
|
|
:irc.pl0rt.org 005 GoTest CMDS=KNOCK,MAP,DCCALLOW,USERIP UHNAMES NAMESX SAFELIST HCN MAXCHANNELS=20 CHANLIMIT=#:20 MAXLIST=b:60,e:60,I:60 NICKLEN=30 CHANNELLEN=32 TOPICLEN=307 KICKLEN=307 AWAYLEN=307 :are supported by this server
|
|
|
|
:irc.pl0rt.org 005 GoTest MAXTARGETS=20 WALLCHOPS WATCH=128 WATCHOPTS=A SILENCE=15 MODES=12 CHANTYPES=# PREFIX=(qaohv)~&@%+ CHANMODES=beI,kfL,lj,psmntirRcOAQKVCuzNSMT NETWORK=bb101.net CASEMAPPING=ascii EXTBAN=~,cqnr ELIST=MNUCT :are supported by this server
|
|
|
|
:irc.pl0rt.org 005 GoTest STATUSMSG=~&@%+ EXCEPTS INVEX :are supported by this server
|
2009-12-17 17:22:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Handler to deal with "433 :Nickname already in use"
|
|
|
|
conn.AddHandler("433", func(conn *Conn, line *Line) {
|
|
|
|
// Args[1] is the new nick we were attempting to acquire
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.Nick(line.Args[1] + "_")
|
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handler NICK messages to inform us about nick changes
|
|
|
|
conn.AddHandler("NICK", func(conn *Conn, line *Line) {
|
|
|
|
// all nicks should be handled the same way, our own included
|
|
|
|
if n := conn.GetNick(line.Nick); n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
n.ReNick(line.Text)
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.NICK(): buh? unknown nick %s.", line.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle VERSION requests and CTCP PING
|
|
|
|
conn.AddHandler("CTCP", func(conn *Conn, line *Line) {
|
|
|
|
if line.Args[0] == "VERSION" {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.CtcpReply(line.Nick, "VERSION", "powered by goirc...")
|
2009-12-17 17:22:31 +00:00
|
|
|
} else if line.Args[0] == "PING" {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.CtcpReply(line.Nick, "PING", line.Text)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle JOINs to channels to maintain state
|
|
|
|
conn.AddHandler("JOIN", func(conn *Conn, line *Line) {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch := conn.GetChannel(line.Text)
|
|
|
|
n := conn.GetNick(line.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
if ch == nil {
|
|
|
|
// first we've seen of this channel, so should be us joining it
|
|
|
|
// NOTE this will also take care of n == nil && ch == nil
|
|
|
|
if n != conn.Me {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.JOIN(): buh? JOIN to unknown channel %s recieved from (non-me) nick %s", line.Text, line.Nick)
|
|
|
|
return
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
ch = conn.NewChannel(line.Text)
|
2009-12-17 17:22:31 +00:00
|
|
|
// since we don't know much about this channel, ask server for info
|
|
|
|
// we get the channel users automatically in 353 and the channel
|
|
|
|
// topic in 332 on join, so we just need to get the modes
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.Mode(ch.Name)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
if n == nil {
|
|
|
|
// this is the first we've seen of this nick
|
2009-12-17 21:30:18 +00:00
|
|
|
n = conn.NewNick(line.Nick, line.Ident, "", line.Host)
|
2009-12-17 17:22:31 +00:00
|
|
|
// since we don't know much about this nick, ask server for info
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.Whois(n.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
// this takes care of both nick and channel linking \o/
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.AddNick(n)
|
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle PARTs from channels to maintain state
|
|
|
|
conn.AddHandler("PART", func(conn *Conn, line *Line) {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch := conn.GetChannel(line.Args[0])
|
|
|
|
n := conn.GetNick(line.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
if ch != nil && n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.DelNick(n)
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.PART(): buh? PART of channel %s by nick %s", line.Args[0], line.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle KICKs from channels to maintain state
|
|
|
|
conn.AddHandler("KICK", func(conn *Conn, line *Line) {
|
|
|
|
// XXX: this won't handle autorejoining channels on KICK
|
|
|
|
// it's trivial to do this in a seperate handler...
|
2009-12-17 21:30:18 +00:00
|
|
|
ch := conn.GetChannel(line.Args[0])
|
|
|
|
n := conn.GetNick(line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
if ch != nil && n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.DelNick(n)
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.KICK(): buh? KICK from channel %s of nick %s", line.Args[0], line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle other people's QUITs
|
|
|
|
conn.AddHandler("QUIT", func(conn *Conn, line *Line) {
|
|
|
|
if n := conn.GetNick(line.Nick); n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
n.Delete()
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.QUIT(): buh? QUIT from unknown nick %s", line.Nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle MODE changes for channels we know about (and our nick personally)
|
|
|
|
// this is moderately ugly. suggestions for improvement welcome
|
|
|
|
conn.AddHandler("MODE", func(conn *Conn, line *Line) {
|
|
|
|
// channel modes first
|
|
|
|
if ch := conn.GetChannel(line.Args[0]); ch != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
modeargs := line.Args[2:len(line.Args)]
|
|
|
|
var modeop bool // true => add mode, false => remove mode
|
|
|
|
var modestr string
|
2009-12-17 17:22:31 +00:00
|
|
|
for i := 0; i < len(line.Args[1]); i++ {
|
|
|
|
switch m := line.Args[1][i]; m {
|
|
|
|
case '+':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = true
|
|
|
|
modestr = string(m)
|
2009-12-17 17:22:31 +00:00
|
|
|
case '-':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = false
|
|
|
|
modestr = string(m)
|
|
|
|
case 'i':
|
|
|
|
ch.Modes.InviteOnly = modeop
|
|
|
|
case 'm':
|
|
|
|
ch.Modes.Moderated = modeop
|
|
|
|
case 'n':
|
|
|
|
ch.Modes.NoExternalMsg = modeop
|
|
|
|
case 'p':
|
|
|
|
ch.Modes.Private = modeop
|
|
|
|
case 's':
|
|
|
|
ch.Modes.Secret = modeop
|
|
|
|
case 't':
|
|
|
|
ch.Modes.ProtectedTopic = modeop
|
|
|
|
case 'z':
|
|
|
|
ch.Modes.SSLOnly = modeop
|
|
|
|
case 'O':
|
|
|
|
ch.Modes.OperOnly = modeop
|
2009-12-17 17:22:31 +00:00
|
|
|
case 'k':
|
|
|
|
if len(modeargs) != 0 {
|
|
|
|
ch.Modes.Key, modeargs = modeargs[0], modeargs[1:len(modeargs)]
|
|
|
|
} else {
|
|
|
|
conn.error("irc.MODE(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
|
|
|
}
|
|
|
|
case 'l':
|
|
|
|
if len(modeargs) != 0 {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.Modes.Limit, _ = strconv.Atoi(modeargs[0])
|
|
|
|
modeargs = modeargs[1:len(modeargs)]
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
|
|
|
conn.error("irc.MODE(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
|
|
|
}
|
|
|
|
case 'q', 'a', 'o', 'h', 'v':
|
|
|
|
if len(modeargs) != 0 {
|
2009-12-17 21:30:18 +00:00
|
|
|
n := conn.GetNick(modeargs[0])
|
2009-12-17 17:22:31 +00:00
|
|
|
if p, ok := ch.Nicks[n]; ok && n != nil {
|
|
|
|
switch m {
|
2009-12-17 21:30:18 +00:00
|
|
|
case 'q':
|
|
|
|
p.Owner = modeop
|
|
|
|
case 'a':
|
|
|
|
p.Admin = modeop
|
|
|
|
case 'o':
|
|
|
|
p.Op = modeop
|
|
|
|
case 'h':
|
|
|
|
p.HalfOp = modeop
|
|
|
|
case 'v':
|
|
|
|
p.Voice = modeop
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
modeargs = modeargs[1:len(modeargs)]
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.MODE(): MODE %s %s%s %s: buh? state tracking failure.", ch.Name, modestr, m, modeargs[0])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.MODE(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if n := conn.GetNick(line.Args[0]); n != nil {
|
|
|
|
// nick mode change, should be us
|
|
|
|
if n != conn.Me {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.MODE(): buh? recieved MODE %s for (non-me) nick %s", line.Args[1], n.Nick)
|
|
|
|
return
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
var modeop bool // true => add mode, false => remove mode
|
2009-12-17 17:22:31 +00:00
|
|
|
for i := 0; i < len(line.Text); i++ {
|
|
|
|
switch m := line.Text[i]; m {
|
|
|
|
case '+':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = true
|
2009-12-17 17:22:31 +00:00
|
|
|
case '-':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = false
|
|
|
|
case 'i':
|
|
|
|
n.Modes.Invisible = modeop
|
|
|
|
case 'o':
|
|
|
|
n.Modes.Oper = modeop
|
|
|
|
case 'w':
|
|
|
|
n.Modes.WallOps = modeop
|
|
|
|
case 'x':
|
|
|
|
n.Modes.HiddenHost = modeop
|
|
|
|
case 'z':
|
|
|
|
n.Modes.SSL = modeop
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.MODE(): buh? not sure what to do with MODE %s %s", line.Args[0], line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle TOPIC changes for channels
|
|
|
|
conn.AddHandler("TOPIC", func(conn *Conn, line *Line) {
|
|
|
|
if ch := conn.GetChannel(line.Args[0]); ch != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.Topic = line.Text
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.TOPIC(): buh? topic change on unknown channel %s", line.Args[0])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle 311 whois reply
|
|
|
|
conn.AddHandler("311", func(conn *Conn, line *Line) {
|
|
|
|
if n := conn.GetNick(line.Args[1]); n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
n.Ident = line.Args[2]
|
|
|
|
n.Host = line.Args[3]
|
|
|
|
n.Name = line.Text
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.311(): buh? received WHOIS info for unknown nick %s", line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle 324 mode reply
|
|
|
|
conn.AddHandler("324", func(conn *Conn, line *Line) {
|
|
|
|
// XXX: copypasta from MODE, needs tidying.
|
|
|
|
if ch := conn.GetChannel(line.Args[1]); ch != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
modeargs := line.Args[3:len(line.Args)]
|
|
|
|
var modeop bool // true => add mode, false => remove mode
|
|
|
|
var modestr string
|
2009-12-17 17:22:31 +00:00
|
|
|
for i := 0; i < len(line.Args[2]); i++ {
|
|
|
|
switch m := line.Args[2][i]; m {
|
|
|
|
case '+':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = true
|
|
|
|
modestr = string(m)
|
2009-12-17 17:22:31 +00:00
|
|
|
case '-':
|
2009-12-17 21:30:18 +00:00
|
|
|
modeop = false
|
|
|
|
modestr = string(m)
|
|
|
|
case 'i':
|
|
|
|
ch.Modes.InviteOnly = modeop
|
|
|
|
case 'm':
|
|
|
|
ch.Modes.Moderated = modeop
|
|
|
|
case 'n':
|
|
|
|
ch.Modes.NoExternalMsg = modeop
|
|
|
|
case 'p':
|
|
|
|
ch.Modes.Private = modeop
|
|
|
|
case 's':
|
|
|
|
ch.Modes.Secret = modeop
|
|
|
|
case 't':
|
|
|
|
ch.Modes.ProtectedTopic = modeop
|
|
|
|
case 'z':
|
|
|
|
ch.Modes.SSLOnly = modeop
|
|
|
|
case 'O':
|
|
|
|
ch.Modes.OperOnly = modeop
|
2009-12-17 17:22:31 +00:00
|
|
|
case 'k':
|
|
|
|
if len(modeargs) != 0 {
|
|
|
|
ch.Modes.Key, modeargs = modeargs[0], modeargs[1:len(modeargs)]
|
|
|
|
} else {
|
|
|
|
conn.error("irc.324(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
|
|
|
}
|
|
|
|
case 'l':
|
|
|
|
if len(modeargs) != 0 {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.Modes.Limit, _ = strconv.Atoi(modeargs[0])
|
|
|
|
modeargs = modeargs[1:len(modeargs)]
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
|
|
|
conn.error("irc.324(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.324(): buh? received MODE settings for unknown channel %s", line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle 332 topic reply on join to channel
|
|
|
|
conn.AddHandler("332", func(conn *Conn, line *Line) {
|
|
|
|
if ch := conn.GetChannel(line.Args[1]); ch != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.Topic = line.Text
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.332(): buh? received TOPIC value for unknown channel %s", line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
|
|
|
|
// Handle 353 names reply
|
|
|
|
conn.AddHandler("353", func(conn *Conn, line *Line) {
|
|
|
|
if ch := conn.GetChannel(line.Args[2]); ch != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
nicks := strings.Split(line.Text, " ", 0)
|
2009-12-17 17:22:31 +00:00
|
|
|
for _, nick := range nicks {
|
|
|
|
// UnrealIRCd's coders are lazy and leave a trailing space
|
|
|
|
if nick == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
switch c := nick[0]; c {
|
|
|
|
case '~', '&', '@', '%', '+':
|
2009-12-17 21:30:18 +00:00
|
|
|
nick = nick[1:len(nick)]
|
|
|
|
fallthrough
|
2009-12-17 17:22:31 +00:00
|
|
|
default:
|
2009-12-17 21:30:18 +00:00
|
|
|
n := conn.GetNick(nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
if n == nil {
|
|
|
|
// we don't know this nick yet!
|
2009-12-17 21:30:18 +00:00
|
|
|
n = conn.NewNick(nick, "", "", "")
|
|
|
|
conn.Whois(nick)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
if n != conn.Me {
|
|
|
|
// we will be in the names list, but should also be in
|
|
|
|
// the channel's nick list from the JOIN handler above
|
2009-12-17 21:30:18 +00:00
|
|
|
ch.AddNick(n)
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
p := ch.Nicks[n]
|
2009-12-17 17:22:31 +00:00
|
|
|
switch c {
|
2009-12-17 21:30:18 +00:00
|
|
|
case '~':
|
|
|
|
p.Owner = true
|
|
|
|
case '&':
|
|
|
|
p.Admin = true
|
|
|
|
case '@':
|
|
|
|
p.Op = true
|
|
|
|
case '%':
|
|
|
|
p.HalfOp = true
|
|
|
|
case '+':
|
|
|
|
p.Voice = true
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.353(): buh? received NAMES list for unknown channel %s", line.Args[2])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-11-29 20:23:15 +00:00
|
|
|
|
2009-12-17 17:22:31 +00:00
|
|
|
// Handle 671 whois reply (nick connected via SSL)
|
|
|
|
conn.AddHandler("671", func(conn *Conn, line *Line) {
|
|
|
|
if n := conn.GetNick(line.Args[1]); n != nil {
|
2009-12-17 21:30:18 +00:00
|
|
|
n.Modes.SSL = true
|
2009-12-17 17:22:31 +00:00
|
|
|
} else {
|
2009-12-17 21:30:18 +00:00
|
|
|
conn.error("irc.671(): buh? received WHOIS SSL info for unknown nick %s", line.Args[1])
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|
2009-12-17 21:30:18 +00:00
|
|
|
})
|
2009-12-17 17:22:31 +00:00
|
|
|
}
|