X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmode.cpp;h=ef3801ab6c29990fdf08adc5266b0ff211c8171a;hb=45d76881d8b153cb42c28fe61951aa9b6a055cb6;hp=1ae8dce07e35d5dd0fe41ce0355dbb85d278458e;hpb=fb044a78b11216565ac80ebf148a6e5fa4badd3c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index 1ae8dce07..ef3801ab6 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -185,7 +185,6 @@ const char* ModeParser::Grant(userrec *d,chanrec *chan,int MASK) { if (n->second & MASK) { - ServerInstance->Log(DEBUG,"User already has privilage %d (privset: %d)", MASK, n->second); return ""; } n->second = n->second | MASK; @@ -201,13 +200,8 @@ 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; } - else - { - ServerInstance->Log(DEBUG,"Channel %s not in users joined list", chan->name); - } return ""; } @@ -236,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 ""; @@ -281,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, @@ -290,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 == '+') @@ -302,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; @@ -333,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) @@ -442,7 +450,6 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool /* 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! */ @@ -456,9 +463,10 @@ void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool } 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) == MODEACTION_DENY) + if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == false) { abort = true; break; @@ -571,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; @@ -655,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; } @@ -895,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; } @@ -918,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; } @@ -965,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)); @@ -973,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); }