]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Replace hardcoded mode letters, part 3
authorattilamolnar <attilamolnar@hush.com>
Tue, 18 Jun 2013 17:10:07 +0000 (19:10 +0200)
committerattilamolnar <attilamolnar@hush.com>
Fri, 19 Jul 2013 17:40:04 +0000 (19:40 +0200)
This changes most remaining User::IsModeSet() calls to use ModeReferences for modes that were created by other modules or the core

include/usermanager.h
include/users.h
src/channels.cpp
src/commands/cmd_lusers.cpp
src/commands/cmd_wallops.cpp
src/commands/cmd_who.cpp
src/modules/m_alias.cpp
src/modules/m_operprefix.cpp
src/modules/m_regonlycreate.cpp
src/usermanager.cpp
src/users.cpp

index 50dac27bf9b267754ae2330fcb34a1652030d314..c6745ace626d12f2347c6caeccbe881e3b351884 100644 (file)
@@ -161,10 +161,6 @@ class CoreExport UserManager
         */
        unsigned int LocalUserCount() const { return (this->local_count - this->UnregisteredUserCount()); }
 
-       /** Number of users with a certain mode set on them
-        */
-       int ModeCount(const char mode);
-
        /** Send a server notice to all local users
         * @param text The text format string to send
         * @param ... The format arguments
index 0e660d0982e1360f2856c4e9b1e8b17f8c6d7f6d..40ba173320a2070a84e4bb68df030c03184582d6 100644 (file)
@@ -436,7 +436,6 @@ class CoreExport User : public Extensible
         * @param m The user mode
         * @param value On or off setting of the mode
         */
-       void SetMode(unsigned char m, bool value);
        void SetMode(ModeHandler* mh, bool value);
        void SetMode(ModeHandler& mh, bool value) { SetMode(&mh, value); }
 
index 505ef479aaf09da2e74d2c05fd24244f6fe76d58..e9e2a30209df6c69e3cbcd56b0735e84c756e566 100644 (file)
@@ -36,6 +36,7 @@ namespace
        ChanModeReference limitmode(NULL, "limit");
        ChanModeReference secretmode(NULL, "secret");
        ChanModeReference privatemode(NULL, "private");
+       UserModeReference invisiblemode(NULL, "invisible");
 }
 
 Channel::Channel(const std::string &cname, time_t ts)
@@ -683,7 +684,7 @@ void Channel::UserList(User *user)
        {
                if (i->first->quitting)
                        continue;
-               if ((!has_user) && (i->first->IsModeSet('i')))
+               if ((!has_user) && (i->first->IsModeSet(invisiblemode)))
                {
                        /*
                         * user is +i, and source not on the channel, does not show
index c594a0e2434144180bdda99ae1e8910c67ce3e4f..c1f35592a04b5691aaf08349b4729749aa5a7ece 100644 (file)
@@ -26,10 +26,10 @@ struct LusersCounters
        unsigned int max_global;
        unsigned int invisible;
 
-       LusersCounters()
+       LusersCounters(unsigned int inv)
                : max_local(ServerInstance->Users->LocalUserCount())
                , max_global(ServerInstance->Users->RegisteredUserCount())
-               , invisible(ServerInstance->Users->ModeCount('i'))
+               , invisible(inv)
        {
        }
 
@@ -128,13 +128,29 @@ public:
 
 class ModuleLusers : public Module
 {
+       UserModeReference invisiblemode;
        LusersCounters counters;
        CommandLusers cmd;
        InvisibleWatcher mw;
 
+       unsigned int CountInvisible()
+       {
+               unsigned int c = 0;
+               for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); ++i)
+               {
+                       User* u = i->second;
+                       if (u->IsModeSet(invisiblemode))
+                               c++;
+               }
+               return c;
+       }
+
  public:
        ModuleLusers()
-               : cmd(this, counters), mw(this, counters.invisible)
+               : invisiblemode(this, "invisible")
+               , counters(CountInvisible())
+               , cmd(this, counters)
+               , mw(this, counters.invisible)
        {
        }
 
@@ -149,13 +165,13 @@ class ModuleLusers : public Module
        void OnPostConnect(User* user)
        {
                counters.UpdateMaxUsers();
-               if (user->IsModeSet('i'))
+               if (user->IsModeSet(invisiblemode))
                        counters.invisible++;
        }
 
        void OnUserQuit(User* user, const std::string& message, const std::string& oper_message)
        {
-               if (user->IsModeSet('i'))
+               if (user->IsModeSet(invisiblemode))
                        counters.invisible--;
        }
 
index 3cd8abc42bb9daa628c5b6649516e5cf16fbbdd5..e0e832ff7a413d6ecdda2863f9d3a861e36f585f 100644 (file)
  */
 class CommandWallops : public Command
 {
+       UserModeReference wallopsmode;
+
  public:
        /** Constructor for wallops.
         */
-       CommandWallops ( Module* parent) : Command(parent,"WALLOPS",1,1) { flags_needed = 'o'; syntax = "<any-text>"; }
+       CommandWallops(Module* parent)
+               : Command(parent, "WALLOPS", 1, 1)
+               , wallopsmode(parent, "wallops")
+       {
+               flags_needed = 'o';
+               syntax = "<any-text>";
+       }
+
        /** Handle command.
         * @param parameters The parameters to the comamnd
         * @param pcnt The number of parameters passed to teh command
@@ -53,7 +62,7 @@ CmdResult CommandWallops::Handle (const std::vector<std::string>& parameters, Us
        for (LocalUserList::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
                User* t = *i;
-               if (t->IsModeSet('w'))
+               if (t->IsModeSet(wallopsmode))
                        user->WriteTo(t,wallop);
        }
 
index a78f03793e167c0a56667cb2361f0340ab35840b..3023939276502eb8316f56b0df68aefc3ea3de5c 100644 (file)
@@ -41,6 +41,7 @@ class CommandWho : public Command
        bool opt_time;
        ChanModeReference secretmode;
        ChanModeReference privatemode;
+       UserModeReference invisiblemode;
 
        Channel* get_first_visible_channel(User *u)
        {
@@ -61,6 +62,7 @@ class CommandWho : public Command
                : Command(parent, "WHO", 1)
                , secretmode(parent, "secret")
                , privatemode(parent, "private")
+               , invisiblemode(parent, "invisible")
        {
                syntax = "<server>|<nickname>|<channel>|<realname>|<host>|0 [ohurmMiaplf]";
        }
@@ -336,7 +338,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                continue;
 
                                        /* If we're not inside the channel, hide +i users */
-                                       if (i->first->IsModeSet('i') && !inside && !user->HasPrivPermission("users/auspex"))
+                                       if (i->first->IsModeSet(invisiblemode) && !inside && !user->HasPrivPermission("users/auspex"))
                                                continue;
                                }
 
@@ -358,7 +360,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                {
                                        if (!user->SharesChannelWith(oper))
                                        {
-                                               if (usingwildcards && (!oper->IsModeSet('i')) && (!user->HasPrivPermission("users/auspex")))
+                                               if (usingwildcards && (!oper->IsModeSet(invisiblemode)) && (!user->HasPrivPermission("users/auspex")))
                                                        continue;
                                        }
 
@@ -374,7 +376,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                {
                                        if (!user->SharesChannelWith(i->second))
                                        {
-                                               if (usingwildcards && (i->second->IsModeSet('i')) && (!user->HasPrivPermission("users/auspex")))
+                                               if (usingwildcards && (i->second->IsModeSet(invisiblemode)) && (!user->HasPrivPermission("users/auspex")))
                                                        continue;
                                        }
 
index 507a935339bd21d7fc0461634ea7df2c28fe5ed4..73e3bfd46e682b98dba17006cc74077df42a26ce 100644 (file)
@@ -67,6 +67,7 @@ class ModuleAlias : public Module
 
        /* whether or not +B users are allowed to use fantasy commands */
        bool AllowBots;
+       UserModeReference botmode;
 
        void ReadAliases()
        {
@@ -96,6 +97,11 @@ class ModuleAlias : public Module
        }
 
  public:
+       ModuleAlias()
+               : botmode(this, "bot")
+       {
+       }
+
        void init() CXX11_OVERRIDE
        {
                ReadAliases();
@@ -187,7 +193,7 @@ class ModuleAlias : public Module
                }
 
                /* Stop here if the user is +B and allowbot is set to no. */
-               if (!AllowBots && user->IsModeSet('B'))
+               if (!AllowBots && user->IsModeSet(botmode))
                {
                        return;
                }
index 1f820c74570f36ac6bb864dd7aea1bc5127a7b79..643f09db92aad809526d3ecf1b93d47ef22460c1 100644 (file)
@@ -68,10 +68,12 @@ class ModuleOperPrefixMode : public Module
 {
        OperPrefixMode opm;
        HideOperWatcher hideoperwatcher;
+       UserModeReference hideopermode;
 
  public:
        ModuleOperPrefixMode()
                : opm(this), hideoperwatcher(this)
+               , hideopermode(this, "hideoper")
        {
        }
 
@@ -92,7 +94,7 @@ class ModuleOperPrefixMode : public Module
 
        ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
        {
-               if ((user->IsOper()) && (user->IsModeSet('H')))
+               if ((user->IsOper()) && (!user->IsModeSet(hideopermode)))
                        privs.push_back('y');
                return MOD_RES_PASSTHRU;
        }
@@ -101,7 +103,8 @@ class ModuleOperPrefixMode : public Module
        {
                std::vector<std::string> modechange;
                modechange.push_back("");
-               modechange.push_back(add ? "+y" : "-y");
+               modechange.push_back(add ? "+" : "-");
+               modechange[1].push_back(opm.GetModeChar());
                modechange.push_back(user->nick);
                for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
                {
@@ -112,7 +115,7 @@ class ModuleOperPrefixMode : public Module
 
        void OnPostOper(User* user, const std::string& opername, const std::string& opertype) CXX11_OVERRIDE
        {
-               if (IS_LOCAL(user) && (!user->IsModeSet('H')))
+               if (IS_LOCAL(user) && (!user->IsModeSet(hideopermode)))
                        SetOperPrefix(user, true);
        }
 
index 84058fbfa6589fb92c56a518783209031042e4bf..6b6e059dfa6c038135ccb0e13d89aa273d36110b 100644 (file)
 
 class ModuleRegOnlyCreate : public Module
 {
+       UserModeReference regusermode;
+
  public:
+       ModuleRegOnlyCreate()
+               : regusermode(this, "u_registered")
+       {
+       }
+
        void init() CXX11_OVERRIDE
        {
                Implementation eventlist[] = { I_OnUserPreJoin };
@@ -40,7 +47,7 @@ class ModuleRegOnlyCreate : public Module
                if (user->IsOper())
                        return MOD_RES_PASSTHRU;
 
-               if (user->IsModeSet('r'))
+               if (user->IsModeSet(regusermode))
                        return MOD_RES_PASSTHRU;
 
                const AccountExtItem* ext = GetAccountExtItem();
index e7d1fd05c2bb888eed24d908e7ab92f80660236a..15e59c8000bd06d056015251acbef645723cad35 100644 (file)
@@ -316,19 +316,6 @@ void UserManager::ServerNoticeAll(const char* text, ...)
        }
 }
 
-/* return how many users have a given mode e.g. 'a' */
-int UserManager::ModeCount(const char mode)
-{
-       int c = 0;
-       for(user_hash::iterator i = clientlist->begin(); i != clientlist->end(); ++i)
-       {
-               User* u = i->second;
-               if (u->modes[mode-65])
-                       c++;
-       }
-       return c;
-}
-
 void UserManager::GarbageCollect()
 {
        // Reset the already_sent IDs so we don't wrap it around and drop a message
index 2f90a7970b5f42f21eb263bbd88f5076917829b8..f4055d464dc6769472c99f5b5284ffb39164b242 100644 (file)
@@ -45,13 +45,6 @@ bool User::IsModeSet(unsigned char m)
        return (modes[m-65]);
 }
 
-void User::SetMode(unsigned char m, bool value)
-{
-       if (!isalpha(m))
-               return;
-       modes[m-65] = value;
-}
-
 const char* User::FormatModes(bool showparameters)
 {
        static std::string data;