]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
We were already sending FMODE +nt after each channel creation to keep services happy...
[user/henk/code/inspircd.git] / src / mode.cpp
index ef3801ab6c29990fdf08adc5266b0ff211c8171a..8b91f7af52de55ec4bcc2d66bd182d4f20572835 100644 (file)
@@ -246,11 +246,17 @@ void ModeParser::DisplayCurrentModes(userrec *user, userrec* targetuser, chanrec
        }
        else if (targetuser)
        {
-               if ((targetuser == user) || (*user->oper))
+               if (targetuser->Visibility && !targetuser->Visibility->VisibleTo(user))
+               {
+                       user->WriteServ("401 %s %s :No such nick/channel",user->nick, text);
+                       return;
+               }
+
+               if ((targetuser == user) || (IS_OPER(user)))
                {
                        /* Display user's current mode string */
                        user->WriteServ("221 %s :+%s",targetuser->nick,targetuser->FormatModes());
-                       if (*targetuser->oper)
+                       if (IS_OPER(targetuser))
                                user->WriteServ("008 %s +%s :Server notice mask", targetuser->nick, targetuser->FormatNoticeMasks());
                        return;
                }
@@ -283,22 +289,46 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
        {
                const char* mode = parameters[1];
                int nonlistmodes_found = 0;
+               bool sent[256];
 
                mask = MASK_CHANNEL;
+
+               memset(&sent, 0, 256);
                
                while (mode && *mode)
                {
+                       unsigned char mletter = *mode;
+
                        if (*mode == '+')
                        {
                                mode++;
                                continue;
                        }
 
+                       /* Ensure the user doesnt request the same mode twice,
+                        * so they cant flood themselves off out of idiocy.
+                        */
+                       if (!sent[mletter])
+                       {
+                               sent[mletter] = true;
+                       }
+                       else
+                       {
+                               mode++;
+                               continue;
+                       }
+
                        ModeHandler *mh = this->FindMode(*mode, MODETYPE_CHANNEL);
                        bool display = true;
 
                        if ((mh) && (mh->IsListMode()))
                        {
+                               if (ServerInstance->Config->HideModeLists[mletter] && (targetchannel->GetStatus(user) < STATUS_HOP))
+                               {
+                                       user->WriteServ("482 %s %s :Only half-operators and above may view the +%c list",user->nick, targetchannel->name, *mode++);
+                                       continue;
+                               }
+
                                /** See below for a description of what craq this is :D
                                 */
                                unsigned char handler_id = (*mode - 65) | mask;
@@ -466,6 +496,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
                                                                
                                                                for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
                                                                {
+                                                                       ServerInstance->Log(DEBUG,"Call mode watcher");
                                                                        if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false)
                                                                        {
                                                                                abort = true;
@@ -482,13 +513,28 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
                                                                if (abort)
                                                                        continue;
                                                        }
+                                                       else
+                                                       {
+                                                               /* Fix by brain: mode watchers not being called for parameterless modes */
+                                                               for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
+                                                               {
+                                                                       if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false)
+                                                                       {
+                                                                               abort = true;
+                                                                               break;
+                                                                       }
+                                                               }
+
+                                                               if (abort)
+                                                                       continue;
+                                                       }
 
                                                        /* It's an oper only mode, check if theyre an oper. If they arent,
                                                         * eat any parameter that  came with the mode, and continue to next
                                                         */
-                                                       if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!*user->oper))
+                                                       if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!IS_OPER(user)))
                                                        {
-                                                               user->WriteServ("481 %s :Permission Denied- Only IRC operators may %sset %s mode %c", user->nick,
+                                                               user->WriteServ("481 %s :Permission Denied - Only IRC operators may %sset %s mode %c", user->nick,
                                                                                adding ? "" : "un", type == MODETYPE_CHANNEL ? "channel" : "user",
                                                                                modehandlers[handler_id]->GetModeChar());
                                                                continue;
@@ -852,7 +898,7 @@ std::string ModeParser::ChanModes()
        return type1 + "," + type2 + "," + type3 + "," + type4;
 }
 
-bool ModeParser::PrefixComparison(const prefixtype one, const prefixtype two)
+bool ModeParser::PrefixComparison(prefixtype one, prefixtype two)
 {       
        return one.second > two.second;
 }
@@ -901,6 +947,7 @@ bool ModeParser::AddModeWatcher(ModeWatcher* mw)
        pos = (mw->GetModeChar()-65) | mask;
 
        modewatchers[pos].push_back(mw);
+
        return true;
 }