mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 11:09:04 -04:00
Switch isupport to use a module-local map instead of an extensible.
This commit is contained in:
parent
5486c0f383
commit
e66555dea3
@ -28,10 +28,12 @@ class ISupportManager final
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/** The generated numerics which are sent to clients. */
|
/** The generated numerics which are sent to clients. */
|
||||||
SimpleExtItem<std::vector<Numeric::Numeric>> cachednumerics;
|
typedef insp::flat_map<ConnectClass::Ptr, std::vector<Numeric::Numeric>> NumericMap;
|
||||||
|
NumericMap cachednumerics;
|
||||||
|
|
||||||
/** The tokens which were generated by the last update. */
|
/** The tokens which were generated by the last update. */
|
||||||
SimpleExtItem<ISupport::TokenMap> cachedtokens;
|
typedef insp::flat_map<ConnectClass::Ptr, ISupport::TokenMap> TokenMap;
|
||||||
|
TokenMap cachedtokens;
|
||||||
|
|
||||||
/** Provider for the ISupport::EventListener event. */
|
/** Provider for the ISupport::EventListener event. */
|
||||||
ISupport::EventProvider isupportevprov;
|
ISupport::EventProvider isupportevprov;
|
||||||
|
@ -44,9 +44,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
ISupportManager::ISupportManager(Module* mod)
|
ISupportManager::ISupportManager(Module* mod)
|
||||||
: cachednumerics(mod, "cached-numerics", ExtensionType::CONNECT_CLASS)
|
: isupportevprov(mod)
|
||||||
, cachedtokens(mod, "cached-tokens", ExtensionType::CONNECT_CLASS)
|
|
||||||
, isupportevprov(mod)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +90,9 @@ void ISupportManager::Build()
|
|||||||
};
|
};
|
||||||
isupportevprov.Call(&ISupport::EventListener::OnBuildISupport, tokens);
|
isupportevprov.Call(&ISupport::EventListener::OnBuildISupport, tokens);
|
||||||
|
|
||||||
insp::flat_map<ConnectClass::Ptr, std::vector<Numeric::Numeric>> diffnumerics;
|
NumericMap diffnumerics;
|
||||||
|
NumericMap newnumerics;
|
||||||
|
TokenMap newtokens;
|
||||||
for (const auto& klass : ServerInstance->Config->Classes)
|
for (const auto& klass : ServerInstance->Config->Classes)
|
||||||
{
|
{
|
||||||
ISupport::TokenMap classtokens = tokens;
|
ISupport::TokenMap classtokens = tokens;
|
||||||
@ -103,20 +103,24 @@ void ISupportManager::Build()
|
|||||||
BuildNumerics(classtokens, numerics);
|
BuildNumerics(classtokens, numerics);
|
||||||
|
|
||||||
// Extract the tokens which have been updated.
|
// Extract the tokens which have been updated.
|
||||||
ISupport::TokenMap* oldtokens = cachedtokens.Get(klass.get());
|
auto oldtokens = cachedtokens.find(klass);
|
||||||
if (oldtokens)
|
if (oldtokens != cachedtokens.end())
|
||||||
{
|
{
|
||||||
// Build the updated numeric diff to send to to existing users.
|
// Build the updated numeric diff to send to to existing users.
|
||||||
ISupport::TokenMap difftokens;
|
ISupport::TokenMap difftokens;
|
||||||
TokenDifference(difftokens, *oldtokens, classtokens);
|
TokenDifference(difftokens, oldtokens->second, classtokens);
|
||||||
BuildNumerics(difftokens, diffnumerics[klass]);
|
BuildNumerics(difftokens, diffnumerics[klass]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the new ISUPPORT values.
|
// Store the new ISUPPORT values.
|
||||||
cachednumerics.Set(klass.get(), numerics);
|
newnumerics[klass] = numerics;
|
||||||
cachedtokens.Set(klass.get(), classtokens);
|
newtokens[klass] = classtokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply the new ISUPPORT values.
|
||||||
|
cachednumerics.swap(newnumerics);
|
||||||
|
cachedtokens.swap(newtokens);
|
||||||
|
|
||||||
if (!diffnumerics.empty())
|
if (!diffnumerics.empty())
|
||||||
{
|
{
|
||||||
for (LocalUser* user : ServerInstance->Users.GetLocalUsers())
|
for (LocalUser* user : ServerInstance->Users.GetLocalUsers())
|
||||||
@ -156,10 +160,10 @@ void ISupportManager::BuildNumerics(ISupport::TokenMap& tokens, std::vector<Nume
|
|||||||
|
|
||||||
void ISupportManager::SendTo(LocalUser* user)
|
void ISupportManager::SendTo(LocalUser* user)
|
||||||
{
|
{
|
||||||
auto numerics = cachednumerics.Get(user->GetClass().get());
|
auto numerics = cachednumerics.find(user->GetClass());
|
||||||
if (!numerics)
|
if (numerics == cachednumerics.end())
|
||||||
return; // Should never happen.
|
return; // Should never happen.
|
||||||
|
|
||||||
for (const auto& numeric : *numerics)
|
for (const auto& numeric : numerics->second)
|
||||||
user->WriteNumeric(numeric);
|
user->WriteNumeric(numeric);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user