]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_delayjoin.cpp
Use !empty() instead of 'size() > 0' when checking parameter count.
[user/henk/code/inspircd.git] / src / modules / m_delayjoin.cpp
index b3165c7bec221bf221ab93f0a74387f2c6d73548..f9cd837d7a23bd66dbcf27c11dda9727838d28c3 100644 (file)
 
 
 #include "inspircd.h"
-#include <stdarg.h>
 
 class DelayJoinMode : public ModeHandler
 {
-       CUList empty;
  public:
        DelayJoinMode(Module* Parent) : ModeHandler(Parent, "delayjoin", 'D', PARAM_NONE, MODETYPE_CHANNEL)
        {
-               levelrequired = OP_VALUE;
+               ranktoset = ranktounset = OP_VALUE;
        }
 
-       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding);
+       ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string& parameter, bool adding) CXX11_OVERRIDE;
 };
 
 class ModuleDelayJoin : public Module
@@ -40,7 +38,9 @@ class ModuleDelayJoin : public Module
        DelayJoinMode djm;
  public:
        LocalIntExt unjoined;
-       ModuleDelayJoin() : djm(this), unjoined("delayjoin", this)
+       ModuleDelayJoin()
+               : djm(this)
+               , unjoined("delayjoin", ExtensionItem::EXT_MEMBERSHIP, this)
        {
        }
 
@@ -51,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;
 };
 
@@ -67,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!
                 */
-               const UserMembList* names = channel->GetUsers();
-               for (UserMembCIter n = names->begin(); n != names->end(); ++n)
-                       creator->OnText(n->first, channel, TYPE_CHANNEL, "", 0, empty);
+               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->OnUserMessage(n->first, msgtarget, msgdetails);
+               }
        }
        channel->SetMode(this, adding);
        return MODEACTION_ALLOW;
@@ -95,8 +99,8 @@ ModResult ModuleDelayJoin::OnNamesListItem(User* issuer, Membership* memb, std::
 
 static void populate(CUList& except, Membership* memb)
 {
-       const UserMembList* users = memb->chan->GetUsers();
-       for(UserMembCIter i = users->begin(); i != users->end(); i++)
+       const Channel::MemberMap& users = memb->chan->GetUsers();
+       for (Channel::MemberMap::const_iterator i = users.begin(); i != users.end(); ++i)
        {
                if (i->first == memb->user || !IS_LOCAL(i->first))
                        continue;
@@ -137,16 +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)
 {
-       /* Server origin */
-       if (!user)
+       if (target.type != MessageTarget::TYPE_CHANNEL)
                return;
 
-       if (target_type != 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))
@@ -166,7 +166,11 @@ void ModuleDelayJoin::OnText(User* user, void* dest, int target_type, const std:
 /* make the user visible if he receives any mode change */
 ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, ModeHandler* mh, const std::string& param, bool adding)
 {
-       if (!user || !channel || param.empty())
+       if (!channel || param.empty())
+               return MOD_RES_PASSTHRU;
+
+       // If not a prefix mode then we got nothing to do here
+       if (!mh->IsPrefixMode())
                return MOD_RES_PASSTHRU;
 
        User* dest;