virtual void OnBackgroundTimer(time_t curtime) { for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();) { if (curtime > i->expire) { std::string chan = i->channel; std::string mask = i->mask; Channel* cr = ServerInstance->FindChan(chan); i = TimedBanList.erase(i); if (cr) { std::vector<std::string> setban; setban.push_back(chan); setban.push_back("-b"); setban.push_back(mask); CUList empty; std::string expiry = "*** Timed ban on " + chan + " expired."; cr->WriteAllExcept(ServerInstance->FakeClient, true, '@', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str()); ServerInstance->PI->SendChannelNotice(cr, '@', expiry); if (ServerInstance->Config->AllowHalfop) { cr->WriteAllExcept(ServerInstance->FakeClient, true, '%', empty, "NOTICE %s :%s", cr->name.c_str(), expiry.c_str()); ServerInstance->PI->SendChannelNotice(cr, '%', expiry); } ServerInstance->SendMode(setban, ServerInstance->FakeClient); ServerInstance->PI->SendMode(chan, ServerInstance->Modes->GetLastParseParams(), ServerInstance->Modes->GetLastParseTranslate()); } } else ++i; } }
void OnBackgroundTimer(time_t curtime) override { timedbans expired; for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end();) { if (curtime > i->expire) { expired.push_back(*i); i = TimedBanList.erase(i); } else ++i; } for (timedbans::iterator i = expired.begin(); i != expired.end(); i++) { std::string mask = i->mask; Channel* cr = i->chan; { const std::string expiry = "*** Timed ban on " + cr->name + " expired."; // If halfop is loaded, send notice to halfops and above, otherwise send to ops and above PrefixMode* mh = ServerInstance->Modes.FindPrefixMode('h'); char pfxchar = (mh && mh->name == "halfop") ? mh->GetPrefix() : '@'; ClientProtocol::Messages::Privmsg notice(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, cr, expiry, MSG_NOTICE); cr->Write(ServerInstance->GetRFCEvents().privmsg, notice, pfxchar); ServerInstance->PI->SendChannelNotice(cr, pfxchar, expiry); Modes::ChangeList setban; setban.push_remove(ServerInstance->Modes.FindMode('b', MODETYPE_CHANNEL), mask); ServerInstance->Modes.Process(ServerInstance->FakeClient, cr, NULL, setban); } } }
virtual int OnDelBan(User* source, Channel* chan, const std::string &banmask) { irc::string listitem = banmask.c_str(); irc::string thischan = chan->name.c_str(); for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); i++) { irc::string target = i->mask.c_str(); irc::string tchan = i->channel.c_str(); if ((listitem == target) && (tchan == thischan)) { TimedBanList.erase(i); break; } } return 0; }
virtual void OnBackgroundTimer(time_t curtime) { bool again = true; while (again) { again = false; for (timedbans::iterator i = TimedBanList.begin(); i < TimedBanList.end(); i++) { if (curtime > i->expire) { chanrec* cr = ServerInstance->FindChan(i->channel); again = true; if (cr) { cr->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :Timed ban on %s expired.", cr->name, i->mask.c_str()); const char *setban[3]; setban[0] = i->channel.c_str(); setban[1] = "-b"; setban[2] = i->mask.c_str(); // kludge alert! // ::SendMode expects a userrec* to send the numeric replies // back to, so we create it a fake user that isnt in the user // hash and set its descriptor to FD_MAGIC_NUMBER so the data // falls into the abyss :p userrec* temp = new userrec(ServerInstance); temp->SetFd(FD_MAGIC_NUMBER); /* FIX: Send mode remotely*/ std::deque<std::string> n; n.push_back(setban[0]); n.push_back("-b"); n.push_back(setban[2]); ServerInstance->SendMode(setban,3,temp); Event rmode((char *)&n, NULL, "send_mode"); rmode.Send(ServerInstance); DELETE(temp); } else { /* Where the hell did our channel go?! */ TimedBanList.erase(i); } // we used to delete the item here, but we dont need to as the servermode above does it for us, break; } } } }
void AfterMode(User* source, User* dest, Channel* chan, const std::string& banmask, bool adding) { if (adding) return; for (timedbans::iterator i = TimedBanList.begin(); i != TimedBanList.end(); ++i) { if (i->chan != chan) continue; const std::string& target = i->mask; if (irc::equals(banmask, target)) { TimedBanList.erase(i); break; } } }
void OnChannelDelete(Channel* chan) override { // Remove all timed bans affecting the channel from internal bookkeeping TimedBanList.erase(std::remove_if(TimedBanList.begin(), TimedBanList.end(), ChannelMatcher(chan)), TimedBanList.end()); }