]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_codepage.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_codepage.cpp
index 5858acd977bde4802e72a86fe633afe8e5aa6f59..f299b92fa4b7f843f6dda7b5c050984bd6c10128 100644 (file)
@@ -67,6 +67,9 @@ class ModuleCodepage
        // The IsNick handler which was set before this module was loaded.
        const TR1NS::function<bool(const std::string&)> origisnick;
 
+       // The character set used for the codepage.
+       std::string charset;
+
        template <typename T>
        void RehashHashmap(T& hashmap)
        {
@@ -76,6 +79,21 @@ class ModuleCodepage
                hashmap.swap(newhash);
        }
 
+       void CheckDuplicateNick()
+       {
+               insp::flat_set<std::string, irc::insensitive_swo> duplicates;
+               const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
+               for (UserManager::LocalList::const_iterator iter = list.begin(); iter != list.end(); ++iter)
+               {
+                       LocalUser* user = *iter;
+                       if (user->nick != user->uuid && !duplicates.insert(user->nick).second)
+                       {
+                               user->WriteNumeric(RPL_SAVENICK, user->uuid, "Your nickname is no longer available.");
+                               user->ChangeNick(user->uuid);
+                       }
+               }
+       }
+
        void CheckInvalidNick()
        {
                const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
@@ -83,7 +101,10 @@ class ModuleCodepage
                {
                        LocalUser* user = *iter;
                        if (user->nick != user->uuid && !ServerInstance->IsNick(user->nick))
+                       {
+                               user->WriteNumeric(RPL_SAVENICK, user->uuid, "Your nickname is no longer valid.");
                                user->ChangeNick(user->uuid);
+                       }
                }
        }
 
@@ -112,6 +133,7 @@ class ModuleCodepage
 
                ServerInstance->Config->CaseMapping = origcasemapname;
                national_case_insensitive_map = origcasemap;
+               CheckDuplicateNick();
                CheckRehash(casemap);
 
                ServerInstance->ISupport.Build();
@@ -119,7 +141,9 @@ class ModuleCodepage
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
-               const std::string name = ServerInstance->Config->ConfValue("codepage")->getString("name");
+               ConfigTag* codepagetag = ServerInstance->Config->ConfValue("codepage");
+
+               const std::string name = codepagetag->getString("name");
                if (name.empty())
                        throw ModuleException("<codepage:name> is a required field!");
 
@@ -133,7 +157,7 @@ class ModuleCodepage
                        unsigned char begin = tag->getUInt("begin", tag->getUInt("index", 0), 1, UCHAR_MAX);
                        if (!begin)
                                throw ModuleException("<cpchars> tag without index or begin specified at " + tag->getTagLocation());
-       
+
                        unsigned char end = tag->getUInt("end", begin, 1, UCHAR_MAX);
                        if (begin > end)
                                throw ModuleException("<cpchars:begin> must be lower than <cpchars:end> at " + tag->getTagLocation());
@@ -181,6 +205,7 @@ class ModuleCodepage
                                lower, lower, upper, upper);
                }
 
+               charset = codepagetag->getString("charset");
                std::swap(allowedchars, newallowedchars);
                std::swap(allowedfrontchars, newallowedfrontchars);
                std::swap(casemap, newcasemap);
@@ -195,6 +220,12 @@ class ModuleCodepage
                ServerInstance->ISupport.Build();
        }
 
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
+       {
+               if (!charset.empty())
+                       tokens["CHARSET"] = charset;
+       }
+
        Version GetVersion() CXX11_OVERRIDE
        {
                std::stringstream linkdata;
@@ -214,7 +245,7 @@ class ModuleCodepage
                        if (casemap[i] != i)
                                linkdata << static_cast<unsigned char>(i) << casemap[i] << ',';
 
-               return Version("Provides support for custom 8-bit codepages", VF_COMMON | VF_VENDOR, linkdata.str());
+               return Version("Allows the server administrator to define what characters are allowed in nicknames and how characters should be compared in a case insensitive way.", VF_COMMON | VF_VENDOR, linkdata.str());
        }
 };
 MODULE_INIT(ModuleCodepage)