X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fchannels.cpp;h=6eda54a9dd270e4b83e11c4af1806aaef02d00f4;hb=4ca5fb1994541181f940a692bce47eb11d681e7a;hp=a0ba81a5fb8fc835fc399453915600292fc4f0b2;hpb=eed401b6ecb6e1b88ee8ca3aa4c0b4df491e2035;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/channels.cpp b/src/channels.cpp index a0ba81a5f..6eda54a9d 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -73,33 +73,36 @@ std::string Channel::GetModeParameter(char mode) return ""; } -int Channel::SetTopic(User *u, std::string &ntopic) +int Channel::SetTopic(User *u, std::string &ntopic, bool forceset) { if (IS_LOCAL(u)) { - int MOD_RESULT = 0; - /* 0: check status, 1: don't, -1: disallow change silently */ - - FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic)); - if (MOD_RESULT == 1) - return CMD_FAILURE; - else if (MOD_RESULT == 0) + if(!forceset) { - if (!this->HasUser(u)) - { - u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str()); + int MOD_RESULT = 0; + /* 0: check status, 1: don't, -1: disallow change silently */ + + FOREACH_RESULT(I_OnLocalTopicChange,OnLocalTopicChange(u,this,ntopic)); + + if (MOD_RESULT == 1) return CMD_FAILURE; - } - if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP)) + else if (MOD_RESULT == 0) { - u->WriteNumeric(482, "%s %s :You must be at least a half-operator to change the topic on this channel", u->nick.c_str(), this->name.c_str()); - return CMD_FAILURE; + if (!this->HasUser(u)) + { + u->WriteNumeric(442, "%s %s :You're not on that channel!",u->nick.c_str(), this->name.c_str()); + return CMD_FAILURE; + } + if ((this->IsModeSet('t')) && (this->GetStatus(u) < STATUS_HOP)) + { + u->WriteNumeric(482, "%s %s :You must be at least a half-operator to change the topic on this channel", u->nick.c_str(), this->name.c_str()); + return CMD_FAILURE; + } } } - - this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic); } + this->topic.assign(ntopic, 0, ServerInstance->Config->Limits.MaxTopic); this->setby.assign(ServerInstance->Config->FullHostInTopic ? u->GetFullHost() : u->nick, 0, 128); this->topicset = ServerInstance->Time(); this->WriteChannel(u, "TOPIC %s :%s", this->name.c_str(), this->topic.c_str()); @@ -333,32 +336,36 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool else if (MOD_RESULT == 0) { std::string ckey = Ptr->GetModeParameter('k'); + bool invited = user->IsInvited(Ptr->name.c_str()); + bool can_bypass = Instance->Config->InvBypassModes && invited; + if (!ckey.empty()) { MOD_RESULT = 0; FOREACH_RESULT_I(Instance, I_OnCheckKey, OnCheckKey(user, Ptr, key ? key : "")); if (!MOD_RESULT) { - if ((!key) || ckey != key) + // If no key provided, or key is not the right one, and can't bypass +k (not invited or option not enabled) + if ((!key || ckey != key) && !can_bypass) { user->WriteNumeric(ERR_BADCHANNELKEY, "%s %s :Cannot join channel (Incorrect channel key)",user->nick.c_str(), Ptr->name.c_str()); return NULL; } } } + if (Ptr->IsModeSet('i')) { MOD_RESULT = 0; FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr)); if (!MOD_RESULT) { - if (!user->IsInvited(Ptr->name.c_str())) + if (!invited) { user->WriteNumeric(ERR_INVITEONLYCHAN, "%s %s :Cannot join channel (Invite only)",user->nick.c_str(), Ptr->name.c_str()); return NULL; } } - user->RemoveInvite(Ptr->name.c_str()); } std::string limit = Ptr->GetModeParameter('l'); @@ -369,7 +376,7 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool if (!MOD_RESULT) { long llimit = atol(limit.c_str()); - if (Ptr->GetUserCounter() >= llimit) + if (Ptr->GetUserCounter() >= llimit && !can_bypass) { user->WriteNumeric(ERR_CHANNELISFULL, "%s %s :Cannot join channel (Channel is full)",user->nick.c_str(), Ptr->name.c_str()); return NULL; @@ -379,12 +386,21 @@ Channel* Channel::JoinUser(InspIRCd* Instance, User *user, const char* cn, bool if (Ptr->bans.size()) { - if (Ptr->IsBanned(user)) + if (Ptr->IsBanned(user) && !can_bypass) { user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)",user->nick.c_str(), Ptr->name.c_str()); 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(Ptr->name.c_str()); + } } } } @@ -986,7 +1002,7 @@ void Channel::UserList(User *user, CUList *ulist) if (curlen + prefixlist.length() + nick.length() + 1 > 480) { /* list overflowed into multiple numerics */ - user->WriteServ(std::string(list)); + user->WriteNumeric(RPL_NAMREPLY, std::string(list)); /* reset our lengths */ dlen = curlen = snprintf(list,MAXBUF,"%s %c %s :", user->nick.c_str(), this->IsModeSet('s') ? '@' : this->IsModeSet('p') ? '*' : '=', this->name.c_str());