feat: implement some miscellaneous numeric replies and errors

This commit is contained in:
2025-08-15 21:21:21 +02:00
parent d5a99ada51
commit 0e213c691a
2 changed files with 195 additions and 12 deletions
+12 -12
View File
@@ -167,12 +167,12 @@ const (
RPL_GLOBALUSERS = "266" // aircd, Hybird, Bahamut - Implemented RPL_GLOBALUSERS = "266" // aircd, Hybird, Bahamut - Implemented
RPL_WHOISCERTFP = "276" // oftc-hybrid - Not Implemented - Has Conflicts (TODO:) RPL_WHOISCERTFP = "276" // oftc-hybrid - Not Implemented - Has Conflicts (TODO:)
RPL_NONE = "300" // RFC1459 - Not Implemented (TODO:) RPL_NONE = "300" // RFC1459 - Not Implemented (TODO:)
RPL_AWAY = "301" // RFC1459 - Not Implemented (TODO:) RPL_AWAY = "301" // RFC1459 - Implemented
RPL_USERHOST = "302" // RFC1459 - Not Implemented (TODO:) RPL_USERHOST = "302" // RFC1459 - Not Implemented (TODO:)
RPL_ISON = "303" // RFC1459 - Not Implemented (TODO:) RPL_ISON = "303" // RFC1459 - Not Implemented (TODO:)
RPL_TEXT = "304" // irc2 - Not Implemented (TODO:) RPL_TEXT = "304" // irc2 - Not Implemented (TODO:)
RPL_UNAWAY = "305" // RFC1459 - Not Implemented (TODO:) RPL_UNAWAY = "305" // RFC1459 - Implemented
RPL_NOWAWAY = "306" // RFC1459 - Not Implemented (TODO:) RPL_NOWAWAY = "306" // RFC1459 - Implemented
RPL_WHOISUSER = "311" // RFC1459 - Implemented RPL_WHOISUSER = "311" // RFC1459 - Implemented
RPL_WHOISSERVER = "312" // RFC1459 - Implemented RPL_WHOISSERVER = "312" // RFC1459 - Implemented
RPL_WHOISOPERATOR = "313" // RFC1459 - Not Implemented (TODO:) RPL_WHOISOPERATOR = "313" // RFC1459 - Not Implemented (TODO:)
@@ -197,7 +197,7 @@ const (
RPL_EXCEPTLIST = "348" // RFC2812 - Not Implemented (TODO:) RPL_EXCEPTLIST = "348" // RFC2812 - Not Implemented (TODO:)
RPL_ENDOFEXCEPTLIST = "349" // RFC2812 - Not Implemented (TODO:) RPL_ENDOFEXCEPTLIST = "349" // RFC2812 - Not Implemented (TODO:)
RPL_WHOISGATEWAY = "350" // InspIRCd - Not Implemented (TODO:) RPL_WHOISGATEWAY = "350" // InspIRCd - Not Implemented (TODO:)
RPL_VERSION = "351" // RFC1459 - Not Implemented (TODO:) RPL_VERSION = "351" // RFC1459 - Implemented
RPL_WHOREPLY = "352" // RFC1459 - Not Implemented (TODO:) RPL_WHOREPLY = "352" // RFC1459 - Not Implemented (TODO:)
RPL_NAMREPLY = "353" // RFC1459 - Implemented RPL_NAMREPLY = "353" // RFC1459 - Implemented
RPL_KILLDONE = "361" // RFC1459 - Not Implemented - Deprecated (TODO:) RPL_KILLDONE = "361" // RFC1459 - Not Implemented - Deprecated (TODO:)
@@ -209,10 +209,10 @@ const (
RPL_BANLIST = "367" // RFC1459 - Not Implemented (TODO:) RPL_BANLIST = "367" // RFC1459 - Not Implemented (TODO:)
RPL_ENDOFBANLIST = "368" // RFC1459 - Not Implemented (TODO:) RPL_ENDOFBANLIST = "368" // RFC1459 - Not Implemented (TODO:)
RPL_ENDOFWHOWAS = "369" // RFC1459 - Not Implemented (TODO:) RPL_ENDOFWHOWAS = "369" // RFC1459 - Not Implemented (TODO:)
RPL_INFO = "371" // RFC1459 - Not Implemented (TODO:) RPL_INFO = "371" // RFC1459 - Implemented
RPL_MOTD = "372" // RFC1459 - Implemented RPL_MOTD = "372" // RFC1459 - Implemented
RPL_INFOSTART = "373" // RFC1459 - Not Implemented - Deprecated (TODO:) RPL_INFOSTART = "373" // RFC1459 - Not Implemented - Deprecated (TODO:)
RPL_ENDOFINFO = "374" // RFC1459 - Not Implemented (TODO:) RPL_ENDOFINFO = "374" // RFC1459 - Implemented
RPL_MOTDSTART = "375" // RFC1459 - Implemented RPL_MOTDSTART = "375" // RFC1459 - Implemented
RPL_ENDOFMOTD = "376" // RFC1459 - Not Implemented (TODO:) RPL_ENDOFMOTD = "376" // RFC1459 - Not Implemented (TODO:)
RPL_WHOISHOST = "378" // ??????? - Implemented - Has Conflicts RPL_WHOISHOST = "378" // ??????? - Implemented - Has Conflicts
@@ -230,9 +230,9 @@ const (
ERR_UNKNOWNERROR = "400" // ??????? - Not Implemented (TODO:) ERR_UNKNOWNERROR = "400" // ??????? - Not Implemented (TODO:)
ERR_NOSUCHNICK = "401" // RFC1459 - Not Implemented (TODO:) ERR_NOSUCHNICK = "401" // RFC1459 - Not Implemented (TODO:)
ERR_NOSUCHSERVER = "402" // RFC1459 - Implemented ERR_NOSUCHSERVER = "402" // RFC1459 - Implemented
ERR_NOSUCHCHANNEL = "403" // RFC1459 - Not Implemented (TODO:) ERR_NOSUCHCHANNEL = "403" // RFC1459 - Implemented
ERR_CANNOTSENDTOCHAN = "404" // RFC1459 - Not Implemented (TODO:) ERR_CANNOTSENDTOCHAN = "404" // RFC1459 - Implemented
ERR_TOOMANYCHANNELS = "405" // RFC1459 - Not Implemented (TODO:) ERR_TOOMANYCHANNELS = "405" // RFC1459 - Implemented
ERR_WASNOSUCHNICK = "406" // RFC1459 - Not Implemented (TODO:) ERR_WASNOSUCHNICK = "406" // RFC1459 - Not Implemented (TODO:)
ERR_NOSUCHSERVICE = "408" // RFC2812 - Not Implemented - Has Conflicts (TODO:) ERR_NOSUCHSERVICE = "408" // RFC2812 - Not Implemented - Has Conflicts (TODO:)
ERR_NOORIGIN = "409" // RFC1459 - Not Implemented (TODO:) ERR_NOORIGIN = "409" // RFC1459 - Not Implemented (TODO:)
@@ -242,7 +242,7 @@ const (
ERR_WILDTOPLEVEL = "414" // RFC1459 - Not Implemented (TODO:) ERR_WILDTOPLEVEL = "414" // RFC1459 - Not Implemented (TODO:)
ERR_BADMASK = "415" // RFC2812 - Not Implemented (TODO:) ERR_BADMASK = "415" // RFC2812 - Not Implemented (TODO:)
ERR_UNKNOWNCOMMAND = "421" // RFC1459 - Implemented ERR_UNKNOWNCOMMAND = "421" // RFC1459 - Implemented
ERR_NOMOTD = "422" // RFC1459 - Not Implemented (TODO:) ERR_NOMOTD = "422" // RFC1459 - Implemented
ERR_NOADMININFO = "423" // RFC1459 - Not Implemented (TODO:) ERR_NOADMININFO = "423" // RFC1459 - Not Implemented (TODO:)
ERR_FILEERROR = "424" // RFC1459 - Not Implemented (TODO:) ERR_FILEERROR = "424" // RFC1459 - Not Implemented (TODO:)
ERR_NONICKNAMEGIVEN = "431" // RFC1459 - Implemented ERR_NONICKNAMEGIVEN = "431" // RFC1459 - Implemented
@@ -269,10 +269,10 @@ const (
ERR_INVITEONLYCHAN = "473" // RFC1459 - Not Implemented (TODO:) ERR_INVITEONLYCHAN = "473" // RFC1459 - Not Implemented (TODO:)
ERR_BANNEDFROMCHAN = "474" // RFC1459 - Not Implemented (TODO:) ERR_BANNEDFROMCHAN = "474" // RFC1459 - Not Implemented (TODO:)
ERR_BADCHANNELKEY = "475" // RFC1459 - Not Implemented (TODO:) ERR_BADCHANNELKEY = "475" // RFC1459 - Not Implemented (TODO:)
ERR_BADCHANMASK = "476" // RFC2812 - Not Implemented (TODO:) ERR_BADCHANMASK = "476" // RFC2812 - Implemented
ERR_BANLISTFULL = "478" // RFC2812 - Not Implemented (TODO:) ERR_BANLISTFULL = "478" // RFC2812 - Not Implemented (TODO:)
ERR_NOPRIVILEGES = "481" // RFC1459 - Not Implemented (TODO:) ERR_NOPRIVILEGES = "481" // RFC1459 - Not Implemented (TODO:)
ERR_CHANOPRIVSNEEDED = "482" // RFC1459 - Not Implemented (TODO:) ERR_CHANOPRIVSNEEDED = "482" // RFC1459 - Implemented
ERR_CANTKILLSERVER = "483" // RFC1459 - Not Implemented (TODO:) ERR_CANTKILLSERVER = "483" // RFC1459 - Not Implemented (TODO:)
ERR_RESTRICTED = "484" // RFC2812 - Not Implemented - Has Conflicts (TODO:) ERR_RESTRICTED = "484" // RFC2812 - Not Implemented - Has Conflicts (TODO:)
ERR_UNIQOPRIVSNEEDED = "485" // RFC2812 - Not Implemented (TODO:) ERR_UNIQOPRIVSNEEDED = "485" // RFC2812 - Not Implemented (TODO:)
+183
View File
@@ -467,6 +467,41 @@ func handleGLOBALUSERS(msg irc.Message, client *irc.Client) {
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts) client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
} }
func handleAWAY(msg irc.Message, client *irc.Client) {
nick := strings.SplitN(msg.Parameters[1], "!", 2)[0]
reason := msg.Parameters[2]
awayMsg := fmt.Sprintf("%s is away (%s)", nick, reason)
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, awayMsg, msgOpts)
}
func handleUNAWAY(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleNOWAWAY(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleWHOISUSER(msg irc.Message, client *irc.Client) { func handleWHOISUSER(msg irc.Message, client *irc.Client) {
nick := msg.Parameters[1] nick := msg.Parameters[1]
user := msg.Parameters[2] user := msg.Parameters[2]
@@ -587,6 +622,24 @@ func handleTOPIC(msg irc.Message, client *irc.Client) {
} }
} }
func handleVERSION(msg irc.Message, client *irc.Client) {
version := msg.Parameters[1]
server := msg.Parameters[2]
versionMsg := fmt.Sprintf("Server: %v | Version: %v", server, version)
if len(msg.Parameters) > 3 && msg.Parameters[3] != "" {
comments := msg.Parameters[3]
versionMsg = fmt.Sprintf("Server: %v | Version: %v | (%s)", server, version, comments)
}
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, versionMsg, msgOpts)
}
func handleNAMREPLY(msg irc.Message, client *irc.Client) { func handleNAMREPLY(msg irc.Message, client *irc.Client) {
// TODO: do i need these // TODO: do i need these
// client := msg.Parameters[0] // client := msg.Parameters[0]
@@ -617,6 +670,28 @@ func handleNAMREPLY(msg irc.Message, client *irc.Client) {
} }
} }
func handleINFO(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleENDOFINFO(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsServerMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleMOTDStart(msg irc.Message, client *irc.Client) { func handleMOTDStart(msg irc.Message, client *irc.Client) {
message := strings.Join(msg.Parameters[1:], " ") message := strings.Join(msg.Parameters[1:], " ")
@@ -672,9 +747,65 @@ func handleNOSUCHSERVER(msg irc.Message, client *irc.Client) {
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts) client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
} }
func handleNOSUCHCHANNEL(msg irc.Message, client *irc.Client) {
channel := msg.Parameters[1]
message := msg.Parameters[2]
message = fmt.Sprintf("%v: %v", channel, message)
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleCANNOTSENDTOCHAN(msg irc.Message, client *irc.Client) {
channel := msg.Parameters[1]
message := msg.Parameters[2]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
for i, c := range client.Channels {
if c.Name == channel {
client.Channels[i].AppendMsg(msg.Timestamp, message, msgOpts)
return
}
}
message = fmt.Sprintf("%v: %v", channel, message)
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleTOOMANYCHANNELS(msg irc.Message, client *irc.Client) {
channel := msg.Parameters[1]
message := msg.Parameters[2]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, fmt.Sprintf("%v: %v", channel, message), msgOpts)
}
func handleUNKNOWNCOMMAND(msg irc.Message, client *irc.Client) { func handleUNKNOWNCOMMAND(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1] + " " + msg.Parameters[2] message := msg.Parameters[1] + " " + msg.Parameters[2]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
}
func handleNOMOTD(msg irc.Message, client *irc.Client) {
message := msg.Parameters[1]
msgOpts := irc.MsgFmtOpts{ msgOpts := irc.MsgFmtOpts{
WithTimestamp: true, WithTimestamp: true,
AsServerMsg: true, AsServerMsg: true,
@@ -716,6 +847,34 @@ func handleALREADYREGISTERED(msg irc.Message, client *irc.Client) {
client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts) client.Channels[0].AppendMsg(msg.Timestamp, message, msgOpts)
} }
func handleBADCHANMASK(msg irc.Message, client *irc.Client) {
channel := msg.Parameters[1]
message := msg.Parameters[2]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
client.Channels[0].AppendMsg(msg.Timestamp, fmt.Sprintf("%v: %v", channel, message), msgOpts)
}
func handleCHANOPRIVSNEEDED(msg irc.Message, client *irc.Client) {
channel := msg.Parameters[1]
message := msg.Parameters[2]
msgOpts := irc.MsgFmtOpts{
WithTimestamp: true,
AsErrorMsg: true,
}
for i, c := range client.Channels {
if c.Name == channel {
client.Channels[i].AppendMsg(msg.Timestamp, message, msgOpts)
}
}
}
func HandleCommand(msg irc.Message, client *irc.Client) { func HandleCommand(msg irc.Message, client *irc.Client) {
// TODO: handle different commands // TODO: handle different commands
switch msg.Command { switch msg.Command {
@@ -759,6 +918,12 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
handleLOCALUSERS(msg, client) handleLOCALUSERS(msg, client)
case commands.RPL_GLOBALUSERS: case commands.RPL_GLOBALUSERS:
handleGLOBALUSERS(msg, client) handleGLOBALUSERS(msg, client)
case commands.RPL_AWAY:
handleAWAY(msg, client)
case commands.RPL_UNAWAY:
handleUNAWAY(msg, client)
case commands.RPL_NOWAWAY:
handleNOWAWAY(msg, client)
case commands.RPL_WHOISUSER: case commands.RPL_WHOISUSER:
handleWHOISUSER(msg, client) handleWHOISUSER(msg, client)
case commands.RPL_WHOISSERVER: case commands.RPL_WHOISSERVER:
@@ -773,6 +938,8 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
handleNOTOPIC(msg, client) handleNOTOPIC(msg, client)
case commands.RPL_TOPIC: case commands.RPL_TOPIC:
handleTOPIC(msg, client) handleTOPIC(msg, client)
case commands.RPL_VERSION:
handleVERSION(msg, client)
case commands.RPL_NAMREPLY: case commands.RPL_NAMREPLY:
handleNAMREPLY(msg, client) handleNAMREPLY(msg, client)
case commands.RPL_ENDOFNAMES: case commands.RPL_ENDOFNAMES:
@@ -781,6 +948,10 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
// start a timeout and update said timeout on every RPL_NAMREPLY // start a timeout and update said timeout on every RPL_NAMREPLY
// and log an error if timeout ends without receiving this command. // and log an error if timeout ends without receiving this command.
case commands.RPL_INFO:
handleINFO(msg, client)
case commands.RPL_ENDOFINFO:
handleENDOFINFO(msg, client)
case commands.RPL_MOTDSTART: case commands.RPL_MOTDSTART:
handleMOTDStart(msg, client) handleMOTDStart(msg, client)
case commands.RPL_MOTD: case commands.RPL_MOTD:
@@ -797,14 +968,26 @@ func HandleCommand(msg irc.Message, client *irc.Client) {
handleWHOISMODES(msg, client) handleWHOISMODES(msg, client)
case commands.ERR_NOSUCHSERVER: case commands.ERR_NOSUCHSERVER:
handleNOSUCHSERVER(msg, client) handleNOSUCHSERVER(msg, client)
case commands.ERR_NOSUCHCHANNEL:
handleNOSUCHCHANNEL(msg, client)
case commands.ERR_CANNOTSENDTOCHAN:
handleCANNOTSENDTOCHAN(msg, client)
case commands.ERR_TOOMANYCHANNELS:
handleTOOMANYCHANNELS(msg, client)
case commands.ERR_UNKNOWNCOMMAND: case commands.ERR_UNKNOWNCOMMAND:
handleUNKNOWNCOMMAND(msg, client) handleUNKNOWNCOMMAND(msg, client)
case commands.ERR_NOMOTD:
handleNOMOTD(msg, client)
case commands.ERR_NONICKNAMEGIVEN: case commands.ERR_NONICKNAMEGIVEN:
handleNONICKNAMEGIVEN(msg, client) handleNONICKNAMEGIVEN(msg, client)
case commands.ERR_NEEDMOREPARAMS: case commands.ERR_NEEDMOREPARAMS:
handleNEEDMOREPARAMS(msg, client) handleNEEDMOREPARAMS(msg, client)
case commands.ERR_ALREADYREGISTERED: case commands.ERR_ALREADYREGISTERED:
handleALREADYREGISTERED(msg, client) handleALREADYREGISTERED(msg, client)
case commands.ERR_BADCHANMASK:
handleBADCHANMASK(msg, client)
case commands.ERR_CHANOPRIVSNEEDED:
handleCHANOPRIVSNEEDED(msg, client)
default: default:
fullMsg := fmt.Sprintf( fullMsg := fmt.Sprintf(
"%s %s %s %s", "%s %s %s %s",