]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Correct this error message to confuse people less.
[user/henk/code/inspircd.git] / src / mode.cpp
index d73a5d1b8921f94b3153d462c467a436ebde811a..a5549a9645b0219a20a6192541d2128a70ded2dd 100644 (file)
@@ -11,7 +11,7 @@
  * ---------------------------------------------------
  */
 
-/* $Core: libIRCDmode */
+/* $Core */
 /* $ExtraDeps: $(RELCPPFILES) */
 /* $ExtraObjects: modes/modeclasses.a */
 /* $ExtraBuild: @${MAKE} -C "modes" DIRNAME="src/modes" CC="$(CC)" $(MAKEARGS) CPPFILES="$(CPPFILES)" */
 #include "modes/cmode_h.h"
 /* +v (channel voice) */
 #include "modes/cmode_v.h"
-/* +s (server notices) */
-#include "modes/umode_s.h"
 /* +w (see wallops) */
 #include "modes/umode_w.h"
 /* +i (invisible) */
 #include "modes/umode_i.h"
 /* +o (operator) */
 #include "modes/umode_o.h"
-/* +n (notice mask - our implementation of snomasks) */
-#include "modes/umode_n.h"
+/* +s (server notice masks) */
+#include "modes/umode_s.h"
 
 ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix, char prefixrequired)
        : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix), count(0), prefixneeded(prefixrequired)
@@ -119,6 +117,11 @@ char ModeHandler::GetModeChar()
        return mode;
 }
 
+std::string ModeHandler::GetUserParameter(User* user)
+{
+       return "";
+}
+
 ModeAction ModeHandler::OnModeChange(User*, User*, Channel*, std::string&, bool, bool)
 {
        return MODEACTION_DENY;
@@ -144,6 +147,10 @@ void ModeHandler::DisplayEmptyList(User*, Channel*)
 {
 }
 
+void ModeHandler::OnParameterMissing(User* user, User* dest, Channel* channel)
+{
+}
+
 bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string&, const std::string&, Channel*)
 {
        return (ours < theirs);
@@ -167,10 +174,6 @@ SimpleChannelModeHandler::SimpleChannelModeHandler(InspIRCd* Instance, char mode
 
 ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool servermode)
 {
-       /* Only opers can change other users modes */
-       if (source != dest)
-               return MODEACTION_DENY;
-
        if (adding)
        {
                if (!dest->IsModeSet(this->GetModeChar()))
@@ -251,7 +254,7 @@ User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int)
        d = ServerInstance->FindNick(dest);
        if (!d)
        {
-               user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, dest);
+               user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), dest);
                return NULL;
        }
        return d;
@@ -282,7 +285,7 @@ const char* ModeParser::Grant(User *d,Channel *chan,int MASK)
                                n->first->AddVoicedUser(d);
                        break;
                }
-               return d->nick;
+               return d->nick.c_str();
        }
        return "";
 }
@@ -312,7 +315,7 @@ const char* ModeParser::Revoke(User *d,Channel *chan,int MASK)
                                n->first->DelVoicedUser(d);
                        break;
                }
-               return d->nick;
+               return d->nick.c_str();
        }
        return "";
 }
@@ -322,35 +325,35 @@ void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targ
        if (targetchannel)
        {
                /* Display channel's current mode string */
-               user->WriteNumeric(324, "%s %s +%s",user->nick, targetchannel->name, targetchannel->ChanModes(targetchannel->HasUser(user)));
-               user->WriteNumeric(329, "%s %s %lu", user->nick, targetchannel->name, (unsigned long)targetchannel->age);
+               user->WriteNumeric(RPL_CHANNELMODEIS, "%s %s +%s",user->nick.c_str(), targetchannel->name.c_str(), targetchannel->ChanModes(targetchannel->HasUser(user)));
+               user->WriteNumeric(RPL_CHANNELCREATED, "%s %s %lu", user->nick.c_str(), targetchannel->name.c_str(), (unsigned long)targetchannel->age);
                return;
        }
        else if (targetuser)
        {
                if (targetuser->Visibility && !targetuser->Visibility->VisibleTo(user))
                {
-                       user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, text);
+                       user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), text);
                        return;
                }
 
-               if ((targetuser == user) || (IS_OPER(user)))
+               if (targetuser == user || user->HasPrivPermission("users/auspex"))
                {
                        /* Display user's current mode string */
-                       user->WriteNumeric(221, "%s :+%s",targetuser->nick,targetuser->FormatModes());
+                       user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes());
                        if (IS_OPER(targetuser))
-                               user->WriteNumeric(8, "%s +%s :Server notice mask", targetuser->nick, targetuser->FormatNoticeMasks());
+                               user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks());
                        return;
                }
                else
                {
-                       user->WriteNumeric(502, "%s :Can't change mode for other users", user->nick);
+                       user->WriteNumeric(ERR_USERSDONTMATCH, "%s :Can't change mode for other users", user->nick.c_str());
                        return;
                }
        }
 
        /* No such nick/channel */
-       user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, text);
+       user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), text);
        return;
 }
 
@@ -412,11 +415,14 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                        continue;
                                }
 
-                               if (ServerInstance->Config->HideModeLists[mletter] && (targetchannel->GetStatus(user) < STATUS_HOP))
+                               if (!user->HasPrivPermission("channels/auspex"))
                                {
-                                       user->WriteNumeric(482, "%s %s :Only half-operators and above may view the +%c list",user->nick, targetchannel->name, *mode++);
-                                       mh->DisplayEmptyList(user, targetchannel);
-                                       continue;
+                                       if (ServerInstance->Config->HideModeLists[mletter] && (targetchannel->GetStatus(user) < STATUS_HOP))
+                                       {
+                                               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only half-operators and above may view the +%c list",user->nick.c_str(), targetchannel->name.c_str(), *mode++);
+                                               mh->DisplayEmptyList(user, targetchannel);
+                                               continue;
+                                       }
                                }
 
                                /** See below for a description of what craq this is :D
@@ -476,16 +482,16 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                {
                        type = MODETYPE_USER;
                        mask = MASK_USER;
-                       if ((user != targetuser) && (!ServerInstance->ULine(user->server)))
+                       if (user != targetuser && IS_LOCAL(user) && !ServerInstance->ULine(user->server))
                        {
-                               user->WriteNumeric(502, "%s :Can't change mode for other users", user->nick);
+                               user->WriteNumeric(ERR_USERSDONTMATCH, "%s :Can't change mode for other users", user->nick.c_str());
                                return;
                        }
                }
                else
                {
                        /* No such nick/channel */
-                       user->WriteNumeric(401, "%s %s :No such nick/channel",user->nick, parameters[0].c_str());
+                       user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), parameters[0].c_str());
                        return;
                }
 
@@ -570,6 +576,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                else
                                                                {
                                                                        /* No parameter, continue to the next mode */
+                                                                       modehandlers[handler_id]->OnParameterMissing(user, targetuser, targetchannel);
                                                                        continue;
                                                                }
 
@@ -611,8 +618,8 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                        if (!ourmode || ourmode->GetPrefixRank() < neededrank)
                                                                        {
                                                                                /* Bog off */
-                                                                               user->WriteNumeric(482, "%s %s :You must have channel privilege %c or above to %sset channel mode %c",
-                                                                                               user->nick, targetchannel->name, needed, adding ? "" : "un", modechar);
+                                                                               user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have channel privilege %c or above to %sset channel mode %c",
+                                                                                               user->nick.c_str(), targetchannel->name.c_str(), needed, adding ? "" : "un", modechar);
                                                                                continue;
                                                                        }
                                                                }
@@ -638,6 +645,17 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                        if (abort)
                                                                continue;
 
+                                                       /* If it's disabled, they have to be an oper.
+                                                        */
+                                                       if (IS_LOCAL(user) && !IS_OPER(user) && ((type == MODETYPE_CHANNEL ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes)[modehandlers[handler_id]->GetModeChar() - 'A']))
+                                                       {
+                                                               user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - %s mode %c has been locked by the administrator",
+                                                                               user->nick.c_str(),
+                                                                               type == MODETYPE_CHANNEL ? "channel" : "user",
+                                                                               modehandlers[handler_id]->GetModeChar());
+                                                               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
                                                         */
@@ -645,16 +663,16 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                        {
                                                                if (IS_OPER(user))
                                                                {
-                                                                       user->WriteNumeric(481, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c",
-                                                                                       user->nick,
-                                                                                       user->oper,
+                                                                       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.c_str(),
                                                                                        type == MODETYPE_CHANNEL ? "channel" : "user",
                                                                                        modehandlers[handler_id]->GetModeChar());
                                                                }
                                                                else
                                                                {
-                                                                       user->WriteNumeric(481, "%s :Permission Denied - Only operators may set %s mode %c",
-                                                                                       user->nick,
+                                                                       user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Only operators may set %s mode %c",
+                                                                                       user->nick.c_str(),
                                                                                        type == MODETYPE_CHANNEL ? "channel" : "user",
                                                                                        modehandlers[handler_id]->GetModeChar());
                                                                }
@@ -711,7 +729,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                                                state_change = false;
 
                                                                if ((output_sequence.length() + parameter_list.str().length() > 450) || (output_sequence.length() > 100)
-                                                                               || (parameter_count > MAXMODES))
+                                                                               || (parameter_count > ServerInstance->Config->Limits.MaxModes))
                                                                {
                                                                        /* We cant have a mode sequence this long */
                                                                        letter = mode_sequence.end() - 1;
@@ -723,7 +741,7 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                                        else
                                        {
                                                /* No mode handler? Unknown mode character then. */
-                                               user->WriteServ("%d %s %c :is unknown mode char to me", type == MODETYPE_CHANNEL ? 472 : 501, user->nick, modechar);
+                                               user->WriteServ("%d %s %c :is unknown mode char to me", type == MODETYPE_CHANNEL ? 472 : 501, user->nick.c_str(), modechar);
                                        }
                                break;
                        }
@@ -736,12 +754,12 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                        {
                                if (type == MODETYPE_CHANNEL)
                                {
-                                       targetchannel->WriteChannelWithServ(ServerInstance->Config->ServerName, "MODE %s %s%s", targetchannel->name, output_sequence.c_str(), parameter_list.str().c_str());
+                                       targetchannel->WriteChannelWithServ(ServerInstance->Config->ServerName, "MODE %s %s%s", targetchannel->name.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
                                        this->LastParse = targetchannel->name;
                                }
                                else
                                {
-                                       targetuser->WriteServ("MODE %s %s%s",targetuser->nick,output_sequence.c_str(), parameter_list.str().c_str());
+                                       targetuser->WriteServ("MODE %s %s%s",targetuser->nick.c_str(),output_sequence.c_str(), parameter_list.str().c_str());
                                        this->LastParse = targetuser->nick;
                                }
                        }
@@ -749,13 +767,13 @@ void ModeParser::Process(const std::vector<std::string>& parameters, User *user,
                        {
                                if (type == MODETYPE_CHANNEL)
                                {
-                                       targetchannel->WriteChannel(user,"MODE %s %s%s",targetchannel->name,output_sequence.c_str(),parameter_list.str().c_str());
+                                       targetchannel->WriteChannel(user, "MODE %s %s%s", targetchannel->name.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
                                        FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, output_sequence + parameter_list.str()));
                                        this->LastParse = targetchannel->name;
                                }
                                else
                                {
-                                       user->WriteTo(targetuser,"MODE %s %s%s",targetuser->nick,output_sequence.c_str(), parameter_list.str().c_str());
+                                       user->WriteTo(targetuser, "MODE %s %s%s", targetuser->nick.c_str(), output_sequence.c_str(), parameter_list.str().c_str());
                                        FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, output_sequence + parameter_list.str()));
                                        this->LastParse = targetuser->nick;
                                }
@@ -780,6 +798,9 @@ void ModeParser::CleanMask(std::string &mask)
        std::string::size_type pos_of_dot = mask.find_first_of('.');
        std::string::size_type pos_of_colons = mask.find("::"); /* Because ipv6 addresses are colon delimited -- double so it treats extban as nick */
 
+       if (mask.length() >= 2 && mask[1] == ':')
+               return; // if it's an extban, don't even try guess how it needs to be formed.
+
        if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
        {
                /* Just a nick, or just a host - or clearly ipv6 (starting with :) */
@@ -989,7 +1010,7 @@ std::string ModeParser::ModeString(User* user, Channel* channel, bool nick_suffi
                return types;
 }
 
-std::string ModeParser::ChanModes()
+std::string ModeParser::GiveModeList(ModeMasks m)
 {
        std::string type1;      /* Listmodes EXCEPT those with a prefix */
        std::string type2;      /* Modes that take a param when adding or removing */
@@ -1001,7 +1022,7 @@ std::string ModeParser::ChanModes()
                if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h'))
                        continue;
 
-               unsigned char pos = (mode-65) | MASK_CHANNEL;
+               unsigned char pos = (mode-65) | m;
                 /* One parameter when adding */
                if (modehandlers[pos])
                {       
@@ -1140,7 +1161,7 @@ void ModeHandler::RemoveMode(User* user, irc::modestacker* stack)
                        sprintf(moderemove,"-%c",this->GetModeChar());
                        parameters.push_back(user->nick);
                        parameters.push_back(moderemove);
-                       ServerInstance->Parser->CallHandler("MODE", parameters, user);
+                       ServerInstance->Modes->Process(parameters, ServerInstance->FakeClient, false);
                }
        }
 }
@@ -1185,7 +1206,6 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
                new ModeChannelOp(Instance),
                new ModeChannelHalfOp(Instance),
                new ModeChannelVoice(Instance),
-               new ModeUserServerNotice(Instance),
                new ModeUserWallops(Instance),
                new ModeUserInvisible(Instance),
                new ModeUserOperator(Instance),
@@ -1204,5 +1224,5 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
                this->AddMode(modes[index]);
 
        seq = 0;
-       memset(&sent, 0, 256);
+       memset(&sent, 0, sizeof(sent));
 }