X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=b293e7fad74a93bada1db9940b581aaf3d961aff;hb=48a400f2e068527b338ceecf8ed1dde2da971ca9;hp=14b1ea54534b3559750e1e2594db4858ff338575;hpb=cee5a82d95fc3f5d3670ef483998bfc2d4a5a82e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 14b1ea545..b293e7fad 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -29,9 +29,6 @@ namespace { ChanModeReference ban(NULL, "ban"); - ChanModeReference inviteonlymode(NULL, "inviteonly"); - ChanModeReference keymode(NULL, "key"); - ChanModeReference limitmode(NULL, "limit"); } Channel::Channel(const std::string &cname, time_t ts) @@ -46,12 +43,20 @@ void Channel::SetMode(ModeHandler* mh, bool on) modes[mh->GetId()] = on; } -void Channel::SetTopic(User* u, const std::string& ntopic) +void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const std::string* setter) { - this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic); - this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128); - this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str()); - this->topicset = ServerInstance->Time(); + // Send a TOPIC message to the channel only if the new topic text differs + if (this->topic != ntopic) + { + this->topic = ntopic; + this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str()); + } + + // Always update setter and set time + if (!setter) + setter = ServerInstance->Config->FullHostInTopic ? &u->GetFullHost() : &u->nick; + this->setby.assign(*setter, 0, ServerInstance->Config->Limits.GetMaxMask()); + this->topicset = topicts; FOREACH_MOD(OnPostTopicChange, (u, this, this->topic)); } @@ -130,7 +135,7 @@ void Channel::SetDefaultModes() if (mode->IsPrefixMode()) continue; - if (mode->GetNumParams(true)) + if (mode->NeedsParam(true)) { list.GetToken(parameter); // If the parameter begins with a ':' then it's invalid @@ -140,7 +145,7 @@ void Channel::SetDefaultModes() else parameter.clear(); - if ((mode->GetNumParams(true)) && (parameter.empty())) + if ((mode->NeedsParam(true)) && (parameter.empty())) continue; mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true); @@ -173,7 +178,7 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co { unsigned int opermaxchans = ConvToInt(user->oper->getConfig("maxchans")); // If not set, use 2.0's , if that's not set either, use limit from CC - if (!opermaxchans) + if (!opermaxchans && user->HasPrivPermission("channels/high-join-limit")) opermaxchans = ServerInstance->Config->OperMaxChans; if (opermaxchans) maxchans = opermaxchans; @@ -227,45 +232,12 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co return NULL; // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case - // most of the time) then proceed to check channel modes +k, +i, +l and bans, - // in this order. + // most of the time) then proceed to check channel bans. + // // If a module explicitly allowed the join (by returning MOD_RES_ALLOW), // then this entire section is skipped if (MOD_RESULT == MOD_RES_PASSTHRU) { - std::string ckey = chan->GetModeParameter(keymode); - if (!ckey.empty()) - { - FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key)); - if (!MOD_RESULT.check(InspIRCd::TimingSafeCompare(ckey, key))) - { - // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled) - user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)"); - return NULL; - } - } - - if (chan->IsModeSet(inviteonlymode)) - { - FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan)); - if (MOD_RESULT != MOD_RES_ALLOW) - { - user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)"); - return NULL; - } - } - - std::string limit = chan->GetModeParameter(limitmode); - if (!limit.empty()) - { - FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str())))) - { - user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)"); - return NULL; - } - } - if (chan->IsBanned(user)) { user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You're banned)"); @@ -341,6 +313,9 @@ bool Channel::IsBanned(User* user) return (result == MOD_RES_DENY); ListModeBase* banlm = static_cast(*ban); + if (!banlm) + return false; + const ListModeBase::ModeList* bans = banlm->GetList(this); if (bans) { @@ -373,8 +348,8 @@ bool Channel::CheckBan(User* user, const std::string& mask) if (InspIRCd::Match(nickIdent, prefix, NULL)) { std::string suffix(mask, at + 1); - if (InspIRCd::Match(user->host, suffix, NULL) || - InspIRCd::Match(user->dhost, suffix, NULL) || + if (InspIRCd::Match(user->GetRealHost(), suffix, NULL) || + InspIRCd::Match(user->GetDisplayedHost(), suffix, NULL) || InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL)) return true; } @@ -389,12 +364,18 @@ ModResult Channel::GetExtBanStatus(User *user, char type) return rv; ListModeBase* banlm = static_cast(*ban); + if (!banlm) + return MOD_RES_PASSTHRU; + const ListModeBase::ModeList* bans = banlm->GetList(this); if (bans) { for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it) { - if (CheckBan(user, it->mask)) + if (it->mask.length() <= 2 || it->mask[0] != type || it->mask[1] != ':') + continue; + + if (CheckBan(user, it->mask.substr(2))) return MOD_RES_DENY; } } @@ -603,20 +584,17 @@ unsigned int Membership::getRank() return rv; } -const char* Membership::GetAllPrefixChars() const +std::string Membership::GetAllPrefixChars() const { - static char prefix[64]; - int ctr = 0; - + std::string ret; for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i) { PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i); if (mh && mh->GetPrefix()) - prefix[ctr++] = mh->GetPrefix(); + ret.push_back(mh->GetPrefix()); } - prefix[ctr] = 0; - return prefix; + return ret; } unsigned int Channel::GetPrefixValue(User* user) @@ -646,3 +624,11 @@ bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding) modes.push_back(prefix); return adding; } + + +void Membership::WriteNotice(const std::string& text) const +{ + std::string rawmsg = "NOTICE "; + rawmsg.append(chan->name).append(" :").append(text); + user->WriteServ(rawmsg); +}