From 0046025d60f82d04e44ad1b94bfd1316ab6f310d Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Tue, 28 Mar 2017 17:32:03 +1000 Subject: [PATCH] Enable chanmode +r, fix bug with registering channels --- irc/channel.go | 3 +++ irc/chanserv.go | 2 +- irc/help.go | 22 +++++++++------------- irc/modes.go | 3 ++- irc/server.go | 12 ++++++++++++ 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index 54b57a12..53446a84 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -425,6 +425,9 @@ func (channel *Channel) CanSpeak(client *Client) bool { if channel.flags[Moderated] && !channel.clientIsAtLeastNoMutex(client, Voice) { return false } + if channel.flags[RegisteredOnly] && client.account == &NoAccount { + return false + } return true } diff --git a/irc/chanserv.go b/irc/chanserv.go index 9153cde5..ee3d05c4 100644 --- a/irc/chanserv.go +++ b/irc/chanserv.go @@ -83,7 +83,7 @@ func (server *Server) chanservReceivePrivmsg(client *Client, message string) { } account := client.account - if account == nil { + if account == &NoAccount { client.ChanServNotice("You must be logged in to register a channel") return nil } diff --git a/irc/help.go b/irc/help.go index 9c5e37c4..d094e616 100644 --- a/irc/help.go +++ b/irc/help.go @@ -21,25 +21,18 @@ var ( Oragono supports the following channel modes: -= Type A - list modes = - - +b | Client masks that are banned from the channel. + +b | Client masks that are banned from the channel (e.g. *!*@127.0.0.1) +e | Client masks that are exempted from bans. +I | Client masks that are exempted from the invite-only flag. - -= Type C - setting modes with a parameter = - - +l | Client join limit for the channel. - +k | Key required when joining the channel. - -= Type D - flag modes = - +i | Invite-only mode, only invited clients can join the channel. + +k | Key required when joining the channel. + +l | Client join limit for the channel. +m | Moderated mode, only privileged clients can talk on the channel. +n | No-outside-messages mode, only users that are on the channel can send | messages to it. - +t | Only channel opers can modify the topic. + +r | Only registered users can talk in the channel. +s | Secret mode, channel won't show up in /LIST or whois replies. + +t | Only channel opers can modify the topic. = Prefixes = @@ -210,7 +203,7 @@ command is processed by that server.`, text: `MODE [ [...]] Sets and removes modes from the given target. For more specific information on -mode characters, see the help for "cmode" and "umode".`, +mode characters, see the help for "modes".`, }, "monitor": { text: `MONITOR @@ -417,6 +410,9 @@ Returns historical information on the last user with the given nickname.`, }, // Informational + "modes": { + text: cmodeHelpText + "\n\n" + umodeHelpText, + }, "cmode": { text: cmodeHelpText, }, diff --git a/irc/modes.go b/irc/modes.go index aa39ace0..93030a7e 100644 --- a/irc/modes.go +++ b/irc/modes.go @@ -122,6 +122,7 @@ const ( Moderated Mode = 'm' // flag NoOutside Mode = 'n' // flag OpOnlyTopic Mode = 't' // flag + RegisteredOnly Mode = 'r' // flag Secret Mode = 's' // flag UserLimit Mode = 'l' // flag arg ) @@ -455,7 +456,7 @@ func ApplyChannelModeChanges(channel *Channel, client *Client, isSamode bool, ch } applied = append(applied, change) - case InviteOnly, Moderated, NoOutside, OpOnlyTopic, Secret, ChanRoleplaying: + case InviteOnly, Moderated, NoOutside, OpOnlyTopic, RegisteredOnly, Secret, ChanRoleplaying: switch change.op { case Add: if channel.flags[change.mode] { diff --git a/irc/server.go b/irc/server.go index 9442e4c3..f7f52980 100644 --- a/irc/server.go +++ b/irc/server.go @@ -952,6 +952,10 @@ func privmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, targetString, "No such channel") continue } + if !channel.CanSpeak(client) { + client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel") + continue + } msgid := server.generateMessageID() channel.SplitPrivMsg(msgid, lowestPrefix, clientOnlyTags, client, splitMsg) } else { @@ -1017,6 +1021,10 @@ func tagmsgHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { client.Send(nil, server.name, ERR_NOSUCHCHANNEL, client.nick, targetString, "No such channel") continue } + if !channel.CanSpeak(client) { + client.Send(nil, client.server.name, ERR_CANNOTSENDTOCHAN, channel.name, "Cannot send to channel") + continue + } msgid := server.generateMessageID() channel.TagMsg(msgid, lowestPrefix, clientOnlyTags, client) @@ -1610,6 +1618,10 @@ func noticeHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool { // errors silently ignored with NOTICE as per RFC continue } + if !channel.CanSpeak(client) { + // errors silently ignored with NOTICE as per RFC + continue + } msgid := server.generateMessageID() channel.SplitNotice(msgid, lowestPrefix, clientOnlyTags, client, splitMsg) } else {