From fd8a9aafe78ea4eb2aeae9376336085e5214753e Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Wed, 24 May 2017 00:06:11 +0200 Subject: [PATCH] Check if the user is allowed to send to a channel --- source/ircd/channel.d | 18 ++++++++++++++++++ source/ircd/connection.d | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/ircd/channel.d b/source/ircd/channel.d index 929cabc..a569ca5 100644 --- a/source/ircd/channel.d +++ b/source/ircd/channel.d @@ -324,4 +324,22 @@ class Channel { return members.canFind(connection) || !modes.canFind('s') && !modes.canFind('p'); } + + bool canReceiveMessagesFromUser(Connection connection) + { + if(modes.canFind('n') && !members.canFind(connection)) + { + return false; + } + else if(modes.canFind('m') && nickPrefix(connection).empty) + { + return false; + } + else if(maskLists['b'].any!(m => connection.matchesMask(m)) && !maskLists['e'].any!(m => connection.matchesMask(m))) + { + return false; + } + + return true; + } } diff --git a/source/ircd/connection.d b/source/ircd/connection.d index 9b6cfc1..993de93 100644 --- a/source/ircd/connection.d +++ b/source/ircd/connection.d @@ -397,10 +397,15 @@ class Connection if(Server.isValidChannelName(target)) { - if(!_server.canFindChannelByName(target)) + auto channelRange = _server.findChannelByName(target); + if(channelRange.empty) { sendErrNoSuchNick(target); } + else if(!channelRange[0].canReceiveMessagesFromUser(this)) + { + send(Message(_server.name, "404", [nick, target, "Cannot send to channel"], true)); + } else { _server.privmsgToChannel(this, target, text);