]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Index Channel::modes and User::modes with the id of the mode instead of its letter
authorAttila Molnar <attilamolnar@hush.com>
Fri, 21 Feb 2014 14:11:24 +0000 (15:11 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 21 Feb 2014 14:11:24 +0000 (15:11 +0100)
include/channels.h
include/users.h
src/channels.cpp
src/users.cpp

index ba2018e97a456065d6eb16203d0aaeeab3c8622e..628f34f9f995a46bb6dee2b81092f77cbf4c9957 100644 (file)
@@ -41,12 +41,10 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel>
        void SetDefaultModes();
 
        /** Modes for the channel.
-        * This is not a null terminated string! It is a bitset where
-        * each item in it represents if a mode is set. For example
-        * for mode +A, index 0. Use modechar-65 to calculate which
-        * field to check.
+        * It is a bitset where each item in it represents if a mode is set.
+        * To see if a mode is set, inspect modes[mh->modeid]
         */
-       std::bitset<64> modes;
+       std::bitset<ModeParser::MODEID_MAX> modes;
 
        /** Remove the given membership from the channel's internal map of
         * memberships and destroy the Membership object.
@@ -113,7 +111,7 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel>
          * @param mode The mode character you wish to query
          * @return True if the custom mode is set, false if otherwise
          */
-       inline bool IsModeSet(ModeHandler* mode) { return modes[mode->GetModeChar()-'A']; }
+       bool IsModeSet(ModeHandler* mode) { return ((mode->GetId() != ModeParser::MODEID_MAX) && (modes[mode->GetId()])); }
        bool IsModeSet(ModeHandler& mode) { return IsModeSet(&mode); }
        bool IsModeSet(ChanModeReference& mode);
 
index c699ebab7551cc83ce17521c833c0edc3912b920..24783b3048e5d63cae84c45d5713def42cee5d0d 100644 (file)
@@ -241,11 +241,11 @@ class CoreExport User : public Extensible
 
        /** The user's mode list.
         * Much love to the STL for giving us an easy to use bitset, saving us RAM.
-        * if (modes[modeletter-65]) is set, then the mode is
-        * set, for example, to work out if mode +s is set, we check the field
-        * User::modes['s'-65] != 0.
+        * if (modes[modeid]) is set, then the mode is set.
+        * For example, to work out if mode +i is set, we check the field
+        * User::modes[invisiblemode->modeid] == true.
         */
-       std::bitset<64> modes;
+       std::bitset<ModeParser::MODEID_MAX> modes;
 
  public:
 
@@ -865,8 +865,7 @@ inline FakeUser* IS_SERVER(User* u)
 
 inline bool User::IsModeSet(ModeHandler* mh)
 {
-       char m = mh->GetModeChar();
-       return (modes[m-65]);
+       return (modes[mh->GetId()]);
 }
 
 inline bool User::IsModeSet(UserModeReference& moderef)
@@ -878,6 +877,5 @@ inline bool User::IsModeSet(UserModeReference& moderef)
 
 inline void User::SetMode(ModeHandler* mh, bool value)
 {
-       char m = mh->GetModeChar();
-       modes[m-65] = value;
+       modes[mh->GetId()] = value;
 }
index 448764e1c46a3c272d6a908a0e321ecb261dc073..99c25fbfc8777cd9c386660b849704c1d0a5d35b 100644 (file)
@@ -48,7 +48,7 @@ Channel::Channel(const std::string &cname, time_t ts)
 
 void Channel::SetMode(ModeHandler* mh, bool on)
 {
-       modes[mh->GetModeChar() - 65] = on;
+       modes[mh->GetId()] = on;
 }
 
 void Channel::SetTopic(User* u, const std::string& ntopic)
@@ -598,12 +598,10 @@ const char* Channel::ChanModes(bool showkey)
        /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
        for(int n = 0; n < 64; n++)
        {
-               if(this->modes[n])
+               ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_CHANNEL);
+               if (mh && IsModeSet(mh))
                {
                        scratch.push_back(n + 65);
-                       ModeHandler* mh = ServerInstance->Modes->FindMode(n+'A', MODETYPE_CHANNEL);
-                       if (!mh)
-                               continue;
 
                        ParamModeBase* pm = mh->IsParameterMode();
                        if (!pm)
index eb91a9cb5d6156c8fbdd29ad2b86f7696b79752b..6545e3b7af5db77636b937a42261b8ae8ba34fb9 100644 (file)
@@ -40,9 +40,8 @@ bool User::IsNoticeMaskSet(unsigned char sm)
 
 bool User::IsModeSet(unsigned char m)
 {
-       if (!isalpha(m))
-               return false;
-       return (modes[m-65]);
+       ModeHandler* mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER);
+       return (mh && modes[mh->GetId()]);
 }
 
 const char* User::FormatModes(bool showparameters)
@@ -53,11 +52,11 @@ const char* User::FormatModes(bool showparameters)
 
        for (unsigned char n = 0; n < 64; n++)
        {
-               if (modes[n])
+               ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
+               if (mh && IsModeSet(mh))
                {
                        data.push_back(n + 65);
-                       ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_USER);
-                       if (showparameters && mh && mh->GetNumParams(true))
+                       if (showparameters && mh->GetNumParams(true))
                        {
                                std::string p = mh->GetUserParameter(this);
                                if (p.length())