X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_ircv3_ctctags.cpp;h=5b53d668e38b93c8d493a6b5c4a901beeca3385f;hb=9982ec4e5b027ed24b1fda5e6fd3ab35b98de1a7;hp=8684642c675c0fd08583b276ed4954a6ab06a9cd;hpb=c495b5d9cf8bed4f07c0b77a1f9e98dcc1f62068;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_ircv3_ctctags.cpp b/src/modules/m_ircv3_ctctags.cpp index 8684642c6..5b53d668e 100644 --- a/src/modules/m_ircv3_ctctags.cpp +++ b/src/modules/m_ircv3_ctctags.cpp @@ -26,8 +26,6 @@ class CommandTagMsg : public Command { private: Cap::Capability& cap; - ChanModeReference moderatedmode; - ChanModeReference noextmsgmode; Events::ModuleEventProvider tagevprov; ClientProtocol::EventProvider msgevprov; @@ -70,32 +68,6 @@ class CommandTagMsg : 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)"); - 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); CTCTags::TagMessageDetails msgdetails(parameters.GetTags()); @@ -103,7 +75,8 @@ class CommandTagMsg : public Command return CMD_FAILURE; unsigned int minrank = pm ? pm->GetPrefixRank() : 0; - CTCTags::TagMessage message(source, chan, parameters.GetTags()); + CTCTags::TagMessage message(source, chan, msgdetails.tags_out); + message.SetSideEffect(true); const Channel::MemberMap& userlist = chan->GetUsers(); for (Channel::MemberMap::const_iterator iter = userlist.begin(); iter != userlist.end(); ++iter) { @@ -144,7 +117,8 @@ class CommandTagMsg : public Command // the message out to the local users. if (InspIRCd::Match(ServerInstance->Config->ServerName, servername)) { - CTCTags::TagMessage message(source, "$*", parameters.GetTags()); + CTCTags::TagMessage message(source, "$*", msgdetails.tags_out); + message.SetSideEffect(true); const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers(); for (UserManager::LocalList::const_iterator iter = list.begin(); iter != list.end(); ++iter) { @@ -211,7 +185,8 @@ class CommandTagMsg : public Command if (localtarget && cap.get(localtarget)) { // Send to the target if they have the capability and are a local user. - CTCTags::TagMessage message(source, localtarget, parameters.GetTags()); + CTCTags::TagMessage message(source, localtarget, msgdetails.tags_out); + message.SetSideEffect(true); localtarget->Send(msgevprov, message); } @@ -223,8 +198,6 @@ class CommandTagMsg : public Command CommandTagMsg(Module* Creator, Cap::Capability& Cap) : Command(Creator, "TAGMSG", 1) , cap(Cap) - , moderatedmode(Creator, "moderated") - , noextmsgmode(Creator, "noextmsg") , tagevprov(Creator, "event/tagmsg") , msgevprov(Creator, "TAGMSG") { @@ -260,7 +233,11 @@ class CommandTagMsg : public Command RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE { - return ROUTE_MESSAGE(parameters[0]); + if (IS_LOCAL(user)) + // This is handled by the OnUserPostTagMessage hook to split the LoopCall pieces + return ROUTE_LOCALONLY; + else + return ROUTE_MESSAGE(parameters[0]); } }; @@ -280,7 +257,7 @@ class C2CTags : public ClientProtocol::MessageTagProvider { // A client-only tag is prefixed with a plus sign (+) and otherwise conforms // to the format specified in IRCv3.2 tags. - if (tagname[0] != '+') + if (tagname[0] != '+' || tagname.length() < 2) return MOD_RES_PASSTHRU; // If the user is local then we check whether they have the message-tags cap @@ -307,6 +284,8 @@ class ModuleIRCv3CTCTags Cap::Capability cap; CommandTagMsg cmd; C2CTags c2ctags; + ChanModeReference moderatedmode; + ChanModeReference noextmsgmode; ModResult CopyClientTags(const ClientProtocol::TagMap& tags_in, ClientProtocol::TagMap& tags_out) { @@ -325,6 +304,8 @@ class ModuleIRCv3CTCTags , cap(this, "message-tags") , cmd(this, cap) , c2ctags(this, cap) + , moderatedmode(this, "moderated") + , noextmsgmode(this, "noextmsg") { } @@ -335,12 +316,39 @@ class ModuleIRCv3CTCTags ModResult OnUserPreTagMessage(User* user, const MessageTarget& target, CTCTags::TagMessageDetails& details) CXX11_OVERRIDE { + if (IS_LOCAL(user) && target.type == MessageTarget::TYPE_CHANNEL) + { + 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(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (no external messages)"); + 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(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (+m is set)"); + 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(ERR_CANNOTSENDTOCHAN, chan->name, "Cannot send to channel (you're banned)"); + return MOD_RES_DENY; + } + } + return CopyClientTags(details.tags_in, details.tags_out); } Version GetVersion() CXX11_OVERRIDE { - return Version("Provides the DRAFT message-tags IRCv3 extension", VF_VENDOR | VF_COMMON); + return Version("Provides the message-tags IRCv3 extension", VF_VENDOR | VF_COMMON); } };