]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ircv3_echomessage.cpp
Expand searching in m_httpd_stats, add global handling of GET parameters (#1566)
[user/henk/code/inspircd.git] / src / modules / m_ircv3_echomessage.cpp
index 8773d718744603b7238e5c36fe460958456cf50a..b407aece4a1af3a4c29519f1424f204b8af0f7bd 100644 (file)
@@ -21,8 +21,6 @@
 #include "inspircd.h"
 #include "modules/cap.h"
 
-static const char* MessageTypeStringSp[] = { "PRIVMSG ", "NOTICE " };
-
 class ModuleIRCv3EchoMessage : public Module
 {
        Cap::Capability cap;
@@ -33,37 +31,49 @@ class ModuleIRCv3EchoMessage : public Module
        {
        }
 
-       void OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE
+       void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
        {
-               if (!cap.get(user))
+               if (!cap.get(user) || !details.echo)
                        return;
 
-               std::string msg = MessageTypeStringSp[msgtype];
-               if (target_type == TYPE_USER)
+               // Caps are only set on local users
+               LocalUser* const localuser = static_cast<LocalUser*>(user);
+
+               const std::string& text = details.echo_original ? details.original_text : details.text;
+               const ClientProtocol::TagMap& tags = details.echo_original ? details.tags_in : details.tags_out;
+               if (target.type == MessageTarget::TYPE_USER)
                {
-                       User* destuser = static_cast<User*>(dest);
-                       msg.append(destuser->nick);
+                       User* destuser = target.Get<User>();
+                       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type);
+                       privmsg.AddTags(tags);
+                       localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
                }
-               else if (target_type == TYPE_CHANNEL)
+               else if (target.type == MessageTarget::TYPE_CHANNEL)
                {
-                       if (status)
-                               msg.push_back(status);
-
-                       Channel* chan = static_cast<Channel*>(dest);
-                       msg.append(chan->name);
+                       Channel* chan = target.Get<Channel>();
+                       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status);
+                       privmsg.AddTags(tags);
+                       localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
                }
                else
                {
-                       const char* servername = static_cast<const char*>(dest);
-                       msg.append(servername);
+                       const std::string* servername = target.Get<std::string>();
+                       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type);
+                       privmsg.AddTags(tags);
+                       localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
                }
-               msg.append(" :").append(text);
-               user->WriteFrom(user, msg);
+       }
+
+       void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE
+       {
+               // Prevent spammers from knowing that their spam was blocked.
+               if (details.echo_original)
+                       OnUserPostMessage(user, target, details);
        }
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides the echo-message IRCv3.2 extension", VF_VENDOR);
+               return Version("Provides the echo-message IRCv3 extension", VF_VENDOR);
        }
 };