X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmode.cpp;h=ef3801ab6c29990fdf08adc5266b0ff211c8171a;hb=45d76881d8b153cb42c28fe61951aa9b6a055cb6;hp=dfa846364f95366e969ec67cae99346fc750f17f;hpb=74c8913f72e6d48c88a01155ef5fe5ca20cc2bb1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index dfa846364..ef3801ab6 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -53,7 +53,7 @@ #include "modes/umode_n.h" ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly, char mprefix) - : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly), prefix(mprefix) + : 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) { } @@ -71,6 +71,16 @@ unsigned int ModeHandler::GetPrefixRank() return 0; } +unsigned int ModeHandler::GetCount() +{ + return 0; +} + +void ModeHandler::ChangeCount(int modifier) +{ + count += modifier; +} + ModeType ModeHandler::GetModeType() { return m_type; @@ -190,7 +200,6 @@ const char* ModeParser::Grant(userrec *d,chanrec *chan,int MASK) n->first->AddVoicedUser(d); break; } - ServerInstance->Log(DEBUG,"grant: %s %s",n->first->name,d->nick); return d->nick; } return ""; @@ -221,7 +230,6 @@ const char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK) n->first->DelVoicedUser(d); break; } - ServerInstance->Log(DEBUG,"revoke: %s %s",n->first->name,d->nick); return d->nick; } return ""; @@ -266,8 +274,6 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool chanrec* targetchannel = ServerInstance->FindChan(parameters[0]); userrec* targetuser = ServerInstance->FindNick(parameters[0]); - ServerInstance->Log(DEBUG,"ModeParser::Process start: pcnt=%d",pcnt); - LastParse = ""; /* Special case for displaying the list for listmodes, @@ -275,9 +281,11 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool */ if ((targetchannel) && (pcnt == 2)) { - ServerInstance->Log(DEBUG,"Spool list"); const char* mode = parameters[1]; + int nonlistmodes_found = 0; + mask = MASK_CHANNEL; + while (mode && *mode) { if (*mode == '+') @@ -287,25 +295,42 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool } ModeHandler *mh = this->FindMode(*mode, MODETYPE_CHANNEL); + bool display = true; if ((mh) && (mh->IsListMode())) { - mh->DisplayList(user, targetchannel); + /** See below for a description of what craq this is :D + */ + unsigned char handler_id = (*mode - 65) | mask; + + 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; + } + + if (display) + mh->DisplayList(user, targetchannel); } + else + nonlistmodes_found++; mode++; } + + /* We didnt have any modes that were non-list, we can return here */ + if (!nonlistmodes_found) + return; } if (pcnt == 1) { - ServerInstance->Log(DEBUG,"Mode list request"); this->DisplayCurrentModes(user, targetuser, targetchannel, parameters[0]); } else if (pcnt > 1) { - ServerInstance->Log(DEBUG,"More than one parameter"); - if (targetchannel) { type = MODETYPE_CHANNEL; @@ -318,8 +343,6 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool if ((IS_LOCAL(user)) && (targetchannel->GetStatus(user) < STATUS_HOP)) { /* We don't have halfop */ - ServerInstance->Log(DEBUG,"The user is not a halfop or above, checking other reasons for being able to set the modes"); - int MOD_RESULT = 0; FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, targetchannel, AC_GENERAL_MODE)); if (MOD_RESULT == ACR_DENY) @@ -365,6 +388,7 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool unsigned char handler_id = 0; int parameter_counter = 2; /* Index of first parameter */ int parameter_count = 0; + bool last_successful_state_change = false; /* A mode sequence that doesnt start with + or -. Assume +. - Thanks for the suggestion spike (bug#132) */ if ((*mode_sequence.begin() != '+') && (*mode_sequence.begin() != '-')) @@ -390,12 +414,16 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool if ((!adding) || (!output_sequence.length())) state_change = true; adding = true; + if (!output_sequence.length()) + last_successful_state_change = false; continue; break; case '-': if ((adding) || (!output_sequence.length())) state_change = true; adding = false; + if (!output_sequence.length()) + last_successful_state_change = true; continue; break; default: @@ -415,19 +443,13 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool { bool abort = false; - for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++) - { - if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == MODEACTION_DENY) - abort = true; - } - if ((modehandlers[handler_id]->GetModeType() == type) && (!abort)) + if (modehandlers[handler_id]->GetModeType() == type) { if (modehandlers[handler_id]->GetNumParams(adding)) { /* This mode expects a parameter, do we have any parameters left in our list to use? */ if (parameter_counter < pcnt) { - ServerInstance->Log(DEBUG,"parameter_counter = %d, pcnt = %d", parameter_counter, pcnt); parameter = parameters[parameter_counter++]; /* Yerk, invalid! */ @@ -439,6 +461,26 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool /* No parameter, continue to the next mode */ continue; } + + 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) == false) + { + abort = true; + break; + } + /* A module whacked the parameter completely, and there was one. abort. */ + if ((had_parameter) && (parameter.empty())) + { + abort = true; + break; + } + } + + if (abort) + continue; } /* It's an oper only mode, check if theyre an oper. If they arent, @@ -468,7 +510,11 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool { /* We're about to output a valid mode letter - was there previously a pending state-change? */ if (state_change) - output_sequence.append(adding ? "+" : "-"); + { + if (adding != last_successful_state_change) + output_sequence.append(adding ? "+" : "-"); + last_successful_state_change = adding; + } /* Add the mode letter */ output_sequence.push_back(modechar); @@ -533,7 +579,6 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool { if (type == MODETYPE_CHANNEL) { - ServerInstance->Log(DEBUG,"Write output sequence and parameters to channel: %s %s%s",targetchannel->name,output_sequence.c_str(),parameter_list.str().c_str()); targetchannel->WriteChannel(user,"MODE %s %s%s",targetchannel->name,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; @@ -617,7 +662,6 @@ bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter) return false; modehandlers[pos] = mh; - ServerInstance->Log(DEBUG,"ModeParser::AddMode: added mode %c",mh->GetModeChar()); return true; } @@ -857,8 +901,6 @@ bool ModeParser::AddModeWatcher(ModeWatcher* mw) pos = (mw->GetModeChar()-65) | mask; modewatchers[pos].push_back(mw); - ServerInstance->Log(DEBUG,"ModeParser::AddModeWatcher: watching mode %c",mw->GetModeChar()); - return true; } @@ -880,12 +922,10 @@ bool ModeParser::DelModeWatcher(ModeWatcher* mw) if (a == modewatchers[pos].end()) { - ServerInstance->Log(DEBUG, "ModeParser::DelModeWatcher: Couldn't find watcher for mode %c in list", mw->GetModeChar()); return false; } modewatchers[pos].erase(a); - ServerInstance->Log(DEBUG,"ModeParser::DelModeWatcher: stopped watching mode %c",mw->GetModeChar()); return true; } @@ -927,6 +967,33 @@ 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)); @@ -935,29 +1002,6 @@ ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance) LastParse = ""; /* 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); }