X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_message.cpp;h=b4404995df2de07a48ac4c98850e7a73da544c71;hb=0e7e1ea3935e48a5093be4ccf2371a344f30bba0;hp=a17157bade316116ef49376477f022f9f4b16f9f;hpb=87b1461e2a4710a38b32186c2582da9fe9bb3804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_message.cpp b/src/coremods/core_message.cpp index a17157bad..b4404995d 100644 --- a/src/coremods/core_message.cpp +++ b/src/coremods/core_message.cpp @@ -1,9 +1,12 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2017-2019 Sadie Powell + * Copyright (C) 2013, 2017-2018 Attila Molnar + * Copyright (C) 2012, 2019 Robby * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2007-2008 Craig Edwards - * Copyright (C) 2007 Robin Burchell + * Copyright (C) 2007 Dennis Friis + * Copyright (C) 2006-2007, 2010 Craig Edwards * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -125,7 +128,7 @@ namespace { // If the source is local and was not sending a CTCP reply then update their idle time. LocalUser* lsource = IS_LOCAL(source); - if (lsource && (msgdetails.type != MSG_NOTICE || !msgdetails.IsCTCP())) + if (lsource && msgdetails.update_idle && (msgdetails.type != MSG_NOTICE || !msgdetails.IsCTCP())) lsource->idle_lastmsg = ServerInstance->Time(); // Inform modules that a message was sent. @@ -138,8 +141,6 @@ class CommandMessage : public Command { private: const MessageType msgtype; - ChanModeReference moderatedmode; - ChanModeReference noextmsgmode; CmdResult HandleChannelTarget(User* source, const Params& parameters, const char* target, PrefixMode* pm) { @@ -151,32 +152,6 @@ class CommandMessage : public Command return CMD_FAILURE; } - if (IS_LOCAL(source)) - { - if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(source)) - { - // The noextmsg mode is set and the source is not in the channel. - source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)"); - return CMD_FAILURE; - } - - bool no_chan_priv = chan->GetPrefixValue(source) < VOICE_VALUE; - if (no_chan_priv && chan->IsModeSet(moderatedmode)) - { - // The moderated mode is set and the source has no status rank. - source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)"); - return CMD_FAILURE; - } - - if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(source)) - { - // The source is banned in the channel and restrictbannedusers is enabled. - if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY) - source->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)"); - return CMD_FAILURE; - } - } - // Fire the pre-message events. MessageTarget msgtarget(chan, pm ? pm->GetPrefix() : 0); MessageDetailsImpl msgdetails(msgtype, parameters[1], parameters.GetTags()); @@ -300,8 +275,6 @@ class CommandMessage : public Command CommandMessage(Module* parent, MessageType mt) : Command(parent, ClientProtocol::Messages::Privmsg::CommandStrFromMsgType(mt), 2, 2) , msgtype(mt) - , moderatedmode(parent, "moderated") - , noextmsgmode(parent, "noextmsg") { syntax = "[,]+ :"; } @@ -413,13 +386,49 @@ class ModuleCoreMessage : public Module CommandMessage cmdprivmsg; CommandMessage cmdnotice; CommandSQuery cmdsquery; + ChanModeReference moderatedmode; + ChanModeReference noextmsgmode; public: ModuleCoreMessage() : cmdprivmsg(this, MSG_PRIVMSG) , cmdnotice(this, MSG_NOTICE) , cmdsquery(this) + , moderatedmode(this, "moderated") + , noextmsgmode(this, "noextmsg") + { + } + + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { + if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_CHANNEL) + return MOD_RES_PASSTHRU; + + Channel* chan = target.Get(); + if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user)) + { + // The noextmsg mode is set and the user is not in the channel. + user->WriteNumeric(Numerics::CannotSendTo(chan, "external messages", *noextmsgmode)); + return MOD_RES_DENY; + } + + bool no_chan_priv = chan->GetPrefixValue(user) < VOICE_VALUE; + if (no_chan_priv && chan->IsModeSet(moderatedmode)) + { + // The moderated mode is set and the user has no status rank. + user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", *moderatedmode)); + return MOD_RES_DENY; + } + + if (no_chan_priv && ServerInstance->Config->RestrictBannedUsers != ServerConfig::BUT_NORMAL && chan->IsBanned(user)) + { + // The user is banned in the channel and restrictbannedusers is enabled. + if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY) + user->WriteNumeric(Numerics::CannotSendTo(chan, "You cannot send messages to this channel whilst banned.")); + return MOD_RES_DENY; + } + + return MOD_RES_PASSTHRU; } Version GetVersion() CXX11_OVERRIDE