summaryrefslogtreecommitdiff
path: root/src/modules/m_nationalchars.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/m_nationalchars.cpp')
-rw-r--r--src/modules/m_nationalchars.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp
index 0650cb3d0..f77899ad4 100644
--- a/src/modules/m_nationalchars.cpp
+++ b/src/modules/m_nationalchars.cpp
@@ -223,11 +223,40 @@ class ModuleNationalChars : public Module
caller1<bool, const std::string&> rememberer;
bool forcequit;
const unsigned char * lowermap_rememberer;
+ unsigned char prev_map[256];
+
+ template <typename T>
+ void RehashHashmap(T& hashmap)
+ {
+ T newhash(hashmap.bucket_count());
+ for (typename T::const_iterator i = hashmap.begin(); i != hashmap.end(); ++i)
+ newhash.insert(std::make_pair(i->first, i->second));
+ hashmap.swap(newhash);
+ }
+
+ void CheckRehash()
+ {
+ // See if anything changed
+ if (!memcmp(prev_map, national_case_insensitive_map, sizeof(prev_map)))
+ return;
+
+ memcpy(prev_map, national_case_insensitive_map, sizeof(prev_map));
+
+ RehashHashmap(ServerInstance->Users.clientlist);
+ RehashHashmap(ServerInstance->Users.uuidlist);
+ RehashHashmap(ServerInstance->chanlist);
+
+ // The OnGarbageCollect() method in m_watch rebuilds the hashmap used by it
+ Module* mod = ServerInstance->Modules->Find("m_watch.so");
+ if (mod)
+ mod->OnGarbageCollect();
+ }
public:
ModuleNationalChars()
: rememberer(ServerInstance->IsNick), lowermap_rememberer(national_case_insensitive_map)
{
+ memcpy(prev_map, national_case_insensitive_map, sizeof(prev_map));
}
void init() CXX11_OVERRIDE
@@ -254,6 +283,7 @@ class ModuleNationalChars : public Module
loadtables(charset, tables, 8, 5);
forcequit = tag->getBool("forcequit");
CheckForceQuit("National character set changed");
+ CheckRehash();
}
void CheckForceQuit(const char * message)
@@ -276,6 +306,7 @@ class ModuleNationalChars : public Module
ServerInstance->IsNick = rememberer;
national_case_insensitive_map = lowermap_rememberer;
CheckForceQuit("National characters module unloaded");
+ CheckRehash();
}
Version GetVersion() CXX11_OVERRIDE