]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Clean up the FileReader class and all of the modules that use it.
[user/henk/code/inspircd.git] / src / mode.cpp
index 417707ee9100a35d1d69b46ce9c1af228b233c36..b4bb72c42a9480de52378bfd9e6ceb2e625e0a5d 100644 (file)
@@ -184,22 +184,6 @@ void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, Mo
 {
 }
 
-User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int)
-{
-       User *d;
-       if ((!user) || (!dest) || (!chan) || (!*dest))
-       {
-               return NULL;
-       }
-       d = ServerInstance->FindNick(dest);
-       if (!d)
-       {
-               user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), dest);
-               return NULL;
-       }
-       return d;
-}
-
 void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text)
 {
        if (targetchannel)
@@ -215,7 +199,7 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ
                {
                        /* Display user's current mode string */
                        user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes());
-                       if (IS_OPER(targetuser))
+                       if ((targetuser->IsOper()))
                                user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks());
                        return;
                }
@@ -296,7 +280,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
                        return MODEACTION_DENY;
        }
 
-       if (IS_LOCAL(user) && !IS_OPER(user))
+       if (IS_LOCAL(user) && !user->IsOper())
        {
                char* disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes;
                if (disabled[modechar - 'A'])
@@ -310,10 +294,10 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool
        if (adding && IS_LOCAL(user) && mh->NeedsOper() && !user->HasModePermission(modechar, type))
        {
                /* It's an oper only mode, and they don't have access to it. */
-               if (IS_OPER(user))
+               if (user->IsOper())
                {
                        user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c",
-                                       user->nick.c_str(), user->oper->NameStr(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
+                                       user->nick.c_str(), user->oper->name.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
                }
                else
                {
@@ -629,6 +613,7 @@ bool ModeParser::AddMode(ModeHandler* mh)
                return false;
 
        modehandlers[pos] = mh;
+       RecreateModeListFor004Numeric();
        return true;
 }
 
@@ -671,6 +656,7 @@ bool ModeParser::DelMode(ModeHandler* mh)
        }
 
        modehandlers[pos] = NULL;
+       RecreateModeListFor004Numeric();
 
        return true;
 }
@@ -689,52 +675,25 @@ ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
        return modehandlers[pos];
 }
 
-std::string ModeParser::UserModeList()
+std::string ModeParser::CreateModeList(ModeType mt, bool needparam)
 {
-       char modestr[256];
-       int pointer = 0;
+       std::string modestr;
+       unsigned char mask = ((mt == MODETYPE_CHANNEL) ? MASK_CHANNEL : MASK_USER);
 
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
-               unsigned char pos = (mode-65) | MASK_USER;
+               unsigned char pos = (mode-65) | mask;
 
-               if (modehandlers[pos])
-                       modestr[pointer++] = mode;
+               if ((modehandlers[pos]) && ((!needparam) || (modehandlers[pos]->GetNumParams(true))))
+                       modestr.push_back(mode);
        }
-       modestr[pointer++] = 0;
-       return modestr;
-}
-
-std::string ModeParser::ChannelModeList()
-{
-       char modestr[256];
-       int pointer = 0;
 
-       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
-       {
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
-
-               if (modehandlers[pos])
-                       modestr[pointer++] = mode;
-       }
-       modestr[pointer++] = 0;
        return modestr;
 }
 
-std::string ModeParser::ParaModeList()
+void ModeParser::RecreateModeListFor004Numeric()
 {
-       char modestr[256];
-       int pointer = 0;
-
-       for (unsigned char mode = 'A'; mode <= 'z'; mode++)
-       {
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
-
-               if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true)))
-                       modestr[pointer++] = mode;
-       }
-       modestr[pointer++] = 0;
-       return modestr;
+       Cached004ModeList = CreateModeList(MODETYPE_USER) + " " + CreateModeList(MODETYPE_CHANNEL) + " " + CreateModeList(MODETYPE_CHANNEL, true);
 }
 
 ModeHandler* ModeParser::FindPrefix(unsigned const char pfxletter)