]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_message.cpp
Don't call events provided by dying or dead modules.
[user/henk/code/inspircd.git] / src / coremods / core_message.cpp
index 8a2779a4f98820c5a5b3f1110491b591aa25f6e0..26573c8bf9262b07fb8c78ac83a087bb6766b6c4 100644 (file)
@@ -1,9 +1,12 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
+ *   Copyright (C) 2017-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013, 2017-2018 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
- *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006-2007, 2010 Craig Edwards <brain@inspircd.org>
  *
  * 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.
@@ -171,7 +174,10 @@ class CommandMessage : public Command
                // If the source isn't allowed to mass message users then reject
                // the attempt to mass-message users.
                if (!source->HasPrivPermission("users/mass-message"))
+               {
+                       source->WriteNumeric(ERR_NOPRIVILEGES, "Permission Denied - You do not have the required operator privileges");
                        return CMD_FAILURE;
+               }
 
                // Extract the server glob match from the target parameter.
                std::string servername(parameters[0], 1);
@@ -244,21 +250,21 @@ class CommandMessage : public Command
                        return CMD_FAILURE;
                }
 
-               // If the target is away then inform the user.
-               if (target->IsAway() && msgtype == MSG_PRIVMSG)
-                       source->WriteNumeric(RPL_AWAY, target->nick, target->awaymsg);
-
                // Fire the pre-message events.
                MessageTarget msgtarget(target);
                MessageDetailsImpl msgdetails(msgtype, parameters[1], parameters.GetTags());
                if (!FirePreEvents(source, msgtarget, msgdetails))
                        return CMD_FAILURE;
 
+               // If the target is away then inform the user.
+               if (target->IsAway() && msgdetails.type == MSG_PRIVMSG)
+                       source->WriteNumeric(RPL_AWAY, target->nick, target->awaymsg);
+
                LocalUser* const localtarget = IS_LOCAL(target);
                if (localtarget)
                {
                        // Send to the target if they are a local user.
-                       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, source, localtarget->nick, msgdetails.text, msgtype);
+                       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, source, localtarget->nick, msgdetails.text, msgdetails.type);
                        privmsg.AddTags(msgdetails.tags_out);
                        privmsg.SetSideEffect(true);
                        localtarget->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
@@ -405,7 +411,7 @@ class ModuleCoreMessage : public Module
                if (chan->IsModeSet(noextmsgmode) && !chan->HasUser(user))
                {
                        // The noextmsg mode is set and the user is not in the channel.
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "external messages", *noextmsgmode));
                        return MOD_RES_DENY;
                }
 
@@ -413,7 +419,7 @@ class ModuleCoreMessage : public Module
                if (no_chan_priv && chan->IsModeSet(moderatedmode))
                {
                        // The moderated mode is set and the user has no status rank.
-                       user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)");
+                       user->WriteNumeric(Numerics::CannotSendTo(chan, "messages", *moderatedmode));
                        return MOD_RES_DENY;
                }
 
@@ -421,7 +427,7 @@ class ModuleCoreMessage : public Module
                {
                        // The user is banned in the channel and restrictbannedusers is enabled.
                        if (ServerInstance->Config->RestrictBannedUsers == ServerConfig::BUT_RESTRICT_NOTIFY)
-                               user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)");
+                               user->WriteNumeric(Numerics::CannotSendTo(chan, "You cannot send messages to this channel whilst banned."));
                        return MOD_RES_DENY;
                }