commit 561f202

Hubert Hirtz  ·  2020-08-01 10:56:55 +0000 UTC
parent dad1d0e
Add constants for IRC replies
3 files changed,  +117, -18
+99, -0
  1@@ -0,0 +1,99 @@
  2+package irc
  3+
  4+// IRC replies.
  5+const (
  6+	rplWelcome  = "001" // :Welcome message
  7+	rplYourhost = "002" // :Your host is...
  8+	rplCreated  = "003" // :This server was created...
  9+	rplMyinfo   = "004" // <servername> <version> <umodes> <chan modes> <chan modes with a parameter>
 10+	rplIsupport = "005" // 1*13<TOKEN[=value]> :are supported by this server
 11+
 12+	rplUmodeis       = "221" // <modes>
 13+	rplLuserclient   = "251" // :<int> users and <int> services on <int> servers
 14+	rplLuserop       = "252" // <int> :operator(s) online
 15+	rplLuserunknown  = "253" // <int> :unknown connection(s)
 16+	rplLuserchannels = "254" // <int> :channels formed
 17+	rplLuserme       = "255" // :I have <int> clients and <int> servers
 18+	rplAdminme       = "256" // <server> :Admin info
 19+	rplAdminloc1     = "257" // :<info>
 20+	rplAdminloc2     = "258" // :<info>
 21+	rplAdminmail     = "259" // :<info>
 22+
 23+	rplAway            = "301" // <nick> :<away message>
 24+	rplUnaway          = "305" // :You are no longer marked as being away
 25+	rplNowaway         = "306" // :You have been marked as being away
 26+	rplWhoisuser       = "311" // <nick> <user> <host> * :<realname>
 27+	rplWhoisserver     = "312" // <nick> <server> :<server info>
 28+	rplWhoisoperator   = "313" // <nick> :is an IRC operator
 29+	rplEndofwho        = "315" // <name> :End of WHO list
 30+	rplWhoisidle       = "317" // <nick> <integer> [<integer>] :seconds idle [, signon time]
 31+	rplEndofwhois      = "318" // <nick> :End of WHOIS list
 32+	rplWhoischannels   = "319" // <nick> :*( (@/+) <channel> " " )
 33+	rplList            = "322" // <channel> <# of visible members> <topic>
 34+	rplListend         = "323" // :End of list
 35+	rplChannelmodeis   = "324" // <channel> <modes> <mode params>
 36+	rplNotopic         = "331" // <channel> :No topic set
 37+	rplTopic           = "332" // <channel> <topic>
 38+	rplTopicwhotime    = "333" // <channel> <nick> <setat>
 39+	rplInviting        = "341" // <nick> <channel>
 40+	rplInvitelist      = "346" // <channel> <invite mask>
 41+	rplEndofinvitelist = "347" // <channel> :End of invite list
 42+	rplExceptlist      = "348" // <channel> <exception mask>
 43+	rplEndofexceptlist = "349" // <channel> :End of exception list
 44+	rplVersion         = "351" // <version> <servername> :<comments>
 45+	rplWhoreply        = "352" // <channel> <user> <host> <server> <nick> "H"/"G" ["*"] [("@"/"+")] :<hop count> <nick>
 46+	rplNamreply        = "353" // <=/*/@> <channel> :1*(@/ /+user)
 47+	rplEndofnames      = "366" // <channel> :End of names list
 48+	rplBanlist         = "367" // <channel> <ban mask>
 49+	rplEndofbanlist    = "368" // <channel> :End of ban list
 50+	rplInfo            = "371" // :<info>
 51+	rplMotd            = "372" // :- <text>
 52+	rplEndofinfo       = "374" // :End of INFO
 53+	rplMotdstart       = "375" // :- <servername> Message of the day -
 54+	rplEndofmotd       = "376" // :End of MOTD command
 55+	rplYoureoper       = "381" // :You are now an operator
 56+	rplRehashing       = "382" // <config file> :Rehashing
 57+	rplTime            = "391" // <servername> :<time in whatever format>
 58+
 59+	errNosuchnick       = "401" // <nick> :No such nick/channel
 60+	errNosuchchannel    = "403" // <channel> :No such channel
 61+	errCannotsendtochan = "404" // <channel> :Cannot send to channel
 62+	errInvalidcapcmd    = "410" // <command> :Unknown cap command
 63+	errNorecipient      = "411" // :No recipient given
 64+	errNotexttosend     = "412" // :No text to send
 65+	errInputtoolong     = "417" // :Input line was too long
 66+	errUnknowncommand   = "421" // <command> :Unknown command
 67+	errNomotd           = "422" // :MOTD file missing
 68+	errNonicknamegiven  = "431" // :No nickname given
 69+	errErroneusnickname = "432" // <nick> :Erroneous nickname
 70+	errNicknameinuse    = "433" // <nick> :Nickname in use
 71+	errUsernotinchannel = "441" // <nick> <channel> :User not in channel
 72+	errNotonchannel     = "442" // <channel> :You're not on that channel
 73+	errUseronchannel    = "443" // <user> <channel> :is already on channel
 74+	errNotregistered    = "451" // :You have not registered
 75+	errNeedmoreparams   = "461" // <command> :Not enough parameters
 76+	errAlreadyregistred = "462" // :Already registered
 77+	errPasswdmismatch   = "464" // :Password incorrect
 78+	errYourebannedcreep = "465" // :You're banned from this server
 79+	errKeyset           = "467" // <channel> :Channel key already set
 80+	errChannelisfull    = "471" // <channel> :Cannot join channel (+l)
 81+	errUnknownmode      = "472" // <char> :Don't know this mode for <channel>
 82+	errInviteonlychan   = "473" // <channel> :Cannot join channel (+I)
 83+	errBannedfromchan   = "474" // <channel> :Cannot join channel (+b)
 84+	errBadchankey       = "475" // <channel> :Cannot join channel (+k)
 85+	errNopriviledges    = "481" // :Permission Denied- You're not an IRC operator
 86+	errChanoprivsneeded = "482" // <channel> :You're not an operator
 87+
 88+	errUmodeunknownflag = "501" // :Unknown mode flag
 89+	errUsersdontmatch   = "502" // :Can't change mode for other users
 90+
 91+	rplLoggedin    = "900" // <nick> <nick>!<ident>@<host> <account> :You are now logged in as <user>
 92+	rplLoggedout   = "901" // <nick> <nick>!<ident>@<host> :You are now logged out
 93+	errNicklocked  = "902" // :You must use a nick assigned to you
 94+	rplSaslsuccess = "903" // :SASL authentication successful
 95+	errSaslfail    = "904" // :SASL authentication failed
 96+	errSasltoolong = "905" // :SASL message too long
 97+	errSaslaborted = "906" // :SASL authentication aborted
 98+	errSaslalready = "907" // :You have already authenticated using SASL
 99+	rplSaslmechs   = "908" // <mechanisms> :are available SASL mechanisms
100+)
+10, -10
 1@@ -354,7 +354,7 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) {
 2 				return
 3 			}
 4 		}
 5-	case "900":
 6+	case rplLoggedin:
 7 		err = s.send("CAP END\r\n")
 8 		if err != nil {
 9 			return
10@@ -362,7 +362,7 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) {
11 
12 		s.acct = msg.Params[2]
13 		_, _, s.host = FullMask(msg.Params[1])
14-	case "902", "904", "905", "906", "907", "908":
15+	case errNicklocked, errSaslfail, errSasltoolong, errSaslaborted, errSaslalready, rplSaslmechs:
16 		err = s.send("CAP END\r\n")
17 		if err != nil {
18 			return
19@@ -423,9 +423,9 @@ func (s *Session) handleStart(msg Message) (ev Event, err error) {
20 				}
21 			}
22 		}
23-	case "372": // RPL_MOTD
24+	case errNomotd:
25 		s.motd += "\n" + strings.TrimPrefix(msg.Params[1], "- ")
26-	case "433": // ERR_NICKNAMEINUSE
27+	case errNicknameinuse:
28 		s.nick = s.nick + "_"
29 
30 		err = s.send("NICK %s\r\n", s.nick)
31@@ -451,7 +451,7 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
32 	}
33 
34 	switch msg.Command {
35-	case "001": // RPL_WELCOME
36+	case rplWelcome:
37 		s.nick = msg.Params[0]
38 		s.lNick = strings.ToLower(s.nick)
39 		s.state = ConnRegistered
40@@ -463,9 +463,9 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
41 				return
42 			}
43 		}
44-	case "005": // RPL_ISUPPORT
45+	case rplIsupport:
46 		s.updateFeatures(msg.Params[1 : len(msg.Params)-1])
47-	case "352": // RPL_WHOREPLY
48+	case rplWhoreply:
49 		if s.lNick == strings.ToLower(msg.Params[5]) {
50 			s.host = msg.Params[3]
51 		}
52@@ -618,7 +618,7 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
53 				Time:         t,
54 			}
55 		}
56-	case "353": // RPL_NAMREPLY
57+	case rplNamreply:
58 		channel := strings.ToLower(msg.Params[2])
59 
60 		if c, ok := s.channels[channel]; ok {
61@@ -635,9 +635,9 @@ func (s *Session) handle(msg Message) (ev Event, err error) {
62 				c.Members[lNick] = name.PowerLevel
63 			}
64 		}
65-	case "366": // RPL_ENDOFNAMES
66+	case rplEndofnames:
67 		ev = SelfJoinEvent{ChannelEvent{Channel: msg.Params[1]}}
68-	case "332": // RPL_TOPIC
69+	case rplTopic:
70 		channel := strings.ToLower(msg.Params[1])
71 
72 		if c, ok := s.channels[channel]; ok {
+8, -8
 1@@ -156,19 +156,19 @@ func Tokenize(line string) (msg Message, err error) {
 2 
 3 func (msg *Message) Validate() (err error) {
 4 	switch msg.Command {
 5-	case "001":
 6+	case rplWelcome:
 7 		if len(msg.Params) < 1 {
 8 			err = errNotEnoughParams
 9 		}
10-	case "005":
11+	case rplIsupport:
12 		if len(msg.Params) < 3 {
13 			err = errNotEnoughParams
14 		}
15-	case "352":
16+	case rplWhoreply:
17 		if len(msg.Params) < 8 {
18 			err = errNotEnoughParams
19 		}
20-	case "372":
21+	case rplMotd:
22 		if len(msg.Params) < 2 {
23 			err = errNotEnoughParams
24 		}
25@@ -176,11 +176,11 @@ func (msg *Message) Validate() (err error) {
26 		if len(msg.Params) < 1 {
27 			err = errNotEnoughParams
28 		}
29-	case "900":
30+	case rplLoggedin:
31 		if len(msg.Params) < 3 {
32 			err = errNotEnoughParams
33 		}
34-	case "901":
35+	case rplLoggedout:
36 		if len(msg.Params) < 2 {
37 			err = errNotEnoughParams
38 		}
39@@ -212,11 +212,11 @@ func (msg *Message) Validate() (err error) {
40 		if msg.Prefix == "" {
41 			err = errNoPrefix
42 		}
43-	case "353":
44+	case rplNamreply:
45 		if len(msg.Params) < 4 {
46 			err = errNotEnoughParams
47 		}
48-	case "332":
49+	case rplTopic:
50 		if len(msg.Params) < 3 {
51 			err = errNotEnoughParams
52 		}