X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fcoremods%2Fcore_channel%2Fcore_channel.cpp;h=bf51bd4b27f2898e6473d30c5371fc07478cfa75;hb=f2e3fd5952b23209b084bde4f464e6643c8a00ff;hp=a49f8492d7daa8140acb29bf3a813246c1335641;hpb=b3a728d93f134684593576f8eaaf2daf8df39340;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index a49f8492d..bf51bd4b2 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -22,6 +22,71 @@ #include "invite.h" #include "listmode.h" +namespace +{ +/** Hook that sends a MODE after a JOIN if the user in the JOIN has some modes prefix set. + * This happens e.g. when modules such as operprefix explicitly set prefix modes on the joining + * user, or when a member with prefix modes does a host cycle. + */ +class JoinHook : public ClientProtocol::EventHook +{ + ClientProtocol::Messages::Mode modemsg; + Modes::ChangeList modechangelist; + const User* joininguser; + + public: + /** If true, MODE changes after JOIN will be sourced from the user, rather than the server + */ + bool modefromuser; + + JoinHook(Module* mod) + : ClientProtocol::EventHook(mod, "JOIN") + { + } + + void OnEventInit(const ClientProtocol::Event& ev) CXX11_OVERRIDE + { + const ClientProtocol::Events::Join& join = static_cast(ev); + const Membership& memb = *join.GetMember(); + + modechangelist.clear(); + for (std::string::const_iterator i = memb.modes.begin(); i != memb.modes.end(); ++i) + { + PrefixMode* const pm = ServerInstance->Modes.FindPrefixMode(*i); + if (!pm) + continue; // Shouldn't happen + modechangelist.push_add(pm, memb.user->nick); + } + + if (modechangelist.empty()) + { + // Member got no modes on join + joininguser = NULL; + return; + } + + joininguser = memb.user; + + // Prepare a mode protocol event that we can append to the message list in OnPreEventSend() + modemsg.SetParams(memb.chan, NULL, modechangelist); + if (modefromuser) + modemsg.SetSource(join); + else + modemsg.SetSourceUser(ServerInstance->FakeClient); + } + + ModResult OnPreEventSend(LocalUser* user, const ClientProtocol::Event& ev, ClientProtocol::MessageList& messagelist) CXX11_OVERRIDE + { + // If joininguser is NULL then they didn't get any modes on join, skip. + // Also don't show their own modes to them, they get that in the NAMES list not via MODE. + if ((joininguser) && (user != joininguser)) + messagelist.push_back(&modemsg); + return MOD_RES_PASSTHRU; + } +}; + +} + class CoreModChannel : public Module, public CheckExemption::EventListener { Invite::APIImpl invapi; @@ -30,6 +95,8 @@ class CoreModChannel : public Module, public CheckExemption::EventListener CommandKick cmdkick; CommandNames cmdnames; CommandTopic cmdtopic; + Events::ModuleEventProvider evprov; + JoinHook joinhook; ModeChannelBan banmode; SimpleChannelModeHandler inviteonlymode; @@ -62,6 +129,8 @@ class CoreModChannel : public Module, public CheckExemption::EventListener , cmdkick(this) , cmdnames(this) , cmdtopic(this) + , evprov(this, "event/channel") + , joinhook(this) , banmode(this) , inviteonlymode(this, "inviteonly", 'i') , keymode(this) @@ -79,14 +148,6 @@ class CoreModChannel : public Module, public CheckExemption::EventListener void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* optionstag = ServerInstance->Config->ConfValue("options"); - Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan }; - if (optionstag->getBool("invitebypassmodes", true)) - ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation)); - else - { - for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++) - ServerInstance->Modules.Detach(events[i], this); - } std::string current; irc::spacesepstream defaultstream(optionstag->getString("exemptchanops")); @@ -103,13 +164,41 @@ class CoreModChannel : public Module, public CheckExemption::EventListener ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Exempting prefix %c from %s", prefix, restriction.c_str()); exempts[restriction] = prefix; } - exemptions.swap(exempts); + ConfigTag* securitytag = ServerInstance->Config->ConfValue("security"); + const std::string announceinvites = securitytag->getString("announceinvites", "dynamic"); + Invite::AnnounceState newannouncestate; + if (stdalgo::string::equalsci(announceinvites, "none")) + newannouncestate = Invite::ANNOUNCE_NONE; + else if (stdalgo::string::equalsci(announceinvites, "all")) + newannouncestate = Invite::ANNOUNCE_ALL; + else if (stdalgo::string::equalsci(announceinvites, "ops")) + newannouncestate = Invite::ANNOUNCE_OPS; + else if (stdalgo::string::equalsci(announceinvites, "dynamic")) + newannouncestate = Invite::ANNOUNCE_DYNAMIC; + else + throw ModuleException(announceinvites + " is an invalid value, at " + securitytag->getTagLocation()); + + // Config is valid, apply it + + // Validates and applies tags, so do it first + banmode.DoRehash(); + + exemptions.swap(exempts); // In 2.0 we allowed limits of 0 to be set. This is non-standard behaviour // and will be removed in the next major release. - limitmode.minlimit = optionstag->getBool("allowzerolimit", true) ? 0 : 1; + limitmode.minlimit = optionstag->getBool("allowzerolimit", true) ? 0 : 1;; + cmdinvite.announceinvites = newannouncestate; + joinhook.modefromuser = optionstag->getBool("cyclehostsfromuser"); - banmode.DoRehash(); + Implementation events[] = { I_OnCheckKey, I_OnCheckLimit, I_OnCheckChannelBan }; + if (optionstag->getBool("invitebypassmodes", true)) + ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation)); + else + { + for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++) + ServerInstance->Modules.Detach(events[i], this); + } } void On005Numeric(std::map& tokens) CXX11_OVERRIDE @@ -132,7 +221,10 @@ class CoreModChannel : public Module, public CheckExemption::EventListener if (!buffer.empty()) buffer.push_back(','); - buffer.append(iter->second); + std::string modes(iter->second); + std::sort(modes.begin(), modes.end()); + + buffer.append(modes); buffer.push_back(':'); buffer.append(ConvToStr(iter->first)); } @@ -256,6 +348,7 @@ class CoreModChannel : public Module, public CheckExemption::EventListener void Prioritize() CXX11_OVERRIDE { ServerInstance->Modules.SetPriority(this, I_OnPostJoin, PRIORITY_FIRST); + ServerInstance->Modules.SetPriority(this, I_OnUserPreJoin, PRIORITY_LAST); } Version GetVersion() CXX11_OVERRIDE