]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Tidier than a trinary op
[user/henk/code/inspircd.git] / src / mode.cpp
index 810c003aa34af57397c8fb8b3650c687b4ef828f..35003de0eaee54d554aa5154944b76ac12496901 100644 (file)
@@ -496,6 +496,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");
@@ -567,6 +577,39 @@ void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
        return;
 }
 
+void ModeParser::CleanMask(std::string &mask)
+{
+       std::string::size_type pos_of_pling = mask.find_first_of('!');
+       std::string::size_type pos_of_at = mask.find_first_of('@');
+       std::string::size_type pos_of_dot = mask.find_first_of('.');
+       std::string::size_type pos_of_colon = mask.find_first_of(':'); /* Because ipv6 addresses are colon delimited */
+
+       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_colon == std::string::npos))
+               {
+                       /* It has no '.' in it, it must be a nick. */
+                       mask.append("!*@*");
+               }
+               else
+               {
+                       /* Got a dot in it? Has to be a host */
+                       mask = "*!*@" + mask;
+               }
+       }
+       else if ((pos_of_pling == std::string::npos) && (pos_of_at != std::string::npos))
+       {
+               /* Has an @ but no !, its a user@host */
+                mask = "*!" + mask;
+       }
+       else if ((pos_of_pling != std::string::npos) && (pos_of_at == std::string::npos))
+       {
+               /* Has a ! but no @, it must be a nick!ident */
+               mask.append("@*");
+       }
+}
+
 bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
 {
        unsigned char mask = 0;
@@ -586,6 +629,7 @@ bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
                return false;
 
        modehandlers[pos] = mh;
+       log(DEBUG,"ModeParser::AddMode: added mode %c",modeletter);
        return true;
 }