Don't sync xlines defined in the config and expire them on rehash.

Closes #1427.
This commit is contained in:
Peter Powell 2018-09-21 20:54:05 +01:00
parent f020429fd3
commit 876b1ae4e2
3 changed files with 36 additions and 2 deletions

View File

@ -50,7 +50,12 @@ class CoreExport XLine : public classbase
* @param t The line type, should be set by the derived class constructor
*/
XLine(time_t s_time, long d, std::string src, std::string re, const std::string &t)
: set_time(s_time), duration(d), source(src), reason(re), type(t)
: set_time(s_time)
, duration(d)
, source(src)
, reason(re)
, type(t)
, from_config(false)
{
expiry = set_time + duration;
}
@ -140,6 +145,9 @@ class CoreExport XLine : public classbase
*/
const std::string type;
// Whether this XLine was loaded from the server config.
bool from_config;
virtual bool IsBurstable();
};
@ -523,4 +531,7 @@ class CoreExport XLineManager
* @param stats Stats context
*/
void InvokeStats(const std::string& type, unsigned int numeric, Stats::Context& stats);
/** Clears any XLines which were added by the server configuration. */
void ClearConfigLines();
};

View File

@ -108,6 +108,7 @@ static void ReadXLine(ServerConfig* conf, const std::string& tag, const std::str
throw CoreException("<"+tag+":"+key+"> missing at " + ctag->getTagLocation());
std::string reason = ctag->getString("reason", "<Config>");
XLine* xl = make->Generate(ServerInstance->Time(), 0, "<Config>", reason, mask);
xl->from_config = true;
if (!ServerInstance->XLines->AddLine(xl, NULL))
delete xl;
}
@ -446,6 +447,7 @@ void ServerConfig::Fill()
SocketEngine::Close(socktest);
}
ServerInstance->XLines->ClearConfigLines();
ReadXLine(this, "badip", "ipmask", ServerInstance->XLines->GetFactory("Z"));
ReadXLine(this, "badnick", "nick", ServerInstance->XLines->GetFactory("Q"));
ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K"));

View File

@ -518,7 +518,7 @@ void XLine::Apply(User* u)
bool XLine::IsBurstable()
{
return true;
return !from_config;
}
void XLine::DefaultApply(User* u, const std::string &line, bool bancache)
@ -747,3 +747,24 @@ XLineFactory* XLineManager::GetFactory(const std::string &type)
return n->second;
}
void XLineManager::ClearConfigLines()
{
// Nothing to do.
if (lookup_lines.empty())
return;
ServerInstance->SNO->WriteToSnoMask('x', "Server rehashing; expiring lines defined in the server config ...");
for (ContainerIter type = lookup_lines.begin(); type != lookup_lines.end(); ++type)
{
for (LookupIter xline = type->second.begin(); xline != type->second.end(); )
{
// We cache this to avoid iterator invalidation.
LookupIter cachedxline = xline++;
if (cachedxline->second->from_config)
{
ExpireLine(type, cachedxline);
}
}
}
}