return "";
}
+int Channel::SetTopic(User *u, std::string &ntopic, bool forceset)
+{
+ if (IS_LOCAL(u))
+ {
+ if(!forceset)
+ {
+ 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 (!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->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());
+
+ if (IS_LOCAL(u))
+ {
+ FOREACH_MOD(I_OnPostLocalTopicChange,OnPostLocalTopicChange(u, this, this->topic));
+ }
+
+ return CMD_SUCCESS;
+}
+
long Channel::GetUserCounter()
{
return (this->internal_userlist.size());
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');
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;
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());
+ }
}
}
}