X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Flistmode.cpp;h=0f139bb0129c42a2d44f5dcf6ecc499723fc8c82;hb=4634151efc02ff016e19c5f123d75824d0d6c811;hp=f45f1624f57da8b06b17411013a0d230adb75988;hpb=9de86c34d41fcbcedf7b332746b7f0e8c37c7c45;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/listmode.cpp b/src/listmode.cpp index f45f1624f..0f139bb01 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -20,7 +20,7 @@ #include "listmode.h" ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modechar, const std::string &eolstr, unsigned int lnum, unsigned int eolnum, bool autotidy, const std::string &ctag) - : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL), + : ModeHandler(Creator, Name, modechar, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_LIST), listnumeric(lnum), endoflistnumeric(eolnum), endofliststring(eolstr), tidy(autotidy), configtag(ctag), extItem("listbase_mode_" + name + "_list", Creator) { @@ -29,60 +29,39 @@ ListModeBase::ListModeBase(Module* Creator, const std::string& Name, char modech void ListModeBase::DisplayList(User* user, Channel* channel) { - ModeList* el = extItem.get(channel); - if (el) + ChanData* cd = extItem.get(channel); + if (cd) { - for (ModeList::reverse_iterator it = el->rbegin(); it != el->rend(); ++it) + for (ModeList::reverse_iterator it = cd->list.rbegin(); it != cd->list.rend(); ++it) { - user->WriteNumeric(listnumeric, "%s %s %s %s %lu", user->nick.c_str(), channel->name.c_str(), it->mask.c_str(), (!it->setter.empty() ? it->setter.c_str() : ServerInstance->Config->ServerName.c_str()), (unsigned long) it->time); + user->WriteNumeric(listnumeric, "%s %s %s %lu", channel->name.c_str(), it->mask.c_str(), (!it->setter.empty() ? it->setter.c_str() : ServerInstance->Config->ServerName.c_str()), (unsigned long) it->time); } } - user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str()); + user->WriteNumeric(endoflistnumeric, "%s :%s", channel->name.c_str(), endofliststring.c_str()); } void ListModeBase::DisplayEmptyList(User* user, Channel* channel) { - user->WriteNumeric(endoflistnumeric, "%s %s :%s", user->nick.c_str(), channel->name.c_str(), endofliststring.c_str()); + user->WriteNumeric(endoflistnumeric, "%s :%s", channel->name.c_str(), endofliststring.c_str()); } -void ListModeBase::RemoveMode(Channel* channel, irc::modestacker* stack) +void ListModeBase::RemoveMode(Channel* channel, irc::modestacker& stack) { - ModeList* el = extItem.get(channel); - if (el) + ChanData* cd = extItem.get(channel); + if (cd) { - irc::modestacker modestack(false); - - for (ModeList::iterator it = el->begin(); it != el->end(); it++) - { - if (stack) - stack->Push(this->GetModeChar(), it->mask); - else - modestack.Push(this->GetModeChar(), it->mask); - } - - if (stack) - return; - - std::vector stackresult; - stackresult.push_back(channel->name); - while (modestack.GetStackedLine(stackresult)) + for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++) { - ServerInstance->SendMode(stackresult, ServerInstance->FakeClient); - stackresult.clear(); - stackresult.push_back(channel->name); + stack.Push(this->GetModeChar(), it->mask); } } } -void ListModeBase::RemoveMode(User*, irc::modestacker* stack) -{ - /* Listmodes dont get set on users */ -} - void ListModeBase::DoRehash() { ConfigTagList tags = ServerInstance->Config->ConfTags(configtag); + limitlist oldlimits = chanlimits; chanlimits.clear(); for (ConfigIter i = tags.first; i != tags.second; i++) @@ -97,21 +76,25 @@ void ListModeBase::DoRehash() if (chanlimits.empty()) chanlimits.push_back(ListLimit("*", 64)); -} -void ListModeBase::DoImplements(Module* m) -{ - ServerInstance->Modules->AddService(extItem); - this->DoRehash(); - Implementation eventlist[] = { I_OnSyncChannel, I_OnRehash }; - ServerInstance->Modules->Attach(eventlist, m, sizeof(eventlist)/sizeof(Implementation)); + // Most of the time our settings are unchanged, so we can avoid iterating the chanlist + if (oldlimits == chanlimits) + return; + + const chan_hash& chans = ServerInstance->GetChans(); + for (chan_hash::const_iterator i = chans.begin(); i != chans.end(); ++i) + { + ChanData* cd = extItem.get(i->second); + if (cd) + cd->maxitems = -1; + } } -unsigned int ListModeBase::GetLimit(Channel* channel) +unsigned int ListModeBase::FindLimit(const std::string& channame) { for (limitlist::iterator it = chanlimits.begin(); it != chanlimits.end(); ++it) { - if (InspIRCd::Match(channel->name, it->mask)) + if (InspIRCd::Match(channame, it->mask)) { // We have a pattern matching the channel return it->limit; @@ -120,10 +103,26 @@ unsigned int ListModeBase::GetLimit(Channel* channel) return 64; } +unsigned int ListModeBase::GetLimitInternal(const std::string& channame, ChanData* cd) +{ + if (cd->maxitems < 0) + cd->maxitems = FindLimit(channame); + return cd->maxitems; +} + +unsigned int ListModeBase::GetLimit(Channel* channel) +{ + ChanData* cd = extItem.get(channel); + if (!cd) // just find the limit + return FindLimit(channel->name); + + return GetLimitInternal(channel->name, cd); +} + ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) { // Try and grab the list - ModeList* el = extItem.get(channel); + ChanData* cd = extItem.get(channel); if (adding) { @@ -134,15 +133,15 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std return MODEACTION_DENY; // If there was no list - if (!el) + if (!cd) { // Make one - el = new ModeList; - extItem.set(channel, el); + cd = new ChanData; + extItem.set(channel, cd); } // Check if the item already exists in the list - for (ModeList::iterator it = el->begin(); it != el->end(); it++) + for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); it++) { if (parameter == it->mask) { @@ -154,11 +153,10 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std } } - if ((IS_LOCAL(source)) && (el->size() >= GetLimit(channel))) + if ((IS_LOCAL(source)) && (cd->list.size() >= GetLimitInternal(channel->name, cd))) { /* List is full, give subclass a chance to send a custom message */ TellListTooLong(source, channel, parameter); - parameter.clear(); return MODEACTION_DENY; } @@ -175,7 +173,7 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std if (ValidateParam(source, channel, parameter)) { // And now add the mask onto the list... - el->push_back(ListItem(parameter, source->nick, ServerInstance->Time())); + cd->list.push_back(ListItem(parameter, source->nick, ServerInstance->Time())); return MODEACTION_ALLOW; } else @@ -187,13 +185,13 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std else { // We're taking the mode off - if (el) + if (cd) { - for (ModeList::iterator it = el->begin(); it != el->end(); it++) + for (ModeList::iterator it = cd->list.begin(); it != cd->list.end(); ++it) { if (parameter == it->mask) { - el->erase(it); + cd->list.erase(it); return MODEACTION_ALLOW; } } @@ -201,33 +199,10 @@ ModeAction ListModeBase::OnModeChange(User* source, User*, Channel* channel, std /* Tried to remove something that wasn't set */ TellNotSet(source, channel, parameter); - parameter.clear(); return MODEACTION_DENY; } } -void ListModeBase::DoSyncChannel(Channel* chan, Module* proto, void* opaque) -{ - ModeList* mlist = extItem.get(chan); - if (!mlist) - return; - - irc::modestacker modestack(true); - std::vector stackresult; - std::vector types; - types.push_back(TR_TEXT); - - for (ModeList::iterator it = mlist->begin(); it != mlist->end(); it++) - modestack.Push(mode, it->mask); - - while (modestack.GetStackedLine(stackresult)) - { - types.assign(stackresult.size(), this->GetTranslateType()); - proto->ProtoSendMode(opaque, TYPE_CHANNEL, chan, stackresult, types); - stackresult.clear(); - } -} - bool ListModeBase::ValidateParam(User*, Channel*, std::string&) { return true; @@ -235,7 +210,7 @@ bool ListModeBase::ValidateParam(User*, Channel*, std::string&) void ListModeBase::TellListTooLong(User* source, Channel* channel, std::string& parameter) { - source->WriteNumeric(478, "%s %s %s :Channel ban list is full", source->nick.c_str(), channel->name.c_str(), parameter.c_str()); + source->WriteNumeric(ERR_BANLISTFULL, "%s %s :Channel ban list is full", channel->name.c_str(), parameter.c_str()); } void ListModeBase::TellAlreadyOnList(User*, Channel*, std::string&)