Check if the user is allowed to send to a channel

This commit is contained in:
Les De Ridder 2017-05-24 00:06:11 +02:00
parent f7edfa9e8f
commit fd8a9aafe7
No known key found for this signature in database
GPG Key ID: 5EC132DFA85DB372
2 changed files with 24 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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);