X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=7321d11c425a9cb86a539a33d72e2695f081a358;hb=2b3394855d5adddb16285b905503d9ffe5a1d963;hp=a7effa642d2fef7ff97a43b51bdccdc7e40b381f;hpb=08dc6b94f774f8f836354c8ac1c1945ddf35ad48;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index a7effa642..7321d11c4 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -12,10 +12,7 @@ */ #include "inspircd.h" -#include "users.h" -#include "modules.h" #include "inspstring.h" -#include "mode.h" /* +s (secret) */ #include "modes/cmode_s.h" @@ -79,6 +76,7 @@ unsigned int ModeHandler::GetCount() void ModeHandler::ChangeCount(int modifier) { count += modifier; + ServerInstance->Log(DEBUG,"Change count for mode %c is now %d", mode, count); } ModeType ModeHandler::GetModeType() @@ -127,6 +125,10 @@ void ModeHandler::DisplayList(userrec* user, chanrec* channel) { } +void ModeHandler::DisplayEmptyList(userrec* user, chanrec* channel) +{ +} + bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel) { return (ours < theirs); @@ -246,11 +248,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; } @@ -274,7 +282,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool chanrec* targetchannel = ServerInstance->FindChan(parameters[0]); userrec* targetuser = ServerInstance->FindNick(parameters[0]); - LastParse = ""; + LastParse.clear(); /* Special case for displaying the list for listmodes, * e.g. MODE #chan b, or MODE #chan +b without a parameter @@ -283,22 +291,47 @@ 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++); + mh->DisplayEmptyList(user, targetchannel); + continue; + } + /** See below for a description of what craq this is :D */ unsigned char handler_id = (*mode - 65) | mask; @@ -381,9 +414,9 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool } std::string mode_sequence = parameters[1]; - std::string parameter = ""; + std::string parameter; std::ostringstream parameter_list; - std::string output_sequence = ""; + std::string output_sequence; bool adding = true, state_change = false; unsigned char handler_id = 0; int parameter_counter = 2; /* Index of first parameter */ @@ -454,7 +487,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool /* Yerk, invalid! */ if ((parameter.find(':') == 0) || (parameter.rfind(' ') != std::string::npos)) - parameter = ""; + parameter.clear(); } else { @@ -482,13 +515,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; @@ -497,7 +545,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool /* Call the handler for the mode */ ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding); - if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter == "")) + if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter.empty())) { /* The handler nuked the parameter and they are supposed to have one. * We CANT continue now, even if they actually returned MODEACTION_ALLOW, @@ -519,8 +567,10 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool /* Add the mode letter */ output_sequence.push_back(modechar); + modehandlers[handler_id]->ChangeCount(adding ? 1 : -1); + /* Is there a valid parameter for this mode? If so add it to the parameter list */ - if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter != "")) + if ((modehandlers[handler_id]->GetNumParams(adding)) && (!parameter.empty())) { parameter_list << " " << parameter; parameter_count++; @@ -559,8 +609,9 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool break; } } + /* Was there at least one valid mode in the sequence? */ - if (output_sequence != "") + if (!output_sequence.empty()) { if (servermode) { @@ -645,7 +696,7 @@ bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter) * If they do that, thats their problem, and if i ever EVER see an * official InspIRCd developer do that, i'll beat them with a paddle! */ - if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z')) + if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z') || (mh->GetPrefix() > 126)) return false; /* A mode prefix of ',' is not acceptable, it would fuck up server to server. @@ -737,6 +788,9 @@ 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]) @@ -753,6 +807,9 @@ 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))) @@ -813,6 +870,9 @@ 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; /* One parameter when adding */ if (modehandlers[pos]) @@ -852,20 +912,23 @@ 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; } std::string ModeParser::BuildPrefixes() { - std::string mletters = ""; - std::string mprefixes = ""; + std::string mletters; + std::string mprefixes; pfxcontainer pfx; std::map prefix_to_mode; 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())) @@ -901,6 +964,7 @@ bool ModeParser::AddModeWatcher(ModeWatcher* mw) pos = (mw->GetModeChar()-65) | mask; modewatchers[pos].push_back(mw); + return true; } @@ -967,37 +1031,41 @@ void ModeHandler::RemoveMode(chanrec* channel) ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance) { + struct Initializer + { + char modechar; + ModeHandler* handler; + }; + + Initializer modes[] = { + { 's', new ModeChannelSecret(Instance) }, + { 'p', new ModeChannelPrivate(Instance) }, + { 'm', new ModeChannelModerated(Instance) }, + { 't', new ModeChannelTopicOps(Instance) }, + { 'n', new ModeChannelNoExternal(Instance) }, + { 'i', new ModeChannelInviteOnly(Instance) }, + { 'k', new ModeChannelKey(Instance) }, + { 'l', new ModeChannelLimit(Instance) }, + { 'b', new ModeChannelBan(Instance) }, + { 'o', new ModeChannelOp(Instance) }, + { 'h', new ModeChannelHalfOp(Instance) }, + { 'v', new ModeChannelVoice(Instance) }, + { 's', new ModeUserServerNotice(Instance) }, + { 'w', new ModeUserWallops(Instance) }, + { 'i', new ModeUserInvisible(Instance) }, + { 'o', new ModeUserOperator(Instance) }, + { 'n', new ModeUserServerNoticeMask(Instance) }, + { 0, NULL } + }; + /* Clear mode list */ memset(modehandlers, 0, sizeof(modehandlers)); memset(modewatchers, 0, sizeof(modewatchers)); /* Last parse string */ - LastParse = ""; + LastParse.clear(); /* Initialise the RFC mode letters */ - - /* Start with channel simple modes, no params */ - this->AddMode(new ModeChannelSecret(Instance), 's'); - this->AddMode(new ModeChannelPrivate(Instance), 'p'); - this->AddMode(new ModeChannelModerated(Instance), 'm'); - this->AddMode(new ModeChannelTopicOps(Instance), 't'); - this->AddMode(new ModeChannelNoExternal(Instance), 'n'); - this->AddMode(new ModeChannelInviteOnly(Instance), 'i'); - - /* Cannel modes with params */ - this->AddMode(new ModeChannelKey(Instance), 'k'); - this->AddMode(new ModeChannelLimit(Instance), 'l'); - - /* Channel listmodes */ - this->AddMode(new ModeChannelBan(Instance), 'b'); - this->AddMode(new ModeChannelOp(Instance), 'o'); - this->AddMode(new ModeChannelHalfOp(Instance), 'h'); - this->AddMode(new ModeChannelVoice(Instance), 'v'); - - /* Now for usermodes */ - this->AddMode(new ModeUserServerNotice(Instance), 's'); - this->AddMode(new ModeUserWallops(Instance), 'w'); - this->AddMode(new ModeUserInvisible(Instance), 'i'); - this->AddMode(new ModeUserOperator(Instance), 'o'); - this->AddMode(new ModeUserServerNoticeMask(Instance), 'n'); + for (int index = 0; modes[index].modechar; index++) + this->AddMode(modes[index].handler, modes[index].modechar); }