]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_codepage.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_codepage.cpp
index 1c3ac02dad4382813bb286aed1e17fc04d44ecdb..45fdb3d834ae02e2b312c2c5b68403cdba7a3dbd 100644 (file)
@@ -2,7 +2,6 @@
  * InspIRCd -- Internet Relay Chat Daemon
  *
  *   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
- *   Copyright (C) 2014 Googolplexed <googol@googolplexed.net>
  *
  * This file is part of InspIRCd.  InspIRCd is free software: you can
  * redistribute it and/or modify it under the terms of the GNU General Public
@@ -62,8 +61,11 @@ class ModuleCodepage
        // The character map which was set before this module was loaded.
        const unsigned char* origcasemap;
 
+       // The name of the character map which was set before this module was loaded.
+       const std::string origcasemapname;
+
        // The IsNick handler which was set before this module was loaded.
-       TR1NS::function<bool(const std::string&)> origisnick;
+       const TR1NS::function<bool(const std::string&)> origisnick;
 
        template <typename T>
        void RehashHashmap(T& hashmap)
@@ -74,6 +76,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();
@@ -81,13 +98,16 @@ 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);
+                       }
                }
        }
 
        void CheckRehash(unsigned char* prevmap)
        {
-               if (!memcmp(prevmap, national_case_insensitive_map, sizeof(origcasemap)))
+               if (!memcmp(prevmap, national_case_insensitive_map, UCHAR_MAX))
                        return;
 
                RehashHashmap(ServerInstance->Users.clientlist);
@@ -98,6 +118,7 @@ class ModuleCodepage
  public:
        ModuleCodepage()
                : origcasemap(national_case_insensitive_map)
+               , origcasemapname(ServerInstance->Config->CaseMapping)
                , origisnick(ServerInstance->IsNick)
        {
        }
@@ -107,8 +128,12 @@ class ModuleCodepage
                ServerInstance->IsNick = origisnick;
                CheckInvalidNick();
 
+               ServerInstance->Config->CaseMapping = origcasemapname;
                national_case_insensitive_map = origcasemap;
+               CheckDuplicateNick();
                CheckRehash(casemap);
+
+               ServerInstance->ISupport.Build();
        }
 
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
@@ -127,7 +152,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());
@@ -185,6 +210,8 @@ class ModuleCodepage
                ServerInstance->Config->CaseMapping = name;
                national_case_insensitive_map = casemap;
                CheckRehash(newcasemap);
+
+               ServerInstance->ISupport.Build();
        }
 
        Version GetVersion() CXX11_OVERRIDE
@@ -206,7 +233,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)