]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
ModeHandler documented
[user/henk/code/inspircd.git] / src / mode.cpp
index 9607a1b4c95c13f3143cece8cae5f01a22e0785c..74eb2790b219294344d7e27562a78a4ca8c36b07 100644 (file)
@@ -50,6 +50,12 @@ using namespace std;
 #include "modes/cmode_b.h"
 /* +m (moderated) */
 #include "modes/cmode_m.h"
+/* +t (only (half) ops can change topic) */
+#include "modes/cmode_t.h"
+/* +n (no external messages) */
+#include "modes/cmode_n.h"
+/* +i (invite only) */
+#include "modes/cmode_i.h"
 
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
@@ -423,12 +429,14 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server
                int handler_id = 0;
                int parameter_counter = 2; /* Index of first parameter */
 
-               for (std::string::const_iterator modeletter = mode_sequence.begin(); modeletter != mode_sequence.end(); modeletter++)
+               for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
                {
-                       switch (*modeletter)
+                       unsigned char modechar = *letter;
+
+                       switch (modechar)
                        {
 
-                               log(DEBUG,"Iterate mode letter %c",*modeletter);
+                               log(DEBUG,"Iterate mode letter %c",modechar);
 
                                /* NB:
                                 * For + and - mode characters, we don't just stick the character into the output sequence.
@@ -463,13 +471,13 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server
                                         * a user mode. This is a little stranger, but a lot
                                         * faster, than using a map of pairs.
                                         */
-                                       handler_id = (*modeletter - 65) | mask;
+                                       handler_id = (modechar - 65) | mask;
 
                                        if (modehandlers[handler_id])
                                        {
                                                bool abort = false;
 
-                                               log(DEBUG,"Found a ModeHandler* for mode %c",*modeletter);
+                                               log(DEBUG,"Found a ModeHandler* for mode %c",modechar);
 
                                                for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
                                                {
@@ -496,6 +504,16 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server
                                                                }
                                                        }
                                                        ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding);
+
+                                                       if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter == ""))
+                                                       {
+                                                               /* The handler nuked the parameter and they are supposed to have one.
+                                                                * We CANT continue now, even if they actually returned MODEACTION_ALLOW,
+                                                                * so we bail to the next mode character.
+                                                                */
+                                                               continue;
+                                                       }
+
                                                        if (ma == MODEACTION_ALLOW)
                                                        {
                                                                log(DEBUG,"ModeAction was allow");
@@ -508,7 +526,7 @@ void ModeParser::Process(char **parameters, int pcnt, userrec *user, bool server
                                                                }
                                                                
                                                                /* Add the mode letter */
-                                                               output_sequence = output_sequence + *modeletter;
+                                                               output_sequence.push_back(modechar);
                                                                log(DEBUG,"Added mode letter to output sequence, sequence now: '%s'",output_sequence.c_str());
 
                                                                /* Is there a valid parameter for this mode? If so add it to the parameter list */
@@ -577,7 +595,7 @@ void ModeParser::CleanMask(std::string &mask)
        if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
        {
                /* Just a nick, or just a host */
-               if ((pos_of_dot == std::string::npos) && (pos_of_dot == std::string::npos))
+               if ((pos_of_dot == std::string::npos) && (pos_of_colon == std::string::npos))
                {
                        /* It has no '.' in it, it must be a nick. */
                        mask.append("!*@*");
@@ -598,16 +616,6 @@ void ModeParser::CleanMask(std::string &mask)
                /* Has a ! but no @, it must be a nick!ident */
                mask.append("@*");
        }
-
-       /* Check for dumb stuff like *@*!*
-        * swap the two items over so that at least the n!u@h ordering
-        * is correct even if the elements may not be
-        */
-       if (pos_of_pling > pos_of_at)
-       {
-               mask.replace(pos_of_pling, 1, "@");
-               mask.replace(pos_of_at, 1, "!");
-       }
 }
 
 bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
@@ -644,5 +652,9 @@ ModeParser::ModeParser()
        this->AddMode(new ModeChannelPrivate, 'p');
        this->AddMode(new ModeChannelBan, 'b');
        this->AddMode(new ModeChannelModerated, 'm');
+       this->AddMode(new ModeChannelTopicOps, 't');
+       this->AddMode(new ModeChannelNoExternal, 'n');
+       this->AddMode(new ModeChannelInviteOnly, 'i');
+       /* TODO: Modes +l, +k, +o, +v, +h */
 }