From 04f881a617ed83d5767c2cd5c30fcb08905996c0 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Sat, 8 Feb 2014 23:33:56 -0800 Subject: [PATCH] channel 'no outside messages' flag --- irc/channel.go | 22 +++++++++++++++++++--- irc/constants.go | 22 +++++++++++----------- irc/reply.go | 5 +++++ irc/types.go | 4 ++++ 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/irc/channel.go b/irc/channel.go index aff1bccf..5c771fe4 100644 --- a/irc/channel.go +++ b/irc/channel.go @@ -113,8 +113,11 @@ func (channel *Channel) String() string { } // -func (channel *Channel) ModeString() string { - return "" +func (channel *Channel) ModeString() (str string) { + if channel.noOutside { + str += NoOutside.String() + } + return } func (channel *Channel) Join(client *Client) { @@ -181,7 +184,12 @@ func (m *TopicCommand) HandleChannel(channel *Channel) { } func (m *PrivMsgCommand) HandleChannel(channel *Channel) { - channel.replies <- RplPrivMsg(m.Client(), channel, m.message) + client := m.Client() + if channel.noOutside && !channel.members.Has(client) { + client.replies <- ErrCannotSendToChan(channel) + return + } + channel.replies <- RplPrivMsg(client, channel, m.message) } func (msg *ChannelModeCommand) HandleChannel(channel *Channel) { @@ -195,6 +203,14 @@ func (msg *ChannelModeCommand) HandleChannel(channel *Channel) { client.replies <- RplBanList(channel, banMask) } client.replies <- RplEndOfBanList(channel) + case NoOutside: + // TODO perms + switch modeOp.op { + case Add: + channel.noOutside = true + case Remove: + channel.noOutside = false + } } } diff --git a/irc/constants.go b/irc/constants.go index 56c5eede..6a3aeb4d 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -171,20 +171,20 @@ const ( ServerNotice UserMode = 's' WallOps UserMode = 'w' - Anonymous ChannelMode = 'a' + Anonymous ChannelMode = 'a' // flag BanMask ChannelMode = 'b' // arg ExceptionMask ChannelMode = 'e' // arg InviteMask ChannelMode = 'I' // arg - InviteOnly ChannelMode = 'i' - Key ChannelMode = 'k' // arg - Moderated ChannelMode = 'm' - NoOutside ChannelMode = 'n' - OpOnlyTopic ChannelMode = 't' - Private ChannelMode = 'p' - Quiet ChannelMode = 'q' - ReOp ChannelMode = 'r' - Secret ChannelMode = 's' - UserLimit ChannelMode = 'l' // arg + InviteOnly ChannelMode = 'i' // flag + Key ChannelMode = 'k' // flag arg + Moderated ChannelMode = 'm' // flag + NoOutside ChannelMode = 'n' // flag + OpOnlyTopic ChannelMode = 't' // flag + Private ChannelMode = 'p' // flag + Quiet ChannelMode = 'q' // flag + ReOp ChannelMode = 'r' // flag + Secret ChannelMode = 's' // flag + UserLimit ChannelMode = 'l' // flag arg ChannelCreator UserChannelMode = 'O' ChannelOperator UserChannelMode = 'o' diff --git a/irc/reply.go b/irc/reply.go index e018cda6..cc05b08b 100644 --- a/irc/reply.go +++ b/irc/reply.go @@ -343,3 +343,8 @@ func ErrUserNotInChannel(server *Server, nick string, channel *Channel) Reply { return NewNumericReply(server, ERR_USERNOTINCHANNEL, "%s %s :They aren't on that channel", nick, channel.name) } + +func ErrCannotSendToChan(channel *Channel) Reply { + return NewNumericReply(channel.server, ERR_CANNOTSENDTOCHAN, + "%s :Cannot send to channel", channel.name) +} diff --git a/irc/types.go b/irc/types.go index 01187cac..ec974e67 100644 --- a/irc/types.go +++ b/irc/types.go @@ -20,6 +20,10 @@ type UserMode rune // channel mode flags type ChannelMode rune +func (mode ChannelMode) String() string { + return fmt.Sprintf("%c", mode) +} + // user-channel mode flags type UserChannelMode rune