diff options
30 files changed, 326 insertions, 230 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index bdbcdb20d..b0446482d 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -88,6 +88,7 @@ struct fakederef #include "socketengine.h" #include "snomasks.h" #include "filelogger.h" +#include "message.h" #include "modules.h" #include "threadengine.h" #include "configreader.h" diff --git a/include/message.h b/include/message.h new file mode 100644 index 000000000..fb9e7619f --- /dev/null +++ b/include/message.h @@ -0,0 +1,127 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2017 Peter Powell <petpow@saberuk.com> + * + * 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 + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +/** Whether message was a PRIVMSG or a NOTICE. */ +enum MessageType +{ + /** The message is a PRIVMSG. */ + MSG_PRIVMSG, + + /** The message is a NOTICE. */ + MSG_NOTICE +}; + +class CoreExport MessageDetails +{ + public: + /* Whether to send the original message back to clients with echo-message support. */ + bool echooriginal; + + /** The users who are exempted from receiving this message. */ + CUList exemptions; + + /* The original message as sent by the user. */ + const std::string originaltext; + + /** The message which will be sent to clients. */ + std::string text; + + /** The type of message. */ + const MessageType type; + + MessageDetails(MessageType mt, const std::string& msg) + : echooriginal(false) + , originaltext(msg) + , text(msg) + , type(mt) + { + } +}; + +/** Represents the target of a message (NOTICE, PRIVMSG, etc). */ +class CoreExport MessageTarget +{ + public: + /** An enumeration of possible message target types. */ + enum TargetType + { + /** The target of the message is a user. */ + TYPE_USER, + + /** The target of the message is a channel. */ + TYPE_CHANNEL, + + /** The target of the message is a server. */ + TYPE_SERVER + }; + + private: + /** The target of the message. */ + void* dest; + + public: + /** If type is TYPE_CHANNEL and the user specified a status rank. */ + char status; + + /** The type of the target of the message. If this is TYPE_CHANNEL then dest + * is a Channel*, TYPE_USER then dest is a User*, and TYPE_SERVER then dest is + * a std::string* containing a server glob. + */ + MessageTarget::TargetType type; + + /** Initialises a new channel message target. + * @param channel The channel which is the target of the message. + * @param statuschar The lowest status rank that the message is being sent to. + */ + MessageTarget(Channel* channel, char statuschar) + : dest(channel) + , status(statuschar) + , type(TYPE_CHANNEL) + { + } + + /** Initialises a new user message target. + * @param user The user which is the target of the message. + */ + MessageTarget(User* user) + : dest(user) + , status(0) + , type(TYPE_USER) + { + } + + /** Initialises a new server message target. + * @param server The server glob which is the target of the message. + */ + MessageTarget(std::string* server) + : dest(server) + , status(0) + , type(TYPE_SERVER) + { + } + + /** Retrieves the target of this message. */ + template<typename T> + T* Get() const + { + return static_cast<T*>(dest); + } +}; diff --git a/include/modules.h b/include/modules.h index 5dee6bfb6..c6b10cad9 100644 --- a/include/modules.h +++ b/include/modules.h @@ -54,22 +54,6 @@ enum ModuleFlags VF_OPTCOMMON = 8 }; -/** Used to represent an event type, for user, channel or server - */ -enum TargetTypeFlags { - TYPE_USER = 1, - TYPE_CHANNEL, - TYPE_SERVER, - TYPE_OTHER -}; - -/** Used to represent wether a message was PRIVMSG or NOTICE - */ -enum MessageType { - MSG_PRIVMSG = 0, - MSG_NOTICE = 1 -}; - #define MOD_RES_ALLOW (ModResult(1)) #define MOD_RES_PASSTHRU (ModResult(0)) #define MOD_RES_DENY (ModResult(-1)) @@ -230,7 +214,7 @@ enum Implementation I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick, - I_OnUserMessage, I_OnMode, + I_OnUserPostMessage, I_OnMode, I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit, I_OnChangeHost, I_OnChangeName, I_OnAddLine, I_OnDelLine, I_OnExpireLine, I_OnUserPostNick, I_OnPreMode, I_On005Numeric, I_OnKill, I_OnLoadModule, @@ -241,7 +225,7 @@ enum Implementation I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete, I_OnPostOper, I_OnSetAway, I_OnPostCommand, I_OnPostJoin, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, - I_OnText, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, + I_OnUserMessage, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP, I_OnServiceAdd, I_OnServiceDel, I_END @@ -500,24 +484,16 @@ class CoreExport Module : public classbase, public usecountbase */ virtual void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts); - /** Called whenever a user is about to PRIVMSG A user or a channel, before any processing is done. - * Returning any nonzero value from this function stops the process immediately, causing no - * output to be sent to the user by the core. If you do this you must produce your own numerics, - * notices etc. This is useful for modules which may want to filter or redirect messages. - * target_type can be one of TYPE_USER or TYPE_CHANNEL. If the target_type value is a user, - * you must cast dest to a User* otherwise you must cast it to a Channel*, this is the details - * of where the message is destined to be sent. - * @param user The user sending the message - * @param dest The target of the message (Channel* or User*) - * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL) - * @param text Changeable text being sent by the user - * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone. - * @param exempt_list A list of users not to send to. For channel messages, this will usually contain just the sender. - * It will be ignored for private messages. - * @param msgtype The message type, MSG_PRIVMSG for PRIVMSGs, MSG_NOTICE for NOTICEs - * @return 1 to deny the message, 0 to allow it - */ - virtual ModResult OnUserPreMessage(User* user,void* dest,int target_type, std::string &text,char status, CUList &exempt_list, MessageType msgtype); + /** Called before a user sends a message to a channel, a user, or a server glob mask. + * @param user The user sending the message. + * @param target The target of the message. This can either be a channel, a user, or a server + * glob mask. + * @param details Details about the message such as the message text and type. See the + * MessageDetails class for more information. + * @return MOD_RES_ALLOW to explicitly allow the message, MOD_RES_DENY to explicitly deny the + * message, or MOD_RES_PASSTHRU to let another module handle the event. + */ + virtual ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details); /** Called when sending a message to all "neighbors" of a given user - * that is, all users that share a common channel. This is used in @@ -539,33 +515,23 @@ class CoreExport Module : public classbase, public usecountbase */ virtual ModResult OnUserPreNick(LocalUser* user, const std::string& newnick); - /** Called after any PRIVMSG sent from a user. - * The dest variable contains a User* if target_type is TYPE_USER and a Channel* - * if target_type is TYPE_CHANNEL. - * @param user The user sending the message - * @param dest The target of the message - * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL) - * @param text the text being sent by the user - * @param status The status being used, e.g. PRIVMSG @#chan has status== '@', 0 to send to everyone. - * @param exempt_list A list of users to not send to. - * @param msgtype The message type, MSG_PRIVMSG for PRIVMSGs, MSG_NOTICE for NOTICEs - */ - virtual void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list, MessageType msgtype); - - /** Called immediately before any NOTICE or PRIVMSG sent from a user, local or remote. - * The dest variable contains a User* if target_type is TYPE_USER and a Channel* - * if target_type is TYPE_CHANNEL. - * The difference between this event and OnUserPreMessage is that delivery is gauranteed, - * the message has already been vetted. In the case of the other two methods, a later module may stop your - * message. This also differs from OnUserMessage which occurs AFTER the message has been sent. - * @param user The user sending the message - * @param dest The target of the message - * @param target_type The type of target (TYPE_USER or TYPE_CHANNEL) - * @param text the text being sent by the user - * @param status The status being used, e.g. NOTICE @#chan has status== '@', 0 to send to everyone. - * @param exempt_list A list of users not to send to. For channel messages, this will usually contain just the sender. - */ - virtual void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list); + /** Called immediately after a user sends a message to a channel, a user, or a server glob mask. + * @param user The user sending the message. + * @param target The target of the message. This can either be a channel, a user, or a server + * glob mask. + * @param details Details about the message such as the message text and type. See the + * MessageDetails class for more information. + */ + virtual void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details); + + /** Called immediately before a user sends a message to a channel, a user, or a server glob mask. + * @param user The user sending the message. + * @param target The target of the message. This can either be a channel, a user, or a server + * glob mask. + * @param details Details about the message such as the message text and type. See the + * MessageDetails class for more information. + */ + virtual void OnUserMessage(User* user, const MessageTarget& target, const MessageDetails& details); /** Called after every MODE command sent from a user * Either the usertarget or the chantarget variable contains the target of the modes, diff --git a/src/coremods/core_privmsg.cpp b/src/coremods/core_privmsg.cpp index 89c74346e..f1461df5f 100644 --- a/src/coremods/core_privmsg.cpp +++ b/src/coremods/core_privmsg.cpp @@ -57,7 +57,7 @@ class MessageCommandBase : public Command RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters) CXX11_OVERRIDE { if (IS_LOCAL(user)) - // This is handled by the OnUserMessage hook to split the LoopCall pieces + // This is handled by the OnUserPostMessage hook to split the LoopCall pieces return ROUTE_LOCALONLY; else return ROUTE_MESSAGE(parameters[0]); @@ -79,7 +79,6 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para { User *dest; Channel *chan; - CUList except_list; LocalUser* localuser = IS_LOCAL(user); if (localuser) @@ -93,23 +92,24 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para if (!user->HasPrivPermission("users/mass-message")) return CMD_SUCCESS; + std::string servername(parameters[0], 1); + MessageTarget msgtarget(&servername); + MessageDetails msgdetails(mt, parameters[1]); + ModResult MOD_RESULT; - std::string temp = parameters[1]; - FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, (void*)parameters[0].c_str(), TYPE_SERVER, temp, 0, except_list, mt)); + FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; - const char* text = temp.c_str(); - const char* servermask = (parameters[0].c_str()) + 1; - - FOREACH_MOD(OnText, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list)); - if (InspIRCd::Match(ServerInstance->Config->ServerName, servermask, NULL)) + FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails)); + if (InspIRCd::Match(ServerInstance->Config->ServerName, servername, NULL)) { - SendAll(user, text, mt); + SendAll(user, msgdetails.text, mt); } - FOREACH_MOD(OnUserMessage, (user, (void*)parameters[0].c_str(), TYPE_SERVER, text, 0, except_list, mt)); + FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails)); return CMD_SUCCESS; } + char status = 0; const char* target = parameters[0].c_str(); @@ -122,8 +122,6 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para { chan = ServerInstance->FindChan(target); - except_list.insert(user); - if (chan) { if (localuser && chan->GetPrefixValue(user) < VOICE_VALUE) @@ -149,34 +147,35 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para } } } - ModResult MOD_RESULT; - std::string temp = parameters[1]; - FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, chan, TYPE_CHANNEL, temp, status, except_list, mt)); + MessageTarget msgtarget(chan, status); + MessageDetails msgdetails(mt, parameters[1]); + msgdetails.exemptions.insert(user); + + ModResult MOD_RESULT; + FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; - const char* text = temp.c_str(); - /* Check again, a module may have zapped the input string */ - if (temp.empty()) + if (msgdetails.text.empty()) { user->WriteNumeric(ERR_NOTEXTTOSEND, "No text to send"); return CMD_FAILURE; } - FOREACH_MOD(OnText, (user,chan,TYPE_CHANNEL,text,status,except_list)); + FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails)); if (status) { - chan->WriteAllExcept(user, false, status, except_list, "%s %c%s :%s", MessageTypeString[mt], status, chan->name.c_str(), text); + chan->WriteAllExcept(user, false, status, msgdetails.exemptions, "%s %c%s :%s", MessageTypeString[mt], status, chan->name.c_str(), msgdetails.text.c_str()); } else { - chan->WriteAllExcept(user, false, status, except_list, "%s %s :%s", MessageTypeString[mt], chan->name.c_str(), text); + chan->WriteAllExcept(user, false, status, msgdetails.exemptions, "%s %s :%s", MessageTypeString[mt], chan->name.c_str(), msgdetails.text.c_str()); } - FOREACH_MOD(OnUserMessage, (user,chan, TYPE_CHANNEL, text, status, except_list, mt)); + FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails)); } else { @@ -226,24 +225,23 @@ CmdResult MessageCommandBase::HandleMessage(const std::vector<std::string>& para user->WriteNumeric(RPL_AWAY, dest->nick, dest->awaymsg); } - ModResult MOD_RESULT; + MessageTarget msgtarget(dest); + MessageDetails msgdetails(mt, parameters[1]); - std::string temp = parameters[1]; - FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, dest, TYPE_USER, temp, 0, except_list, mt)); + ModResult MOD_RESULT; + FIRST_MOD_RESULT(OnUserPreMessage, MOD_RESULT, (user, msgtarget, msgdetails)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; - const char* text = temp.c_str(); - - FOREACH_MOD(OnText, (user, dest, TYPE_USER, text, 0, except_list)); + FOREACH_MOD(OnUserMessage, (user, msgtarget, msgdetails)); if (IS_LOCAL(dest)) { // direct write, same server - dest->WriteFrom(user, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), text); + dest->WriteFrom(user, "%s %s :%s", MessageTypeString[mt], dest->nick.c_str(), msgdetails.text.c_str()); } - FOREACH_MOD(OnUserMessage, (user, dest, TYPE_USER, text, 0, except_list, mt)); + FOREACH_MOD(OnUserPostMessage, (user, msgtarget, msgdetails)); } else { diff --git a/src/modules.cpp b/src/modules.cpp index f204f3fc1..ec793c64f 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -84,7 +84,7 @@ void Module::OnOper(User*, const std::string&) { DetachEvent(I_OnOper); } void Module::OnPostOper(User*, const std::string&, const std::string &) { DetachEvent(I_OnPostOper); } void Module::OnInfo(User*) { DetachEvent(I_OnInfo); } ModResult Module::OnUserPreInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserPreInvite); return MOD_RES_PASSTHRU; } -ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&, MessageType) { DetachEvent(I_OnUserPreMessage); return MOD_RES_PASSTHRU; } +ModResult Module::OnUserPreMessage(User*, const MessageTarget&, MessageDetails&) { DetachEvent(I_OnUserPreMessage); return MOD_RES_PASSTHRU; } ModResult Module::OnUserPreNick(LocalUser*, const std::string&) { DetachEvent(I_OnUserPreNick); return MOD_RES_PASSTHRU; } void Module::OnUserPostNick(User*, const std::string&) { DetachEvent(I_OnUserPostNick); } ModResult Module::OnPreMode(User*, User*, Channel*, Modes::ChangeList&) { DetachEvent(I_OnPreMode); return MOD_RES_PASSTHRU; } @@ -113,7 +113,7 @@ ModResult Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { Detac ModResult Module::OnPreTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPreTopicChange); return MOD_RES_PASSTHRU; } ModResult Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { DetachEvent(I_OnPassCompare); return MOD_RES_PASSTHRU; } void Module::OnPostConnect(User*) { DetachEvent(I_OnPostConnect); } -void Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { DetachEvent(I_OnUserMessage); } +void Module::OnUserPostMessage(User*, const MessageTarget&, const MessageDetails&) { DetachEvent(I_OnUserPostMessage); } void Module::OnUserInvite(User*, User*, Channel*, time_t, unsigned int, CUList&) { DetachEvent(I_OnUserInvite); } void Module::OnPostTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPostTopicChange); } void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { DetachEvent(I_OnDecodeMetaData); } @@ -130,7 +130,7 @@ ModResult Module::OnSetAway(User*, const std::string &) { DetachEvent(I_OnSetAwa void Module::OnBuildNeighborList(User*, IncludeChanList&, std::map<User*,bool>&) { DetachEvent(I_OnBuildNeighborList); } void Module::OnGarbageCollect() { DetachEvent(I_OnGarbageCollect); } ModResult Module::OnSetConnectClass(LocalUser* user, ConnectClass* myclass) { DetachEvent(I_OnSetConnectClass); return MOD_RES_PASSTHRU; } -void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { DetachEvent(I_OnText); } +void Module::OnUserMessage(User*, const MessageTarget&, const MessageDetails&) { DetachEvent(I_OnUserMessage); } ModResult Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); return MOD_RES_PASSTHRU; } ModResult Module::OnNumeric(User*, const Numeric::Numeric&) { DetachEvent(I_OnNumeric); return MOD_RES_PASSTHRU; } ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { DetachEvent(I_OnAcceptConnection); return MOD_RES_PASSTHRU; } diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 791186414..01338e8b4 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -162,9 +162,9 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; } - 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 ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG)) + if ((target.type != MessageTarget::TYPE_CHANNEL) || (details.type != MSG_PRIVMSG)) { return; } @@ -181,11 +181,11 @@ class ModuleAlias : public Module return; } - Channel *c = (Channel *)dest; + Channel *c = target.Get<Channel>(); std::string scommand; // text is like "!moo cows bite me", we want "!moo" first - irc::spacesepstream ss(text); + irc::spacesepstream ss(details.text); ss.GetToken(scommand); if (scommand.size() <= fprefix.size()) @@ -207,7 +207,7 @@ class ModuleAlias : public Module return; /* The parameters for the command in their original form, with the command stripped off */ - std::string compare(text, scommand.length() + fprefix.size()); + std::string compare(details.text, scommand.length() + fprefix.size()); while (*(compare.c_str()) == ' ') compare.erase(compare.begin()); @@ -216,7 +216,7 @@ class ModuleAlias : public Module if (i->second.ChannelCommand) { // We use substr here to remove the fantasy prefix - if (DoAlias(user, c, &(i->second), compare, text.substr(fprefix.size()))) + if (DoAlias(user, c, &(i->second), compare, details.text.substr(fprefix.size()))) return; } } @@ -343,7 +343,7 @@ class ModuleAlias : public Module { // Prioritise after spanningtree so that channel aliases show the alias before the effects. Module* linkmod = ServerInstance->Modules->Find("m_spanningtree.so"); - ServerInstance->Modules->SetPriority(this, I_OnUserMessage, PRIORITY_AFTER, linkmod); + ServerInstance->Modules->SetPriority(this, I_OnUserPostMessage, PRIORITY_AFTER, linkmod); } }; diff --git a/src/modules/m_blockcaps.cpp b/src/modules/m_blockcaps.cpp index c36eeabff..eba86f94b 100644 --- a/src/modules/m_blockcaps.cpp +++ b/src/modules/m_blockcaps.cpp @@ -44,14 +44,14 @@ public: tokens["EXTBAN"].push_back('B'); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type == TYPE_CHANNEL) + if (target.type == MessageTarget::TYPE_CHANNEL) { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); ModResult res = CheckExemption::Call(exemptionprov, user, c, "blockcaps"); if (res == MOD_RES_ALLOW) @@ -61,17 +61,17 @@ public: { // If the message is a CTCP then we skip it unless it is // an ACTION in which case we strip the prefix and suffix. - std::string::const_iterator text_begin = text.begin(); - std::string::const_iterator text_end = text.end(); - if (text[0] == '\1') + std::string::const_iterator text_begin = details.text.begin(); + std::string::const_iterator text_end = details.text.end(); + if (details.text[0] == '\1') { // If the CTCP is not an action then skip it. - if (text.compare(0, 8, "\1ACTION ", 8)) + if (details.text.compare(0, 8, "\1ACTION ", 8)) return MOD_RES_PASSTHRU; // Skip the CTCP message characters. text_begin += 8; - if (*text.rbegin() == '\1') + if (*details.text.rbegin() == '\1') text_end -= 1; } diff --git a/src/modules/m_blockcolor.cpp b/src/modules/m_blockcolor.cpp index e3135185d..43d0826dd 100644 --- a/src/modules/m_blockcolor.cpp +++ b/src/modules/m_blockcolor.cpp @@ -41,11 +41,11 @@ class ModuleBlockColor : public Module tokens["EXTBAN"].push_back('c'); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user))) + if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user))) { - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); ModResult res = CheckExemption::Call(exemptionprov, user, c, "blockcolor"); if (res == MOD_RES_ALLOW) @@ -53,7 +53,7 @@ class ModuleBlockColor : public Module if (!c->GetExtBanStatus(user, 'c').check(!c->IsModeSet(bc))) { - for (std::string::iterator i = text.begin(); i != text.end(); i++) + for (std::string::iterator i = details.text.begin(); i != details.text.end(); i++) { switch (*i) { diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 2f6199382..349c48c29 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -374,12 +374,12 @@ public: tokens["CALLERID"] = ConvToStr(myumode.GetModeChar()); } - ModResult OnUserPreMessage(User* user, void* voiddest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (!IS_LOCAL(user) || target_type != TYPE_USER) + if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_USER) return MOD_RES_PASSTHRU; - User* dest = static_cast<User*>(voiddest); + User* dest = target.Get<User>(); if (!dest->IsModeSet(myumode) || (user == dest)) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index 6394ba9d0..fce00dfc7 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -41,18 +41,18 @@ class ModuleCensor : public Module } // format of a config entry is <badword text="shit" replace="poo"> - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; bool active = false; - if (target_type == TYPE_USER) - active = ((User*)dest)->IsModeSet(cu); - else if (target_type == TYPE_CHANNEL) + if (target.type == MessageTarget::TYPE_USER) + active = target.Get<User>()->IsModeSet(cu); + else if (target.type == MessageTarget::TYPE_CHANNEL) { - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); active = c->IsModeSet(cc); ModResult res = CheckExemption::Call(exemptionprov, user, c, "censor"); @@ -63,21 +63,22 @@ class ModuleCensor : public Module if (!active) return MOD_RES_PASSTHRU; - irc::string text2 = text.c_str(); + irc::string text2 = details.text.c_str(); for (censor_t::iterator index = censors.begin(); index != censors.end(); index++) { if (text2.find(index->first) != irc::string::npos) { if (index->second.empty()) { - user->WriteNumeric(ERR_WORDFILTERED, ((target_type == TYPE_CHANNEL) ? ((Channel*)dest)->name : ((User*)dest)->nick), index->first.c_str(), "Your message contained a censored word, and was blocked"); + const std::string targname = target.type == MessageTarget::TYPE_CHANNEL ? target.Get<Channel>()->name : target.Get<User>()->nick; + user->WriteNumeric(ERR_WORDFILTERED, targname, index->first.c_str(), "Your message contained a censored word, and was blocked"); return MOD_RES_DENY; } stdalgo::string::replace_all(text2, index->first, index->second); } } - text = text2.c_str(); + details.text = text2.c_str(); return MOD_RES_PASSTHRU; } diff --git a/src/modules/m_chanfilter.cpp b/src/modules/m_chanfilter.cpp index 133c5180d..e7dc6372b 100644 --- a/src/modules/m_chanfilter.cpp +++ b/src/modules/m_chanfilter.cpp @@ -80,12 +80,12 @@ class ModuleChanFilter : public Module cf.DoRehash(); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type != TYPE_CHANNEL) + if (target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; - Channel* chan = static_cast<Channel*>(dest); + Channel* chan = target.Get<Channel>(); ModResult res = CheckExemption::Call(exemptionprov, user, chan, "filter"); if (!IS_LOCAL(user) || res == MOD_RES_ALLOW) @@ -97,7 +97,7 @@ class ModuleChanFilter : public Module { for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++) { - if (InspIRCd::Match(text, i->mask)) + if (InspIRCd::Match(details.text, i->mask)) { if (hidemask) user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (your message contained a censored word)"); diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index e8a516b94..4d74b65e0 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -121,15 +121,15 @@ class ModuleChanHistory : public Module dobots = tag->getBool("bots", true); } - void OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList&, MessageType msgtype) CXX11_OVERRIDE + void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE { - if ((target_type == TYPE_CHANNEL) && (status == 0) && (msgtype == MSG_PRIVMSG)) + if ((target.type == MessageTarget::TYPE_CHANNEL) && (target.status == 0) && (details.type == MSG_PRIVMSG)) { - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); HistoryList* list = m.ext.get(c); if (list) { - const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + text; + const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + details.text; list->lines.push_back(HistoryItem(line)); if (list->lines.size() > list->maxlen) list->lines.pop_front(); diff --git a/src/modules/m_commonchans.cpp b/src/modules/m_commonchans.cpp index 678be0c43..4cef93029 100644 --- a/src/modules/m_commonchans.cpp +++ b/src/modules/m_commonchans.cpp @@ -33,11 +33,11 @@ class ModulePrivacyMode : public Module return Version("Adds user mode +c, which if set, users must be on a common channel with you to private message you", VF_VENDOR); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type == TYPE_USER) + if (target.type == MessageTarget::TYPE_USER) { - User* t = (User*)dest; + User* t = target.Get<User>(); if (!user->IsOper() && (t->IsModeSet(pm)) && (!user->server->IsULine()) && !user->SharesChannelWith(t)) { user->WriteNumeric(ERR_CANTSENDTOUSER, t->nick, "You are not permitted to send private messages to this user (+c set)"); diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index 18ec87179..65eeeba11 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -299,27 +299,27 @@ class ModuleDCCAllow : public Module RemoveNick(user); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - if (target_type == TYPE_USER) + if (target.type == MessageTarget::TYPE_USER) { - User* u = (User*)dest; + User* u = target.Get<User>(); /* Always allow a user to dcc themselves (although... why?) */ if (user == u) return MOD_RES_PASSTHRU; - if ((text.length()) && (text[0] == '\1')) + if ((details.text.length()) && (details.text[0] == '\1')) { Expire(); // :jamie!jamie@test-D4457903BA652E0F.silverdream.org PRIVMSG eimaj :DCC SEND m_dnsbl.cpp 3232235786 52650 9676 // :jamie!jamie@test-D4457903BA652E0F.silverdream.org PRIVMSG eimaj :VERSION - if (strncmp(text.c_str(), "\1DCC ", 5) == 0) + if (strncmp(details.text.c_str(), "\1DCC ", 5) == 0) { dl = ext.get(u); if (dl && dl->size()) @@ -329,7 +329,7 @@ class ModuleDCCAllow : public Module return MOD_RES_PASSTHRU; } - std::string buf = text.substr(5); + std::string buf = details.text.substr(5); size_t s = buf.find(' '); if (s == std::string::npos) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_deaf.cpp b/src/modules/m_deaf.cpp index 7cad49d76..e58d130a5 100644 --- a/src/modules/m_deaf.cpp +++ b/src/modules/m_deaf.cpp @@ -60,14 +60,14 @@ class ModuleDeaf : public Module deaf_bypasschars_uline = tag->getString("bypasscharsuline"); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type != TYPE_CHANNEL) + if (target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; - Channel* chan = static_cast<Channel*>(dest); - bool is_bypasschar = (deaf_bypasschars.find(text[0]) != std::string::npos); - bool is_bypasschar_uline = (deaf_bypasschars_uline.find(text[0]) != std::string::npos); + Channel* chan = target.Get<Channel>(); + bool is_bypasschar = (deaf_bypasschars.find(details.text[0]) != std::string::npos); + bool is_bypasschar_uline = (deaf_bypasschars_uline.find(details.text[0]) != std::string::npos); /* * If we have no bypasschars_uline in config, and this is a bypasschar (regular) @@ -95,7 +95,7 @@ class ModuleDeaf : public Module continue; /* deliver message */ /* don't deliver message! */ - exempt_list.insert(i->first); + details.exemptions.insert(i->first); } return MOD_RES_PASSTHRU; diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index d26a56568..f9cd837d7 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -24,7 +24,6 @@ class DelayJoinMode : public ModeHandler { - CUList empty; public: DelayJoinMode(Module* Parent) : ModeHandler(Parent, "delayjoin", 'D', PARAM_NONE, MODETYPE_CHANNEL) { @@ -52,7 +51,7 @@ class ModuleDelayJoin : public Module void OnUserPart(Membership*, std::string &partmessage, CUList&) CXX11_OVERRIDE; void OnUserKick(User* source, Membership*, const std::string &reason, CUList&) CXX11_OVERRIDE; void OnBuildNeighborList(User* source, IncludeChanList& include, std::map<User*, bool>& exception) CXX11_OVERRIDE; - void OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list) CXX11_OVERRIDE; + void OnUserMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE; ModResult OnRawMode(User* user, Channel* channel, ModeHandler* mh, const std::string& param, bool adding) CXX11_OVERRIDE; }; @@ -68,9 +67,13 @@ ModeAction DelayJoinMode::OnModeChange(User* source, User* dest, Channel* channe * Make all users visible, as +D is being removed. If we don't do this, * they remain permanently invisible on this channel! */ + MessageTarget msgtarget(channel, 0); + MessageDetails msgdetails(MSG_PRIVMSG, ""); const Channel::MemberMap& users = channel->GetUsers(); for (Channel::MemberMap::const_iterator n = users.begin(); n != users.end(); ++n) - creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty); + { + creator->OnUserMessage(n->first, msgtarget, msgdetails); + } } channel->SetMode(this, adding); return MODEACTION_ALLOW; @@ -138,12 +141,12 @@ void ModuleDelayJoin::OnBuildNeighborList(User* source, IncludeChanList& include } } -void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std::string &text, char status, CUList &exempt_list) +void ModuleDelayJoin::OnUserMessage(User* user, const MessageTarget& target, const MessageDetails& details) { - if (target_type != TYPE_CHANNEL) + if (target.type != MessageTarget::TYPE_CHANNEL) return; - Channel* channel = static_cast<Channel*>(dest); + Channel* channel = target.Get<Channel>(); Membership* memb = channel->GetUser(user); if (!memb || !unjoined.set(memb, 0)) diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index 247630e65..b39fb1d0a 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -55,7 +55,7 @@ class ModuleDelayMsg : public Module Version GetVersion() CXX11_OVERRIDE; void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE; - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE; + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE; void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE; }; @@ -93,15 +93,15 @@ void ModuleDelayMsg::OnUserJoin(Membership* memb, bool sync, bool created, CULis } } -ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) +ModResult ModuleDelayMsg::OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - if ((target_type != TYPE_CHANNEL) || ((!allownotice) && (msgtype == MSG_NOTICE))) + if ((target.type != MessageTarget::TYPE_CHANNEL) || ((!allownotice) && (details.type == MSG_NOTICE))) return MOD_RES_PASSTHRU; - Channel* channel = (Channel*) dest; + Channel* channel = target.Get<Channel>(); Membership* memb = channel->GetUser(user); if (!memb) diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp index 7f5be3639..8ad692971 100644 --- a/src/modules/m_filter.cpp +++ b/src/modules/m_filter.cpp @@ -183,7 +183,7 @@ class ModuleFilter : public Module, public ServerEventListener ModuleFilter(); CullResult cull() CXX11_OVERRIDE; - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE; + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE; FilterResult* FilterMatch(User* user, const std::string &text, int flags); bool DeleteFilter(const std::string &freeform); std::pair<bool, std::string> AddFilter(const std::string &freeform, FilterAction type, const std::string &reason, long duration, const std::string &flags); @@ -322,30 +322,30 @@ void ModuleFilter::FreeFilters() filters.clear(); } -ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) +ModResult ModuleFilter::OnUserPreMessage(User* user, const MessageTarget& msgtarget, MessageDetails& details) { // Leave remote users and servers alone if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; - flags = (msgtype == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE; + flags = (details.type == MSG_PRIVMSG) ? FLAG_PRIVMSG : FLAG_NOTICE; - FilterResult* f = this->FilterMatch(user, text, flags); + FilterResult* f = this->FilterMatch(user, details.text, flags); if (f) { std::string target; - if (target_type == TYPE_USER) + if (msgtarget.type == MessageTarget::TYPE_USER) { - User* t = (User*)dest; + User* t = msgtarget.Get<User>(); // Check if the target nick is exempted, if yes, ignore this message if (exemptednicks.count(t->nick)) return MOD_RES_PASSTHRU; target = t->nick; } - else if (target_type == TYPE_CHANNEL) + else if (msgtarget.type == MessageTarget::TYPE_CHANNEL) { - Channel* t = (Channel*)dest; + Channel* t = msgtarget.Get<Channel>(); if (exemptedchans.count(t->name)) return MOD_RES_PASSTHRU; @@ -354,14 +354,14 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type if (f->action == FA_BLOCK) { ServerInstance->SNO->WriteGlobalSno('a', "FILTER: "+user->nick+" had their message filtered, target was "+target+": "+f->reason); - if (target_type == TYPE_CHANNEL) + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked and opers notified (%s)", f->reason.c_str())); else user->WriteNotice("Your message to "+target+" was blocked and opers notified: "+f->reason); } else if (f->action == FA_SILENT) { - if (target_type == TYPE_CHANNEL) + if (msgtarget.type == MessageTarget::TYPE_CHANNEL) user->WriteNumeric(ERR_CANNOTSENDTOCHAN, target, InspIRCd::Format("Message to channel blocked (%s)", f->reason.c_str())); else user->WriteNotice("Your message to "+target+" was blocked: "+f->reason); diff --git a/src/modules/m_ircv3_echomessage.cpp b/src/modules/m_ircv3_echomessage.cpp index 8773d7187..c2818700f 100644 --- a/src/modules/m_ircv3_echomessage.cpp +++ b/src/modules/m_ircv3_echomessage.cpp @@ -33,31 +33,31 @@ 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)) return; - std::string msg = MessageTypeStringSp[msgtype]; - if (target_type == TYPE_USER) + std::string msg = MessageTypeStringSp[details.type]; + if (target.type == MessageTarget::TYPE_USER) { - User* destuser = static_cast<User*>(dest); + User* destuser = target.Get<User>(); msg.append(destuser->nick); } - else if (target_type == TYPE_CHANNEL) + else if (target.type == MessageTarget::TYPE_CHANNEL) { - if (status) - msg.push_back(status); + if (target.status) + msg.push_back(target.status); - Channel* chan = static_cast<Channel*>(dest); + Channel* chan = target.Get<Channel>(); msg.append(chan->name); } else { - const char* servername = static_cast<const char*>(dest); - msg.append(servername); + const std::string* servername = target.Get<std::string>(); + msg.append(*servername); } - msg.append(" :").append(text); + msg.append(" :").append(details.echooriginal ? details.originaltext : details.text); user->WriteFrom(user, msg); } diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 9d2e0e681..36f2c923b 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -118,12 +118,12 @@ class ModuleMsgFlood : public Module { } - ModResult OnUserPreMessage(User* user, void* voiddest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type != TYPE_CHANNEL) + if (target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; - Channel* dest = static_cast<Channel*>(voiddest); + Channel* dest = target.Get<Channel>(); if ((!IS_LOCAL(user)) || !dest->IsModeSet(mf)) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_muteban.cpp b/src/modules/m_muteban.cpp index c9caf6a6a..045666f89 100644 --- a/src/modules/m_muteban.cpp +++ b/src/modules/m_muteban.cpp @@ -28,12 +28,12 @@ class ModuleQuietBan : public Module return Version("Implements extban +b m: - mute bans",VF_OPTCOMMON|VF_VENDOR); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (!IS_LOCAL(user) || target_type != TYPE_CHANNEL) + if (!IS_LOCAL(user) || target.type != MessageTarget::TYPE_CHANNEL) return MOD_RES_PASSTHRU; - Channel* chan = static_cast<Channel*>(dest); + Channel* chan = target.Get<Channel>(); if (chan->GetExtBanStatus(user, 'm') == MOD_RES_DENY && chan->GetPrefixValue(user) < VOICE_VALUE) { user->WriteNumeric(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're muted)"); diff --git a/src/modules/m_noctcp.cpp b/src/modules/m_noctcp.cpp index e9733cf54..26077759a 100644 --- a/src/modules/m_noctcp.cpp +++ b/src/modules/m_noctcp.cpp @@ -39,12 +39,12 @@ class ModuleNoCTCP : public Module return Version("Provides channel mode +C to block CTCPs", VF_VENDOR); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user))) + if ((target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user))) { - Channel* c = (Channel*)dest; - if ((text.empty()) || (text[0] != '\001') || (!strncmp(text.c_str(),"\1ACTION ", 8)) || (text == "\1ACTION\1") || (text == "\1ACTION")) + Channel* c = target.Get<Channel>(); + if ((details.text.empty()) || (details.text[0] != '\001') || (!strncmp(details.text.c_str(),"\1ACTION ", 8)) || (details.text == "\1ACTION\1") || (details.text == "\1ACTION")) return MOD_RES_PASSTHRU; ModResult res = CheckExemption::Call(exemptionprov, user, c, "noctcp"); diff --git a/src/modules/m_nonotice.cpp b/src/modules/m_nonotice.cpp index d7ea32d2f..77b0c9aa3 100644 --- a/src/modules/m_nonotice.cpp +++ b/src/modules/m_nonotice.cpp @@ -39,12 +39,12 @@ class ModuleNoNotice : public Module tokens["EXTBAN"].push_back('T'); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { ModResult res; - if ((msgtype == MSG_NOTICE) && (target_type == TYPE_CHANNEL) && (IS_LOCAL(user))) + if ((details.type == MSG_NOTICE) && (target.type == MessageTarget::TYPE_CHANNEL) && (IS_LOCAL(user))) { - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet(nt))) { res = CheckExemption::Call(exemptionprov, user, c, "nonotice"); diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp index 75105ca0d..a57e96740 100644 --- a/src/modules/m_repeat.cpp +++ b/src/modules/m_repeat.cpp @@ -355,12 +355,12 @@ class RepeatModule : public Module rm.ReadConfig(); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type != TYPE_CHANNEL || !IS_LOCAL(user)) + if (target.type != MessageTarget::TYPE_CHANNEL || !IS_LOCAL(user)) return MOD_RES_PASSTHRU; - Channel* chan = reinterpret_cast<Channel*>(dest); + Channel* chan = target.Get<Channel>(); ChannelSettings* settings = rm.ext.get(chan); if (!settings) return MOD_RES_PASSTHRU; @@ -373,7 +373,7 @@ class RepeatModule : public Module if (res == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; - if (rm.MatchLine(memb, settings, text)) + if (rm.MatchLine(memb, settings, details.text)) { if (settings->Action == ChannelSettings::ACT_BLOCK) { diff --git a/src/modules/m_restrictmsg.cpp b/src/modules/m_restrictmsg.cpp index 8ca531ed5..16a9bae86 100644 --- a/src/modules/m_restrictmsg.cpp +++ b/src/modules/m_restrictmsg.cpp @@ -24,11 +24,11 @@ class ModuleRestrictMsg : public Module { public: - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if ((target_type == TYPE_USER) && (IS_LOCAL(user))) + if ((target.type == MessageTarget::TYPE_USER) && (IS_LOCAL(user))) { - User* u = (User*)dest; + User* u = target.Get<User>(); // message allowed if: // (1) the sender is opered diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 05cc2b416..6b5f5dacd 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -188,7 +188,7 @@ class ModuleServicesAccount : public Module, public Whois::EventListener m5.RemoveMode(user); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; @@ -196,9 +196,9 @@ class ModuleServicesAccount : public Module, public Whois::EventListener std::string *account = accountname.get(user); bool is_registered = account && !account->empty(); - if (target_type == TYPE_CHANNEL) + if (target.type == MessageTarget::TYPE_CHANNEL) { - Channel* c = (Channel*)dest; + Channel* c = target.Get<Channel>(); ModResult res = CheckExemption::Call(exemptionprov, user, c, "regmoderated"); if (c->IsModeSet(m2) && !is_registered && res != MOD_RES_ALLOW) @@ -208,9 +208,9 @@ class ModuleServicesAccount : public Module, public Whois::EventListener return MOD_RES_DENY; } } - else if (target_type == TYPE_USER) + else if (target.type == MessageTarget::TYPE_USER) { - User* u = (User*)dest; + User* u = target.Get<User>(); if (u->IsModeSet(m3) && !is_registered) { diff --git a/src/modules/m_silence.cpp b/src/modules/m_silence.cpp index edcc77468..0aa957e1d 100644 --- a/src/modules/m_silence.cpp +++ b/src/modules/m_silence.cpp @@ -332,16 +332,16 @@ class ModuleSilence : public Module } } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { - if (target_type == TYPE_USER && IS_LOCAL(((User*)dest))) + if (target.type == MessageTarget::TYPE_USER && IS_LOCAL(target.Get<User>())) { - return MatchPattern((User*)dest, user, ((msgtype == MSG_PRIVMSG) ? SILENCE_PRIVATE : SILENCE_NOTICE)); + return MatchPattern(target.Get<User>(), user, ((details.type == MSG_PRIVMSG) ? SILENCE_PRIVATE : SILENCE_NOTICE)); } - else if (target_type == TYPE_CHANNEL) + else if (target.type == MessageTarget::TYPE_CHANNEL) { - Channel* chan = (Channel*)dest; - BuildExemptList(msgtype, chan, user, exempt_list); + Channel* chan = target.Get<Channel>(); + BuildExemptList(details.type, chan, user, details.exemptions); } return MOD_RES_PASSTHRU; } diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index c244629c1..1a77237bd 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -386,33 +386,33 @@ void ModuleSpanningTree::OnPostTopicChange(User* user, Channel* chan, const std: CommandFTopic::Builder(user, chan).Broadcast(); } -void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string& text, char status, const CUList& exempt_list, MessageType msgtype) +void ModuleSpanningTree::OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) { if (!IS_LOCAL(user)) return; - const char* message_type = (msgtype == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE"); - if (target_type == TYPE_USER) + const char* message_type = (details.type == MSG_PRIVMSG ? "PRIVMSG" : "NOTICE"); + if (target.type == MessageTarget::TYPE_USER) { - User* d = (User*) dest; + User* d = target.Get<User>(); if (!IS_LOCAL(d)) { CmdBuilder params(user, message_type); params.push_back(d->uuid); - params.push_last(text); + params.push_last(details.text); params.Unicast(d); } } - else if (target_type == TYPE_CHANNEL) + else if (target.type == MessageTarget::TYPE_CHANNEL) { - Utils->SendChannelMessage(user->uuid, (Channel*)dest, text, status, exempt_list, message_type); + Utils->SendChannelMessage(user->uuid, target.Get<Channel>(), details.text, target.status, details.exemptions, message_type); } - else if (target_type == TYPE_SERVER) + else if (target.type == MessageTarget::TYPE_SERVER) { - char* target = (char*) dest; + const std::string* serverglob = target.Get<std::string>(); CmdBuilder par(user, message_type); - par.push_back(target); - par.push_last(text); + par.push_back(*serverglob); + par.push_last(details.text); par.Broadcast(); } } diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h index 13bab4cff..4eefb01a0 100644 --- a/src/modules/m_spanningtree/main.h +++ b/src/modules/m_spanningtree/main.h @@ -147,7 +147,7 @@ class ModuleSpanningTree : public Module void OnUserInvite(User* source, User* dest, Channel* channel, time_t timeout, unsigned int notifyrank, CUList& notifyexcepts) CXX11_OVERRIDE; ModResult OnPreTopicChange(User* user, Channel* chan, const std::string& topic) CXX11_OVERRIDE; void OnPostTopicChange(User* user, Channel* chan, const std::string &topic) CXX11_OVERRIDE; - 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; void OnBackgroundTimer(time_t curtime) CXX11_OVERRIDE; void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE; void OnChangeHost(User* user, const std::string &newhost) CXX11_OVERRIDE; diff --git a/src/modules/m_stripcolor.cpp b/src/modules/m_stripcolor.cpp index 8068d8b7e..3699fc3aa 100644 --- a/src/modules/m_stripcolor.cpp +++ b/src/modules/m_stripcolor.cpp @@ -41,20 +41,20 @@ class ModuleStripColor : public Module tokens["EXTBAN"].push_back('S'); } - ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE + ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE { if (!IS_LOCAL(user)) return MOD_RES_PASSTHRU; bool active = false; - if (target_type == TYPE_USER) + if (target.type == MessageTarget::TYPE_USER) { - User* t = (User*)dest; + User* t = target.Get<User>(); active = t->IsModeSet(usc); } - else if (target_type == TYPE_CHANNEL) + else if (target.type == MessageTarget::TYPE_CHANNEL) { - Channel* t = (Channel*)dest; + Channel* t = target.Get<Channel>(); ModResult res = CheckExemption::Call(exemptionprov, user, t, "stripcolor"); if (res == MOD_RES_ALLOW) @@ -65,7 +65,7 @@ class ModuleStripColor : public Module if (active) { - InspIRCd::StripColor(text); + InspIRCd::StripColor(details.text); } return MOD_RES_PASSTHRU; |