X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_timedbans.cpp;h=497ac2569d94ad80528656a1c4a1de345ab339d4;hb=7b5703b9a22e176ef6a47b405f2b0d5ce122df0a;hp=663a43f2fec560958eb6dea3180b0136ecc0894f;hpb=fcacc8e0306382bc3f938073092c3729d77e2b41;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_timedbans.cpp b/src/modules/m_timedbans.cpp index 663a43f2f..497ac2569 100644 --- a/src/modules/m_timedbans.cpp +++ b/src/modules/m_timedbans.cpp @@ -62,29 +62,33 @@ class CommandTban : public Command user->WriteNumeric(482, "%s %s :You do not have permission to set bans on this channel", user->nick.c_str(), channel->name.c_str()); return CMD_FAILURE; - } - if (!ServerInstance->IsValidMask(parameters[2])) - { - user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban mask"); - return CMD_FAILURE; - } + } + TimedBan T; std::string channelname = parameters[0]; long duration = ServerInstance->Duration(parameters[1]); unsigned long expire = duration + ServerInstance->Time(); if (duration < 1) { - user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid ban time"); + user->WriteServ("NOTICE "+user->nick+" :Invalid ban time"); return CMD_FAILURE; } std::string mask = parameters[2]; std::vector setban; setban.push_back(parameters[0]); setban.push_back("+b"); - setban.push_back(parameters[2]); - // use CallCommandHandler to make it so that the user sets the mode + bool isextban = ((mask.size() > 2) && (mask[1] == ':')); + if (!isextban && !ServerInstance->IsValidMask(mask)) + mask.append("!*@*"); + if ((mask.length() > 250) || (!ServerInstance->IsValidMask(mask) && !isextban)) + { + user->WriteServ("NOTICE "+user->nick+" :Invalid ban mask"); + return CMD_FAILURE; + } + setban.push_back(mask); + // use CallHandler to make it so that the user sets the mode // themselves - ServerInstance->CallCommandHandler("MODE",setban,user); + ServerInstance->Parser->CallHandler("MODE",setban,user); for (BanList::iterator i = channel->bans.begin(); i != channel->bans.end(); i++) if (!strcasecmp(i->data.c_str(), mask.c_str())) goto found; @@ -95,7 +99,12 @@ found: T.mask = mask; T.expire = expire + (IS_REMOTE(user) ? 5 : 0); TimedBanList.push_back(T); - channel->WriteAllExcept(ServerInstance->FakeClient, true, '@', tmp, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name.c_str(), user->nick.c_str(), mask.c_str(), duration); + + // If halfop is loaded, send notice to halfops and above, otherwise send to ops and above + ModeHandler* mh = ServerInstance->Modes->FindMode('h', MODETYPE_CHANNEL); + char pfxchar = (mh && mh->name == "halfop") ? '%' : '@'; + + channel->WriteAllExcept(ServerInstance->FakeClient, true, pfxchar, tmp, "NOTICE %s :%s added a timed ban on %s lasting for %ld seconds.", channel->name.c_str(), user->nick.c_str(), mask.c_str(), duration); return CMD_SUCCESS; } @@ -112,15 +121,13 @@ class ModuleTimedBans : public Module ModuleTimedBans() : cmd(this) { - ServerInstance->AddCommand(&cmd); - TimedBanList.clear(); - Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer }; - ServerInstance->Modules->Attach(eventlist, this, 2); } - virtual ~ModuleTimedBans() + void init() { - TimedBanList.clear(); + ServerInstance->Modules->AddService(cmd); + Implementation eventlist[] = { I_OnDelBan, I_OnBackgroundTimer }; + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } virtual ModResult OnDelBan(User* source, Channel* chan, const std::string &banmask)