Move GetPrefixChar() from Channel to Membership

This commit is contained in:
Attila Molnar 2014-02-14 12:15:00 +01:00
parent 51b5f06c48
commit 74ccc28da3
6 changed files with 32 additions and 32 deletions

View 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

View 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>

View 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;

View 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);

View 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;

View 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);