]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
auto-set +s when +n is set (as +n requires +s) - allow +n to be 'set twice' allowing...
[user/henk/code/inspircd.git] / src / mode.cpp
index c7d66cd463ec81f9fb1177c717725678755990a2..23cbe5ccb299437b4834205a34f1ba23f73ce660 100644 (file)
@@ -351,6 +351,10 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
                unsigned char handler_id = 0;
                int parameter_counter = 2; /* Index of first parameter */
 
+               /* A mode sequence that doesnt start with + or -. Assume +. - Thanks for the suggestion spike (bug#132) */
+               if ((*mode_sequence.begin() != '+') && (*mode_sequence.begin() != '-'))
+                       mode_sequence.insert(0, "+");
+
                for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
                {
                        unsigned char modechar = *letter;
@@ -492,7 +496,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
                                }
                                else
                                {
-                                       targetuser->WriteServ("MODE %s %s",targetuser->nick,output_sequence.c_str());
+                                       targetuser->WriteServ("MODE %s %s%s",targetuser->nick,output_sequence.c_str(), parameter_list.str().c_str());
                                }
                        }
                        else
@@ -505,7 +509,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool
                                }
                                else
                                {
-                                       user->WriteTo(targetuser,"MODE %s %s",targetuser->nick,output_sequence.c_str());
+                                       user->WriteTo(targetuser,"MODE %s %s%s",targetuser->nick,output_sequence.c_str(), parameter_list.str().c_str());
                                        FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, output_sequence));
                                }
                        }
@@ -662,6 +666,79 @@ ModeHandler* ModeParser::FindPrefix(unsigned const char pfxletter)
        return NULL;
 }
 
+std::string ModeParser::ModeString(userrec* user, chanrec* channel)
+{
+       std::string types;
+       std::string pars;
+
+       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
+       {
+               unsigned char pos = (mode-65) | MASK_CHANNEL;
+               ModeHandler* mh = modehandlers[pos];
+               if ((mh) && (mh->GetNumParams(true)) && (mh->GetNumParams(false)))
+               {
+                       ModePair ret;
+                       ret = mh->ModeSet(NULL, user, channel, user->nick);
+                       if (ret.first)
+                       {
+                               pars.append(" ");
+                               pars.append(user->nick);
+                               types.push_back(mh->GetModeChar());
+                       }
+               }
+       }
+
+       return types+pars;
+}
+
+std::string ModeParser::ChanModes()
+{
+       std::string type1;      /* Listmodes EXCEPT those with a prefix */
+       std::string type2;      /* Modes that take a param when adding or removing */
+       std::string type3;      /* Modes that only take a param when adding */
+       std::string type4;      /* Modes that dont take a param */
+
+       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
+       {
+               unsigned char pos = (mode-65) | MASK_CHANNEL;
+                /* One parameter when adding */
+               if (modehandlers[pos])
+               {       
+                       if (modehandlers[pos]->GetNumParams(true))
+                       {
+                               if ((modehandlers[pos]->IsListMode()) && (!modehandlers[pos]->GetPrefix()))
+                               {
+                                       type1 += modehandlers[pos]->GetModeChar();
+                               }
+                               else
+                               {
+                                       /* ... and one parameter when removing */
+                                       if (modehandlers[pos]->GetNumParams(false))
+                                       {
+                                               /* But not a list mode */
+                                               if (!modehandlers[pos]->GetPrefix())
+                                               {
+                                                       type2 += modehandlers[pos]->GetModeChar();
+                                               }
+                                       }
+                                       else
+                                       {
+                                               /* No parameters when removing */
+                                               type3 += modehandlers[pos]->GetModeChar();
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               type4 += modehandlers[pos]->GetModeChar();
+                       }
+               }
+                        
+       }
+
+       return type1 + "," + type2 + "," + type3 + "," + type4;
+}
+
 bool ModeParser::PrefixComparison(const prefixtype one, const prefixtype two)
 {       
        return one.second > two.second;
@@ -775,27 +852,3 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
        this->AddMode(new ModeUserServerNoticeMask(Instance), 'n');
 }
 
-bool ModeParser::InsertMode(std::string &output, const char* mode, unsigned short section)
-{
-       unsigned short currsection = 1;
-       unsigned int pos = output.find("CHANMODES=", 0) + 10; // +10 for the length of "CHANMODES="
-
-       if(section > 4 || section == 0)
-       {
-               ServerInstance->Log(DEBUG, "InsertMode: CHANMODES doesn't have a section %dh :/", section);
-               return false;
-       }
-
-       for(; pos < output.size(); pos++)
-       {
-               if(section == currsection)
-                       break;
-
-               if(output[pos] == ',')
-                       currsection++;
-       }
-
-       output.insert(pos, mode);
-       return true;
-}
-