diff options
| author | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-01 12:56:55 +0200 |
|---|---|---|
| committer | Hubert Hirtz <hubert@hirtzfr.eu> | 2020-08-01 12:56:55 +0200 |
| commit | 561f2027a97fe6cb791bf254fb69fe2718e91640 (patch) | |
| tree | fccf236f2bac5322790b6b9d09a37a27241523d9 | |
| parent | Split event handling into functions (diff) | |
Add constants for IRC replies
| -rw-r--r-- | irc/rpl.go | 99 | ||||
| -rw-r--r-- | irc/states.go | 20 | ||||
| -rw-r--r-- | irc/tokens.go | 16 |
3 files changed, 117 insertions, 18 deletions
diff --git a/irc/rpl.go b/irc/rpl.go new file mode 100644 index 0000000..6373972 --- /dev/null +++ b/irc/rpl.go @@ -0,0 +1,99 @@ +package irc + +// IRC replies. +const ( + rplWelcome = "001" // :Welcome message + rplYourhost = "002" // :Your host is... + rplCreated = "003" // :This server was created... + rplMyinfo = "004" // <servername> <version> <umodes> <chan modes> <chan modes with a parameter> + rplIsupport = "005" // 1*13<TOKEN[=value]> :are supported by this server + + rplUmodeis = "221" // <modes> + rplLuserclient = "251" // :<int> users and <int> services on <int> servers + rplLuserop = "252" // <int> :operator(s) online + rplLuserunknown = "253" // <int> :unknown connection(s) + rplLuserchannels = "254" // <int> :channels formed + rplLuserme = "255" // :I have <int> clients and <int> servers + rplAdminme = "256" // <server> :Admin info + rplAdminloc1 = "257" // :<info> + rplAdminloc2 = "258" // :<info> + rplAdminmail = "259" // :<info> + + rplAway = "301" // <nick> :<away message> + rplUnaway = "305" // :You are no longer marked as being away + rplNowaway = "306" // :You have been marked as being away + rplWhoisuser = "311" // <nick> <user> <host> * :<realname> + rplWhoisserver = "312" // <nick> <server> :<server info> + rplWhoisoperator = "313" // <nick> :is an IRC operator + rplEndofwho = "315" // <name> :End of WHO list + rplWhoisidle = "317" // <nick> <integer> [<integer>] :seconds idle [, signon time] + rplEndofwhois = "318" // <nick> :End of WHOIS list + rplWhoischannels = "319" // <nick> :*( (@/+) <channel> " " ) + rplList = "322" // <channel> <# of visible members> <topic> + rplListend = "323" // :End of list + rplChannelmodeis = "324" // <channel> <modes> <mode params> + rplNotopic = "331" // <channel> :No topic set + rplTopic = "332" // <channel> <topic> + rplTopicwhotime = "333" // <channel> <nick> <setat> + rplInviting = "341" // <nick> <channel> + rplInvitelist = "346" // <channel> <invite mask> + rplEndofinvitelist = "347" // <channel> :End of invite list + rplExceptlist = "348" // <channel> <exception mask> + rplEndofexceptlist = "349" // <channel> :End of exception list + rplVersion = "351" // <version> <servername> :<comments> + rplWhoreply = "352" // <channel> <user> <host> <server> <nick> "H"/"G" ["*"] [("@"/"+")] :<hop count> <nick> + rplNamreply = "353" // <=/*/@> <channel> :1*(@/ /+user) + rplEndofnames = "366" // <channel> :End of names list + rplBanlist = "367" // <channel> <ban mask> + rplEndofbanlist = "368" // <channel> :End of ban list + rplInfo = "371" // :<info> + rplMotd = "372" // :- <text> + rplEndofinfo = "374" // :End of INFO + rplMotdstart = "375" // :- <servername> Message of the day - + rplEndofmotd = "376" // :End of MOTD command + rplYoureoper = "381" // :You are now an operator + rplRehashing = "382" // <config file> :Rehashing + rplTime = "391" // <servername> :<time in whatever format> + + errNosuchnick = "401" // <nick> :No such nick/channel + errNosuchchannel = "403" // <channel> :No such channel + errCannotsendtochan = "404" // <channel> :Cannot send to channel + errInvalidcapcmd = "410" // <command> :Unknown cap command + errNorecipient = "411" // :No recipient given + errNotexttosend = "412" // :No text to send + errInputtoolong = "417" // :Input line was too long + errUnknowncommand = "421" // <command> :Unknown command + errNomotd = "422" // :MOTD file missing + errNonicknamegiven = "431" // :No nickname given + errErroneusnickname = "432" // <nick> :Erroneous nickname + errNicknameinuse = "433" // <nick> :Nickname in use + errUsernotinchannel = "441" // <nick> <channel> :User not in channel + errNotonchannel = "442" // <channel> :You're not on that channel + errUseronchannel = "443" // <user> <channel> :is already on channel + errNotregistered = "451" // :You have not registered + errNeedmoreparams = "461" // <command> :Not enough parameters + errAlreadyregistred = "462" // :Already registered + errPasswdmismatch = "464" // :Password incorrect + errYourebannedcreep = "465" // :You're banned from this server + errKeyset = "467" // <channel> :Channel key already set + errChannelisfull = "471" // <channel> :Cannot join channel (+l) + errUnknownmode = "472" // <char> :Don't know this mode for <channel> + errInviteonlychan = "473" // <channel> :Cannot join channel (+I) + errBannedfromchan = "474" // <channel> :Cannot join channel (+b) + errBadchankey = "475" // <channel> :Cannot join channel (+k) + errNopriviledges = "481" // :Permission Denied- You're not an IRC operator + errChanoprivsneeded = "482" // <channel> :You're not an operator + + errUmodeunknownflag = "501" // :Unknown mode flag + errUsersdontmatch = "502" // :Can't change mode for other users + + rplLoggedin = "900" // <nick> <nick>!<ident>@<host> <account> :You are now logged in as <user> + rplLoggedout = "901" // <nick> <nick>!<ident>@<host> :You are now logged out + errNicklocked = "902" // :You must use a nick assigned to you + rplSaslsuccess = "903" // :SASL authentication successful + errSaslfail = "904" // :SASL authentication failed + errSasltoolong = "905" // :SASL message too long + errSaslaborted = "906" // :SASL authentication aborted + errSaslalready = "907" // :You have already authenticated using SASL + rplSaslmechs = "908" // <mechanisms> :are available SASL mechanisms +) diff --git a/irc/states.go b/irc/states.go index 24a667e..5c9f912 100644 --- a/irc/states.go +++ b/irc/states.go @@ -354,7 +354,7 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) { return } } - case "900": + case rplLoggedin: err = s.send("CAP END\r\n") if err != nil { return @@ -362,7 +362,7 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) { s.acct = msg.Params[2] _, _, s.host = FullMask(msg.Params[1]) - case "902", "904", "905", "906", "907", "908": + case errNicklocked, errSaslfail, errSasltoolong, errSaslaborted, errSaslalready, rplSaslmechs: err = s.send("CAP END\r\n") if err != nil { return @@ -423,9 +423,9 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) { } } } - case "372": // RPL_MOTD + case errNomotd: s.motd += "\n" + strings.TrimPrefix(msg.Params[1], "- ") - case "433": // ERR_NICKNAMEINUSE + case errNicknameinuse: s.nick = s.nick + "_" err = s.send("NICK %s\r\n", s.nick) @@ -451,7 +451,7 @@ func (s *Session) handle(msg Message) (ev Event, err error) { } switch msg.Command { - case "001": // RPL_WELCOME + case rplWelcome: s.nick = msg.Params[0] s.lNick = strings.ToLower(s.nick) s.state = ConnRegistered @@ -463,9 +463,9 @@ func (s *Session) handle(msg Message) (ev Event, err error) { return } } - case "005": // RPL_ISUPPORT + case rplIsupport: s.updateFeatures(msg.Params[1 : len(msg.Params)-1]) - case "352": // RPL_WHOREPLY + case rplWhoreply: if s.lNick == strings.ToLower(msg.Params[5]) { s.host = msg.Params[3] } @@ -618,7 +618,7 @@ func (s *Session) handle(msg Message) (ev Event, err error) { Time: t, } } - case "353": // RPL_NAMREPLY + case rplNamreply: channel := strings.ToLower(msg.Params[2]) if c, ok := s.channels[channel]; ok { @@ -635,9 +635,9 @@ func (s *Session) handle(msg Message) (ev Event, err error) { c.Members[lNick] = name.PowerLevel } } - case "366": // RPL_ENDOFNAMES + case rplEndofnames: ev = SelfJoinEvent{ChannelEvent{Channel: msg.Params[1]}} - case "332": // RPL_TOPIC + case rplTopic: channel := strings.ToLower(msg.Params[1]) if c, ok := s.channels[channel]; ok { diff --git a/irc/tokens.go b/irc/tokens.go index d65ae7b..53deaee 100644 --- a/irc/tokens.go +++ b/irc/tokens.go @@ -156,19 +156,19 @@ func Tokenize(line string) (msg Message, err error) { func (msg *Message) Validate() (err error) { switch msg.Command { - case "001": + case rplWelcome: if len(msg.Params) < 1 { err = errNotEnoughParams } - case "005": + case rplIsupport: if len(msg.Params) < 3 { err = errNotEnoughParams } - case "352": + case rplWhoreply: if len(msg.Params) < 8 { err = errNotEnoughParams } - case "372": + case rplMotd: if len(msg.Params) < 2 { err = errNotEnoughParams } @@ -176,11 +176,11 @@ func (msg *Message) Validate() (err error) { if len(msg.Params) < 1 { err = errNotEnoughParams } - case "900": + case rplLoggedin: if len(msg.Params) < 3 { err = errNotEnoughParams } - case "901": + case rplLoggedout: if len(msg.Params) < 2 { err = errNotEnoughParams } @@ -212,11 +212,11 @@ func (msg *Message) Validate() (err error) { if msg.Prefix == "" { err = errNoPrefix } - case "353": + case rplNamreply: if len(msg.Params) < 4 { err = errNotEnoughParams } - case "332": + case rplTopic: if len(msg.Params) < 3 { err = errNotEnoughParams } |
