X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=bc23c680a07b309a83de482bc29ef7c1ed18dd93;hb=3b595d39a50e38283768bc6ec8aeb9e73071224f;hp=948538ff460d15162048800ceea8c77a218f5954;hpb=0ec19b7ac91eedc83b31c3da733e237bfe28fc48;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index 948538ff4..bc23c680a 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -32,9 +32,6 @@ namespace ChanModeReference inviteonlymode(NULL, "inviteonly"); ChanModeReference keymode(NULL, "key"); ChanModeReference limitmode(NULL, "limit"); - ChanModeReference secretmode(NULL, "secret"); - ChanModeReference privatemode(NULL, "private"); - UserModeReference invisiblemode(NULL, "invisible"); } Channel::Channel(const std::string &cname, time_t ts) @@ -49,12 +46,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)); } @@ -93,7 +98,6 @@ void Channel::CheckDestroy() FOREACH_MOD(OnChannelDelete, (this)); ServerInstance->chanlist.erase(iter); - ClearInvites(); ServerInstance->GlobalCulls.AddItem(this); } @@ -134,7 +138,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 @@ -144,7 +148,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); @@ -177,14 +181,14 @@ 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; } if (user->chans.size() >= maxchans) { - user->WriteNumeric(ERR_TOOMANYCHANNELS, "%s :You are on too many channels", cname.c_str()); + user->WriteNumeric(ERR_TOOMANYCHANNELS, cname, "You are on too many channels"); return NULL; } } @@ -238,16 +242,13 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (MOD_RESULT == MOD_RES_PASSTHRU) { std::string ckey = chan->GetModeParameter(keymode); - bool invited = user->IsInvited(chan); - bool can_bypass = ServerInstance->Config->InvBypassModes && invited; - if (!ckey.empty()) { FIRST_MOD_RESULT(OnCheckKey, MOD_RESULT, (user, chan, key)); - if (!MOD_RESULT.check((ckey == key) || can_bypass)) + 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, "%s :Cannot join channel (Incorrect channel key)", chan->name.c_str()); + user->WriteNumeric(ERR_BADCHANNELKEY, chan->name, "Cannot join channel (Incorrect channel key)"); return NULL; } } @@ -255,9 +256,9 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (chan->IsModeSet(inviteonlymode)) { FIRST_MOD_RESULT(OnCheckInvite, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check(invited)) + if (MOD_RESULT != MOD_RES_ALLOW) { - user->WriteNumeric(ERR_INVITEONLYCHAN, "%s :Cannot join channel (Invite only)", chan->name.c_str()); + user->WriteNumeric(ERR_INVITEONLYCHAN, chan->name, "Cannot join channel (Invite only)"); return NULL; } } @@ -266,27 +267,18 @@ Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, co if (!limit.empty()) { FIRST_MOD_RESULT(OnCheckLimit, MOD_RESULT, (user, chan)); - if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str()) || can_bypass))) + if (!MOD_RESULT.check((chan->GetUserCounter() < atol(limit.c_str())))) { - user->WriteNumeric(ERR_CHANNELISFULL, "%s :Cannot join channel (Channel is full)", chan->name.c_str()); + user->WriteNumeric(ERR_CHANNELISFULL, chan->name, "Cannot join channel (Channel is full)"); return NULL; } } - if (chan->IsBanned(user) && !can_bypass) + if (chan->IsBanned(user)) { - user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s :Cannot join channel (You're banned)", chan->name.c_str()); + user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (You're banned)"); return NULL; } - - /* - * If the user has invites for this channel, remove them now - * after a successful join so they don't build up. - */ - if (invited) - { - user->RemoveInvite(chan); - } } } } @@ -344,16 +336,6 @@ Membership* Channel::ForceJoin(User* user, const std::string* privs, bool bursti this->WriteAllExcept(user, !ServerInstance->Config->CycleHostsFromUser, 0, except_list, "MODE %s +%s", this->name.c_str(), ms.c_str()); } - if (IS_LOCAL(user)) - { - if (this->topicset) - { - user->WriteNumeric(RPL_TOPIC, "%s :%s", this->name.c_str(), this->topic.c_str()); - user->WriteNumeric(RPL_TOPICTIME, "%s %s %lu", this->name.c_str(), this->setby.c_str(), (unsigned long)this->topicset); - } - this->UserList(user); - } - FOREACH_MOD(OnPostJoin, (memb)); return memb; } @@ -431,23 +413,25 @@ ModResult Channel::GetExtBanStatus(User *user, char type) * Remove a channel from a users record, remove the reference to the Membership object * from the channel and destroy it. */ -void Channel::PartUser(User *user, std::string &reason) +bool Channel::PartUser(User* user, std::string& reason) { MemberMap::iterator membiter = userlist.find(user); - if (membiter != userlist.end()) - { - Membership* memb = membiter->second; - CUList except_list; - FOREACH_MOD(OnUserPart, (memb, reason, except_list)); + if (membiter == userlist.end()) + return false; - WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str()); + Membership* memb = membiter->second; + CUList except_list; + FOREACH_MOD(OnUserPart, (memb, reason, except_list)); - // Remove this channel from the user's chanlist - user->chans.erase(memb); - // Remove the Membership from this channel's userlist and destroy it - this->DelUser(membiter); - } + WriteAllExcept(user, false, 0, except_list, "PART %s%s%s", this->name.c_str(), reason.empty() ? "" : " :", reason.c_str()); + + // Remove this channel from the user's chanlist + user->chans.erase(memb); + // Remove the Membership from this channel's userlist and destroy it + this->DelUser(membiter); + + return true; } void Channel::KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason) @@ -586,64 +570,11 @@ const char* Channel::ChanModes(bool showkey) return scratch.c_str(); } -/* compile a userlist of a channel into a string, each nick seperated by - * spaces and op, voice etc status shown as @ and +, and send it to 'user' - */ -void Channel::UserList(User* user, bool has_user) -{ - bool has_privs = user->HasPrivPermission("channels/auspex"); - std::string list; - list.push_back(this->IsModeSet(secretmode) ? '@' : this->IsModeSet(privatemode) ? '*' : '='); - list.push_back(' '); - list.append(this->name).append(" :"); - std::string::size_type pos = list.size(); - - const size_t maxlen = ServerInstance->Config->Limits.MaxLine - 10 - ServerInstance->Config->ServerName.size(); - std::string prefixlist; - std::string nick; - for (MemberMap::iterator i = userlist.begin(); i != userlist.end(); ++i) - { - if ((!has_user) && (i->first->IsModeSet(invisiblemode)) && (!has_privs)) - { - /* - * user is +i, and source not on the channel, does not show - * nick in NAMES list - */ - continue; - } - - Membership* memb = i->second; - - prefixlist.clear(); - char prefix = memb->GetPrefixChar(); - if (prefix) - prefixlist.push_back(prefix); - nick = i->first->nick; - - ModResult res; - FIRST_MOD_RESULT(OnNamesListItem, res, (user, memb, prefixlist, nick)); - - // See if a module wants us to exclude this user from NAMES - if (res == MOD_RES_DENY) - continue; - - if (list.size() + prefixlist.length() + nick.length() + 1 > maxlen) - { - /* list overflowed into multiple numerics */ - user->WriteNumeric(RPL_NAMREPLY, list); - - // Erase all nicks, keep the constant part - list.erase(pos); - } - - list.append(prefixlist).append(nick).push_back(' '); - } - - // Only send the user list numeric if there is at least one user in it - if (list.size() != pos) - user->WriteNumeric(RPL_NAMREPLY, list); - - user->WriteNumeric(RPL_ENDOFNAMES, "%s :End of /NAMES list.", this->name.c_str()); +void Channel::WriteNotice(const std::string& text) +{ + std::string rawmsg = "NOTICE "; + rawmsg.append(this->name).append(" :").append(text); + WriteChannelWithServ(ServerInstance->Config->ServerName, rawmsg); } /* returns the status character for a given user on a channel, e.g. @ for op, @@ -680,20 +611,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) @@ -723,68 +651,3 @@ bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding) modes.push_back(prefix); return adding; } - -void Invitation::Create(Channel* c, LocalUser* u, time_t timeout) -{ - if ((timeout != 0) && (ServerInstance->Time() >= timeout)) - // Expired, don't bother - return; - - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create chan=%s user=%s", c->name.c_str(), u->uuid.c_str()); - - Invitation* inv = Invitation::Find(c, u, false); - if (inv) - { - if ((inv->expiry == 0) || (inv->expiry > timeout)) - return; - inv->expiry = timeout; - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create changed expiry in existing invitation %p", (void*) inv); - } - else - { - inv = new Invitation(c, u, timeout); - c->invites.push_front(inv); - u->invites.push_front(inv); - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Create created new invitation %p", (void*) inv); - } -} - -Invitation* Invitation::Find(Channel* c, LocalUser* u, bool check_expired) -{ - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find chan=%s user=%s check_expired=%d", c ? c->name.c_str() : "NULL", u ? u->uuid.c_str() : "NULL", check_expired); - - Invitation* result = NULL; - for (InviteList::iterator i = u->invites.begin(); i != u->invites.end(); ) - { - Invitation* inv = *i; - ++i; - - if ((check_expired) && (inv->expiry != 0) && (inv->expiry <= ServerInstance->Time())) - { - /* Expired invite, remove it. */ - std::string expiration = InspIRCd::TimeString(inv->expiry); - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find ecountered expired entry: %p expired %s", (void*) inv, expiration.c_str()); - delete inv; - } - else - { - /* Is it what we're searching for? */ - if (inv->chan == c) - { - result = inv; - break; - } - } - } - - ServerInstance->Logs->Log("INVITATION", LOG_DEBUG, "Invitation::Find result=%p", (void*) result); - return result; -} - -Invitation::~Invitation() -{ - // Remove this entry from both lists - chan->invites.erase(this); - user->invites.erase(this); - ServerInstance->Logs->Log("INVITEBASE", LOG_DEBUG, "Invitation::~ %p", (void*) this); -}