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:
|
||||
/** 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. */
|
||||
SimpleExtItem<ISupport::TokenMap> cachedtokens;
|
||||
typedef insp::flat_map<ConnectClass::Ptr, ISupport::TokenMap> TokenMap;
|
||||
TokenMap cachedtokens;
|
||||
|
||||
/** Provider for the ISupport::EventListener event. */
|
||||
ISupport::EventProvider isupportevprov;
|
||||
|
@ -44,9 +44,7 @@ namespace
|
||||
}
|
||||
|
||||
ISupportManager::ISupportManager(Module* mod)
|
||||
: cachednumerics(mod, "cached-numerics", ExtensionType::CONNECT_CLASS)
|
||||
, cachedtokens(mod, "cached-tokens", ExtensionType::CONNECT_CLASS)
|
||||
, isupportevprov(mod)
|
||||
: isupportevprov(mod)
|
||||
{
|
||||
}
|
||||
|
||||
@ -92,7 +90,9 @@ void ISupportManager::Build()
|
||||
};
|
||||
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)
|
||||
{
|
||||
ISupport::TokenMap classtokens = tokens;
|
||||
@ -103,20 +103,24 @@ void ISupportManager::Build()
|
||||
BuildNumerics(classtokens, numerics);
|
||||
|
||||
// Extract the tokens which have been updated.
|
||||
ISupport::TokenMap* oldtokens = cachedtokens.Get(klass.get());
|
||||
if (oldtokens)
|
||||
auto oldtokens = cachedtokens.find(klass);
|
||||
if (oldtokens != cachedtokens.end())
|
||||
{
|
||||
// Build the updated numeric diff to send to to existing users.
|
||||
ISupport::TokenMap difftokens;
|
||||
TokenDifference(difftokens, *oldtokens, classtokens);
|
||||
TokenDifference(difftokens, oldtokens->second, classtokens);
|
||||
BuildNumerics(difftokens, diffnumerics[klass]);
|
||||
}
|
||||
|
||||
// Apply the new ISUPPORT values.
|
||||
cachednumerics.Set(klass.get(), numerics);
|
||||
cachedtokens.Set(klass.get(), classtokens);
|
||||
// Store the new ISUPPORT values.
|
||||
newnumerics[klass] = numerics;
|
||||
newtokens[klass] = classtokens;
|
||||
}
|
||||
|
||||
// Apply the new ISUPPORT values.
|
||||
cachednumerics.swap(newnumerics);
|
||||
cachedtokens.swap(newtokens);
|
||||
|
||||
if (!diffnumerics.empty())
|
||||
{
|
||||
for (LocalUser* user : ServerInstance->Users.GetLocalUsers())
|
||||
@ -156,10 +160,10 @@ void ISupportManager::BuildNumerics(ISupport::TokenMap& tokens, std::vector<Nume
|
||||
|
||||
void ISupportManager::SendTo(LocalUser* user)
|
||||
{
|
||||
auto numerics = cachednumerics.Get(user->GetClass().get());
|
||||
if (!numerics)
|
||||
auto numerics = cachednumerics.find(user->GetClass());
|
||||
if (numerics == cachednumerics.end())
|
||||
return; // Should never happen.
|
||||
|
||||
for (const auto& numeric : *numerics)
|
||||
for (const auto& numeric : numerics->second)
|
||||
user->WriteNumeric(numeric);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user