X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=fcfb524ce1071c8ae11a54332429fb9aa22f7a37;hb=da45f24ff1ab4fbac1b674c820796e9b3850a380;hp=39265764738e7b35aa8c39b9778d1e60c7fdb259;hpb=458168b575663dc7bdb71c651c30320752f22e41;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 392657647..fcfb524ce 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -42,36 +42,13 @@ namespace Channel::Channel(const std::string &cname, time_t ts) : name(cname), age(ts), topicset(0) { - if (!ServerInstance->chanlist->insert(std::make_pair(cname, this)).second) + if (!ServerInstance->chanlist.insert(std::make_pair(cname, this)).second) throw CoreException("Cannot create duplicate channel " + cname); } void Channel::SetMode(ModeHandler* mh, bool on) { - modes[mh->GetModeChar() - 65] = on; -} - -void Channel::SetModeParam(ModeHandler* mh, const std::string& parameter) -{ - char mode = mh->GetModeChar(); - if (parameter.empty()) - { - custom_mode_params.erase(mode); - modes[mode-65] = false; - } - else - { - custom_mode_params[mode] = parameter; - modes[mode-65] = true; - } -} - -std::string Channel::GetModeParameter(ModeHandler* mode) -{ - CustomModeList::iterator n = custom_mode_params.find(mode->GetModeChar()); - if (n != custom_mode_params.end()) - return n->second; - return ""; + modes[mh->GetId()] = on; } void Channel::SetTopic(User* u, const std::string& ntopic) @@ -111,12 +88,12 @@ void Channel::CheckDestroy() if (res == MOD_RES_DENY) return; - chan_hash::iterator iter = ServerInstance->chanlist->find(this->name); + chan_hash::iterator iter = ServerInstance->chanlist.find(this->name); /* kill the record */ - if (iter != ServerInstance->chanlist->end()) + if (iter != ServerInstance->chanlist.end()) { FOREACH_MOD(OnChannelDelete, (this)); - ServerInstance->chanlist->erase(iter); + ServerInstance->chanlist.erase(iter); } ClearInvites(); @@ -438,7 +415,6 @@ ModResult Channel::GetExtBanStatus(User *user, char type) ListModeBase* banlm = static_cast(*ban); const ListModeBase::ModeList* bans = banlm->GetList(this); if (bans) - { for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it) { @@ -622,11 +598,13 @@ 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) + + ParamModeBase* pm = mh->IsParameterMode(); + if (!pm) continue; if (n == 'k' - 65 && !showkey) @@ -635,12 +613,8 @@ const char* Channel::ChanModes(bool showkey) } else { - const std::string param = this->GetModeParameter(mh); - if (!param.empty()) - { - sparam += ' '; - sparam += param; - } + sparam += ' '; + pm->GetParameter(this, sparam); } } } @@ -678,8 +652,6 @@ void Channel::UserList(User *user) std::string nick; for (UserMembIter i = userlist.begin(); i != userlist.end(); ++i) { - if (i->first->quitting) - continue; if ((!has_user) && (i->first->IsModeSet(invisiblemode)) && (!has_privs)) { /* @@ -689,10 +661,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()) @@ -726,23 +701,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; @@ -761,20 +731,16 @@ unsigned int Membership::getRank() return rv; } -const char* Channel::GetAllPrefixChars(User* user) +const char* Membership::GetAllPrefixChars() const { static char prefix[64]; int ctr = 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(m->second->modes[i]); - if (mh && mh->GetPrefix()) - prefix[ctr++] = mh->GetPrefix(); - } + PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i); + if (mh && mh->GetPrefix()) + prefix[ctr++] = mh->GetPrefix(); } prefix[ctr] = 0;