]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move GetPrefixChar() from Channel to Membership
authorAttila Molnar <attilamolnar@hush.com>
Fri, 14 Feb 2014 11:15:00 +0000 (12:15 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 14 Feb 2014 11:15:00 +0000 (12:15 +0100)
include/channels.h
include/membership.h
src/channels.cpp
src/commands/cmd_who.cpp
src/commands/cmd_whois.cpp
src/modules/m_check.cpp

index 5109c046318f216168d279632d32c3e5ea1dfbb9..daf8be9e2a2e4ac561705a19191b005fc3ab0b0b 100644 (file)
@@ -304,19 +304,6 @@ class CoreExport Channel : public Extensible, public InviteBase<Channel>
         */
        void UserList(User *user);
 
-       /** Get a users prefix on this channel in a string.
-        * @param user The user to look up
-        * @return A character array containing the prefix string.
-        * Unlike GetStatus and GetStatusFlags which will only return the
-        * core specified modes @, % and + (op, halfop and voice), GetPrefixChar
-        * will also return module-defined prefixes. If the user has to prefix,
-        * an empty but non-null string is returned. If the user has multiple
-        * prefixes, the highest is returned. If you do not recognise the prefix
-        * character you can get, you can deal with it in a 'proprtional' manner
-        * compared to known prefixes, using GetPrefixValue().
-        */
-       const char* GetPrefixChar(User *user);
-
        /** Return all of a users mode prefixes into a char* string.
         * @param user The user to look up
         * @return A list of all prefix characters. The prefixes will always
index d98b54731884cd31d12f641e9ddd42c6a6be0a5f..c6b0bf14ae52b2418ab01b7e0c89c001646702c3 100644 (file)
@@ -43,6 +43,15 @@ class CoreExport Membership : public Extensible, public intrusive_list_node<Memb
         * @return True if a change was made
         */
        bool SetPrefix(PrefixMode* mh, bool adding);
+
+       /** Get the highest prefix this user has on the channel
+        * @return A character containing the highest prefix.
+        * If the user has no prefix, 0 is returned. If the user has multiple prefixes,
+        * the highest is returned. If you do not recognise the prefix character you
+        * can get, you can deal with it in a 'proportional' manner compared to known
+        * prefixes, using GetPrefixValue().
+        */
+       char GetPrefixChar() const;
 };
 
 template <typename T>
index 7d8bff661311ff92fc7a9746be3ed034ab1f6ebc..c47bcb1194391c9ad8ff4d414536fd9fe261c153 100644 (file)
@@ -686,10 +686,13 @@ void Channel::UserList(User *user)
                        continue;
                }
 
-               prefixlist = this->GetPrefixChar(i->first);
+               Membership* memb = i->second;
+
+               prefixlist.clear();
+               prefixlist.push_back(memb->GetPrefixChar());
                nick = i->first->nick;
 
-               FOREACH_MOD(OnNamesListItem, (user, i->second, prefixlist, nick));
+               FOREACH_MOD(OnNamesListItem, (user, memb, prefixlist, nick));
 
                /* Nick was nuked, a module wants us to skip it */
                if (nick.empty())
@@ -723,23 +726,18 @@ void Channel::UserList(User *user)
  * % for halfop etc. If the user has several modes set, the highest mode
  * the user has must be returned.
  */
-const char* Channel::GetPrefixChar(User *user)
+char Membership::GetPrefixChar() const
 {
-       static char pf[2] = {0, 0};
-       *pf = 0;
+       char pf = 0;
        unsigned int bestrank = 0;
 
-       UserMembIter m = userlist.find(user);
-       if (m != userlist.end())
+       for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
-               for(unsigned int i=0; i < m->second->modes.length(); i++)
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+               if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
                {
-                       PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(m->second->modes[i]);
-                       if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
-                       {
-                               bestrank = mh->GetPrefixRank();
-                               pf[0] = mh->GetPrefix();
-                       }
+                       bestrank = mh->GetPrefixRank();
+                       pf = mh->GetPrefix();
                }
        }
        return pf;
index d7084d53b2297ad1203ce465199496b2755d1d2b..2be724e91581604602528904137e6af4a70e3d51 100644 (file)
@@ -224,7 +224,7 @@ void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms,
        }
 
        if (memb)
-               wholine.append(memb->chan->GetPrefixChar(u));
+               wholine.push_back(memb->GetPrefixChar());
 
        wholine.append(" :0 " + u->fullname);
 
index 29322f8021b122a6c1e3a4502389a5ebd485305a..61a4ad891f3112c5a51aa3f2e9f2a479dca0eade 100644 (file)
@@ -65,12 +65,16 @@ std::string CommandWhois::ChannelList(User* source, User* dest, bool spy)
 
        for (UCListIter i = dest->chans.begin(); i != dest->chans.end(); i++)
        {
-               Channel* c = (*i)->chan;
+               Membership* memb = *i;
+               Channel* c = memb->chan;
                /* If the target is the sender, neither +p nor +s is set, or
                 * the channel contains the user, it is not a spy channel
                 */
                if (spy != (source == dest || !(c->IsModeSet(privatemode) || c->IsModeSet(secretmode)) || c->HasUser(source)))
-                       list.append(c->GetPrefixChar(dest)).append(c->name).append(" ");
+               {
+                       list.push_back(memb->GetPrefixChar());
+                       list.append(c->name).push_back(' ');
+               }
        }
 
        return list;
index c72f88faa404f1a4436056719511406181c390f5..1fa7aa3e2cf06eb907345846aeaa58265c4c0f7b 100644 (file)
@@ -192,8 +192,10 @@ class CommandCheck : public Command
 
                        for (UCListIter i = targuser->chans.begin(); i != targuser->chans.end(); i++)
                        {
-                               Channel* c = (*i)->chan;
-                               chliststr.append(c->GetPrefixChar(targuser)).append(c->name).append(" ");
+                               Membership* memb = *i;
+                               Channel* c = memb->chan;
+                               chliststr.push_back(memb->GetPrefixChar());
+                               chliststr.append(c->name).push_back(' ');
                        }
 
                        std::stringstream dump(chliststr);