X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodes%2Fcmode_b.cpp;h=5d709d4b796dbc2649d1f67ac678f6c4e6a2dc55;hb=2d4621658d8daae931b7e44a9c3ecc6a04dcaf4f;hp=57e13159d9138172b847e82490a5f4dcbd061953;hpb=2e6b07ea37c935bd173795cc9e1ad37a4ebececc;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modes/cmode_b.cpp b/src/modes/cmode_b.cpp index 57e13159d..5d709d4b7 100644 --- a/src/modes/cmode_b.cpp +++ b/src/modes/cmode_b.cpp @@ -28,16 +28,25 @@ ModeChannelBan::ModeChannelBan() : ModeHandler('b', 1, 1, true, MODETYPE_CHANNEL ModeAction ModeChannelBan::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding) { int status = cstatus(source, channel); - adding ? parameter = this->AddBan(source, parameter, channel, status) : parameter = this->DelBan(source, parameter, channel, status); + /* Call the correct method depending on wether we're adding or removing the mode */ + if (adding) + { + parameter = this->AddBan(source, parameter, channel, status); + } + else + { + parameter = this->DelBan(source, parameter, channel, status); + } + /* If the method above 'ate' the parameter by reducing it to an empty string, then + * it won't matter wether we return ALLOW or DENY here, as an empty string overrides + * the return value and is always MODEACTION_DENY if the mode is supposed to have + * a parameter. + */ return MODEACTION_ALLOW; } std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *chan,int status) { - BanItem b; - int toomanyexclamation = 0; - int toomanyat = 0; - if ((!user) || (!chan)) { log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter"); @@ -45,32 +54,11 @@ std::string& ModeChannelBan::AddBan(userrec *user,std::string &dest,chanrec *cha return dest; } - for (std::string::iterator i = dest.begin(); i != dest.end(); i++) - { - if ((*i < 32) || (*i > 126)) - { - dest = ""; - return dest; - } - else if (*i == '!') - { - toomanyexclamation++; - } - else if (*i == '@') - { - toomanyat++; - } - } - - if (toomanyexclamation != 1 || toomanyat != 1) - { - /* - * this stops sillyness like n!u!u!u@h, though note that most - * ircds don't actually verify banmask validity. --w00t - */ - dest = ""; + /* Attempt to tidy the mask */ + ModeParser::CleanMask(dest); + /* If the mask was invalid, we exit */ + if (dest == "") return dest; - } long maxbans = GetMaxBans(chan->name); if ((unsigned)chan->bans.size() > (unsigned)maxbans) @@ -121,6 +109,9 @@ std::string& ModeChannelBan::DelBan(userrec *user,std::string& dest,chanrec *cha return dest; } + /* 'Clean' the mask, e.g. nick -> nick!*@* */ + ModeParser::CleanMask(dest); + for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++) { if (!strcasecmp(i->data,dest.c_str()))