]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
core_whowas Switch from map to a hash map and from irc::string to std::string
[user/henk/code/inspircd.git] / src / mode.cpp
index ef18663b9f40cbcf9d00092c2617d75065921dc2..3d2b8e5c4bb83c78ba2f774be21de0502134a2b1 100644 (file)
@@ -35,7 +35,7 @@ ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modelett
 
 CullResult ModeHandler::cull()
 {
-       if (ServerInstance->Modes)
+       if (ServerInstance)
                ServerInstance->Modes->DelMode(this);
        return classbase::cull();
 }
@@ -619,14 +619,14 @@ ModeHandler::Id ModeParser::AllocateModeId(ModeType mt)
        throw ModuleException("Out of ModeIds");
 }
 
-bool ModeParser::AddMode(ModeHandler* mh)
+void ModeParser::AddMode(ModeHandler* mh)
 {
        /* Yes, i know, this might let people declare modes like '_' or '^'.
         * If they do that, thats their problem, and if i ever EVER see an
         * official InspIRCd developer do that, i'll beat them with a paddle!
         */
        if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
-               return false;
+               throw ModuleException("Invalid letter for mode " + mh->name);
 
        /* A mode prefix of ',' is not acceptable, it would fuck up server to server.
         * A mode prefix of ':' will fuck up both server to server, and client to server.
@@ -636,15 +636,15 @@ bool ModeParser::AddMode(ModeHandler* mh)
        if (pm)
        {
                if ((pm->GetPrefix() > 126) || (pm->GetPrefix() == ',') || (pm->GetPrefix() == ':') || (pm->GetPrefix() == '#'))
-                       return false;
+                       throw ModuleException("Invalid prefix for mode " + mh->name);
 
                if (FindPrefix(pm->GetPrefix()))
-                       return false;
+                       throw ModuleException("Prefix already exists for mode " + mh->name);
        }
 
        ModeHandler*& slot = modehandlers[mh->GetModeType()][mh->GetModeChar()-65];
        if (slot)
-               return false;
+               throw ModuleException("Letter is already in use for mode " + mh->name);
 
        // The mode needs an id if it is either a user mode, a simple mode (flag) or a parameter mode.
        // Otherwise (for listmodes and prefix modes) the id remains MODEID_MAX, which is invalid.
@@ -653,7 +653,7 @@ bool ModeParser::AddMode(ModeHandler* mh)
                modeid = AllocateModeId(mh->GetModeType());
 
        if (!modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)).second)
-               return false;
+               throw ModuleException("Mode name already in use: " + mh->name);
 
        // Everything is fine, add the mode
 
@@ -671,7 +671,6 @@ bool ModeParser::AddMode(ModeHandler* mh)
                mhlist.list.push_back(mh->IsListModeBase());
 
        RecreateModeListFor004Numeric();
-       return true;
 }
 
 bool ModeParser::DelMode(ModeHandler* mh)
@@ -694,15 +693,20 @@ bool ModeParser::DelMode(ModeHandler* mh)
        switch (mh->GetModeType())
        {
                case MODETYPE_USER:
-                       for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); )
+               {
+                       const user_hash& users = ServerInstance->Users->GetUsers();
+                       for (user_hash::const_iterator i = users.begin(); i != users.end(); )
                        {
                                User* user = i->second;
                                ++i;
                                mh->RemoveMode(user);
                        }
+               }
                break;
                case MODETYPE_CHANNEL:
-                       for (chan_hash::iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); )
+               {
+                       const chan_hash& chans = ServerInstance->GetChans();
+                       for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); )
                        {
                                // The channel may not be in the hash after RemoveMode(), see m_permchannels
                                Channel* chan = i->second;
@@ -719,6 +723,7 @@ bool ModeParser::DelMode(ModeHandler* mh)
                                        stackresult.erase(stackresult.begin() + 1, stackresult.end());
                                }
                        }
+               }
                break;
        }
 
@@ -934,7 +939,6 @@ struct builtin_modes
        ModeChannelOp o;
        ModeChannelVoice v;
 
-       ModeUserWallops uw;
        ModeUserInvisible ui;
        ModeUserOperator uo;
        ModeUserServerNoticeMask us;
@@ -942,7 +946,7 @@ struct builtin_modes
        void init()
        {
                ServiceProvider* modes[] = { &s, &p, &m, &t, &n, &i, &k, &l, &b, &o, &v,
-                                                                        &uw, &ui, &uo, &us };
+                                                                        &ui, &uo, &us };
                ServerInstance->Modules->AddServices(modes, sizeof(modes)/sizeof(ServiceProvider*));
        }
 };