X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=78993caad8799a76d1d70e968a4e83a7908701ca;hb=a245aa22076e17e72c84e5a0f5699209cdf62727;hp=65ec7e61413bdc95ee23852cdd94f269baf0a1cd;hpb=4354774fe57e579087f6ba121f5569a8cda52d09;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 65ec7e614..78993caad 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -2,8 +2,8 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits + * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see * the file COPYING for details. @@ -12,9 +12,6 @@ */ /* $Core */ -/* $ExtraDeps: $(RELCPPFILES) */ -/* $ExtraObjects: modes/modeclasses.a */ -/* $ExtraBuild: @${MAKE} -C "modes" DIRNAME="src/modes" CC="$(CC)" $(MAKEARGS) CPPFILES="$(CPPFILES)" */ #include "inspircd.h" #include "inspstring.h" @@ -52,8 +49,8 @@ /* +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) +ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix, char prefixrequired, TranslateType translate) + : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), m_paramtype(translate), oper(operonly), prefix(mprefix), count(0), prefixneeded(prefixrequired) { } @@ -68,6 +65,8 @@ bool ModeHandler::IsListMode() char ModeHandler::GetNeededPrefix() { + if (prefixneeded == '%' && !ServerInstance->Config->AllowHalfop) + return '@'; return prefixneeded; } @@ -97,6 +96,11 @@ ModeType ModeHandler::GetModeType() return m_type; } +TranslateType ModeHandler::GetTranslateType() +{ + return m_paramtype; +} + bool ModeHandler::NeedsOper() { return oper; @@ -174,10 +178,6 @@ SimpleChannelModeHandler::SimpleChannelModeHandler(InspIRCd* Instance, char mode ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool servermode) { - /* Only opers can change other users modes */ - if (source != dest) - return MODEACTION_DENY; - if (adding) { if (!dest->IsModeSet(this->GetModeChar())) @@ -370,6 +370,8 @@ void ModeParser::Process(const std::vector& parameters, User *user, User* targetuser = ServerInstance->FindNick(parameters[0]); LastParse.clear(); + LastParseParams.clear(); + LastParseTranslate.clear(); /* Special case for displaying the list for listmodes, * e.g. MODE #chan b, or MODE #chan +b without a parameter @@ -382,7 +384,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, seq++; mask = MASK_CHANNEL; - + while (mode && *mode) { unsigned char mletter = *mode; @@ -392,7 +394,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, mode++; continue; } - + /* Ensure the user doesnt request the same mode twice, * so they cant flood themselves off out of idiocy. */ @@ -436,7 +438,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, for(ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) { std::string dummyparam; - + if (!((*watchers)->BeforeMode(user, NULL, targetchannel, dummyparam, true, MODETYPE_CHANNEL))) display = false; } @@ -474,9 +476,12 @@ void ModeParser::Process(const std::vector& parameters, User *user, if ((IS_LOCAL(user)) && (!ServerInstance->ULine(user->server)) && (!servermode)) { + /* Make modes that are being changed visible to OnAccessCheck */ + LastParse = parameters[1]; /* We don't have halfop */ int MOD_RESULT = 0; FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, targetchannel, AC_GENERAL_MODE)); + LastParse.clear(); if (MOD_RESULT == ACR_DENY) return; SkipAccessChecks = (MOD_RESULT == ACR_ALLOW); @@ -486,7 +491,7 @@ void ModeParser::Process(const std::vector& 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(ERR_USERSDONTMATCH, "%s :Can't change mode for other users", user->nick.c_str()); return; @@ -508,6 +513,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, unsigned int parameter_counter = 2; /* Index of first parameter */ unsigned int parameter_count = 0; bool last_successful_state_change = false; + LastParseTranslate.push_back(TR_TEXT); /* A mode sequence that doesnt start with + or -. Assume +. - Thanks for the suggestion spike (bug#132) */ if ((*mode_sequence.begin() != '+') && (*mode_sequence.begin() != '-')) @@ -605,11 +611,11 @@ void ModeParser::Process(const std::vector& parameters, User *user, /* If the mode defined by the handler is not '\0', but the handler for it * cannot be found, they probably dont have the right module loaded to implement * the prefix they want to compare the mode against, e.g. '&' for m_chanprotect. - * Revert to checking against the minimum core prefix, '%'. + * Revert to checking against the minimum core prefix, '%' or '@'. */ if (needed && !prefixmode) - prefixmode = FindPrefix('%'); - + prefixmode = ServerInstance->Config->AllowHalfop ? FindPrefix('%') : FindPrefix('@'); + unsigned int neededrank = prefixmode->GetPrefixRank(); /* Compare our rank on the channel against the rank of the required prefix, * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown @@ -630,7 +636,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, } bool had_parameter = !parameter.empty(); - + for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) { if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type, servermode) == false) @@ -704,7 +710,7 @@ void ModeParser::Process(const std::vector& parameters, User *user, output_sequence.append(adding ? "+" : "-"); last_successful_state_change = adding; } - + /* Add the mode letter */ output_sequence.push_back(modechar); @@ -714,6 +720,8 @@ void ModeParser::Process(const std::vector& parameters, User *user, if ((modehandlers[handler_id]->GetNumParams(adding)) && (!parameter.empty())) { parameter_list << " " << parameter; + LastParseParams.push_back(parameter); + LastParseTranslate.push_back(modehandlers[handler_id]->GetTranslateType()); parameter_count++; /* Does this mode have a prefix? */ if (modehandlers[handler_id]->GetPrefix() && targetchannel) @@ -754,7 +762,8 @@ void ModeParser::Process(const std::vector& parameters, User *user, /* Was there at least one valid mode in the sequence? */ if (!output_sequence.empty()) { - if (servermode) + LastParseParams.push_front(output_sequence); + if (!user) { if (type == MODETYPE_CHANNEL) { @@ -772,13 +781,13 @@ void ModeParser::Process(const std::vector& parameters, User *user, if (type == MODETYPE_CHANNEL) { 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())); + FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, LastParseParams, LastParseTranslate)); this->LastParse = targetchannel->name; } else { 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())); + FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, LastParseParams, LastParseTranslate)); this->LastParse = targetuser->nick; } } @@ -935,9 +944,6 @@ std::string ModeParser::ChannelModeList() for (unsigned char mode = 'A'; mode <= 'z'; mode++) { - if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h')) - continue; - unsigned char pos = (mode-65) | MASK_CHANNEL; if (modehandlers[pos]) @@ -954,9 +960,6 @@ std::string ModeParser::ParaModeList() for (unsigned char mode = 'A'; mode <= 'z'; mode++) { - if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h')) - continue; - unsigned char pos = (mode-65) | MASK_CHANNEL; if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true))) @@ -1014,7 +1017,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 */ @@ -1023,13 +1026,10 @@ std::string ModeParser::ChanModes() for (unsigned char mode = 'A'; mode <= 'z'; mode++) { - 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]) - { + { if (modehandlers[pos]->GetNumParams(true)) { if ((modehandlers[pos]->IsListMode()) && (!modehandlers[pos]->GetPrefix())) @@ -1059,14 +1059,13 @@ std::string ModeParser::ChanModes() type4 += modehandlers[pos]->GetModeChar(); } } - } return type1 + "," + type2 + "," + type3 + "," + type4; } bool ModeParser::PrefixComparison(prefixtype one, prefixtype two) -{ +{ return one.second > two.second; } @@ -1079,9 +1078,6 @@ std::string ModeParser::BuildPrefixes() for (unsigned char mode = 'A'; mode <= 'z'; mode++) { - if ((!ServerInstance->Config->AllowHalfop) && (mode == 'h')) - continue; - unsigned char pos = (mode-65) | MASK_CHANNEL; if ((modehandlers[pos]) && (modehandlers[pos]->GetPrefix())) @@ -1165,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, true); } } }