mirror of
https://github.com/anope/anope.git
synced 2026-07-06 13:53:13 +02:00
Move some of CheckKick to the respective modules
This commit is contained in:
+4
-2
@@ -642,9 +642,11 @@ class CoreExport Module : public Extensible
|
||||
* @param u The user
|
||||
* @param ci The channel
|
||||
* @param kick Set to true to kick
|
||||
* @return EVENT_ALLOW to stop processing immediatly
|
||||
* @param mask The mask to ban, if any
|
||||
* @param reason The reason for the kick
|
||||
* @return EVENT_STOP to prevent the user from joining by kicking/banning the user
|
||||
*/
|
||||
virtual EventReturn OnCheckKick(User *u, ChannelInfo *ci, bool &kick) { return EVENT_CONTINUE; }
|
||||
virtual EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) { return EVENT_CONTINUE; }
|
||||
|
||||
/** Called when a user requests info for a channel
|
||||
* @param source The user requesting info
|
||||
|
||||
@@ -502,6 +502,44 @@ class CSAKick : public Module
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnCheckKick };
|
||||
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
|
||||
}
|
||||
|
||||
EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override
|
||||
{
|
||||
if (ci->c->MatchesList(u, CMODE_EXCEPT))
|
||||
return EVENT_CONTINUE;
|
||||
|
||||
for (unsigned j = 0, end = ci->GetAkickCount(); j < end; ++j)
|
||||
{
|
||||
AutoKick *autokick = ci->GetAkick(j);
|
||||
bool kick = false;
|
||||
|
||||
if (autokick->HasFlag(AK_ISNICK))
|
||||
{
|
||||
if (autokick->nc == u->Account())
|
||||
kick = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entry akick_mask(CMODE_BEGIN, autokick->mask);
|
||||
if (akick_mask.Matches(u))
|
||||
kick = true;
|
||||
}
|
||||
|
||||
if (kick)
|
||||
{
|
||||
Log(LOG_DEBUG_2) << u->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask);
|
||||
autokick->last_used = Anope::CurTime;
|
||||
if (!autokick->HasFlag(AK_ISNICK))
|
||||
mask = autokick->mask;
|
||||
reason = autokick->reason.empty() ? Config->CSAutokickReason : autokick->reason;
|
||||
return EVENT_STOP;
|
||||
}
|
||||
}
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1166,7 +1166,7 @@ class CSSet : public Module
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnReload, I_OnChanRegistered };
|
||||
Implementation i[] = { I_OnReload, I_OnChanRegistered, I_OnCheckKick };
|
||||
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
|
||||
|
||||
this->OnReload();
|
||||
@@ -1183,6 +1183,17 @@ class CSSet : public Module
|
||||
if (CSDefChanstats)
|
||||
ci->SetFlag(CI_STATS);
|
||||
}
|
||||
|
||||
EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override
|
||||
{
|
||||
if (!ci->HasFlag(CI_RESTRICTED) || ci->c->MatchesList(u, CMODE_EXCEPT))
|
||||
return EVENT_CONTINUE;
|
||||
|
||||
if (ci->AccessFor(u).empty() && (!ci->GetFounder() || u->Account() != ci->GetFounder()))
|
||||
return EVENT_STOP;
|
||||
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(CSSet)
|
||||
|
||||
@@ -216,7 +216,7 @@ class CSSuspend : public Module
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
Implementation i[] = { I_OnPreChanExpire };
|
||||
Implementation i[] = { I_OnPreChanExpire, I_OnCheckKick };
|
||||
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
|
||||
}
|
||||
|
||||
@@ -250,6 +250,15 @@ class CSSuspend : public Module
|
||||
Log(LOG_NORMAL, "expire", ChanServ) << "Expiring suspend for " << ci->name;
|
||||
}
|
||||
}
|
||||
|
||||
EventReturn OnCheckKick(User *u, ChannelInfo *ci, Anope::string &mask, Anope::string &reason) anope_override
|
||||
{
|
||||
if (u->HasMode(UMODE_OPER) || !ci->HasFlag(CI_SUSPENDED))
|
||||
return EVENT_CONTINUE;
|
||||
|
||||
reason = Language::Translate(u, _("This channel may not be used."));
|
||||
return EVENT_STOP;
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(CSSuspend)
|
||||
|
||||
@@ -29,7 +29,7 @@ class CommandNSResetPass : public Command
|
||||
{
|
||||
const NickAlias *na;
|
||||
|
||||
if (Config->RestrictMail && source.HasCommand("nickserv/resetpass"))
|
||||
if (Config->RestrictMail && !source.HasCommand("nickserv/resetpass"))
|
||||
source.Reply(ACCESS_DENIED);
|
||||
else if (!(na = NickAlias::Find(params[0])))
|
||||
source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str());
|
||||
@@ -78,6 +78,12 @@ class NSResetPass : public Module
|
||||
ModuleManager::Attach(I_OnPreCommand, this);
|
||||
}
|
||||
|
||||
~NSResetPass()
|
||||
{
|
||||
for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
|
||||
it->second->Shrink("ns_resetpass");
|
||||
}
|
||||
|
||||
EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) anope_override
|
||||
{
|
||||
if (command->name == "nickserv/confirm" && params.size() > 1)
|
||||
|
||||
+12
-65
@@ -945,69 +945,19 @@ bool ChannelInfo::CheckKick(User *user)
|
||||
if (user->IsProtected())
|
||||
return false;
|
||||
|
||||
bool set_modes = false, do_kick = false;
|
||||
Anope::string mask, reason;
|
||||
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnCheckKick, OnCheckKick(user, this, do_kick));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
FOREACH_RESULT(I_OnCheckKick, OnCheckKick(user, this, mask, reason));
|
||||
if (MOD_RESULT != EVENT_STOP)
|
||||
return false;
|
||||
|
||||
Anope::string mask, reason;
|
||||
if (!user->HasMode(UMODE_OPER) && this->HasFlag(CI_SUSPENDED))
|
||||
{
|
||||
mask = this->GetIdealBan(user);
|
||||
reason = Language::Translate(user, _("This channel may not be used."));
|
||||
set_modes = true;
|
||||
do_kick = true;
|
||||
}
|
||||
|
||||
if (!do_kick && !this->c->MatchesList(user, CMODE_EXCEPT))
|
||||
return false;
|
||||
|
||||
const NickCore *nc = user->Account() || user->IsRecognized() ? user->Account() : NULL;
|
||||
|
||||
if (!do_kick)
|
||||
{
|
||||
for (unsigned j = 0, end = this->GetAkickCount(); j < end; ++j)
|
||||
{
|
||||
AutoKick *autokick = this->GetAkick(j);
|
||||
|
||||
if (autokick->HasFlag(AK_ISNICK))
|
||||
{
|
||||
if (autokick->nc == nc)
|
||||
do_kick = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Entry akick_mask(CMODE_BEGIN, autokick->mask);
|
||||
if (akick_mask.Matches(user))
|
||||
do_kick = true;
|
||||
}
|
||||
if (do_kick)
|
||||
{
|
||||
Log(LOG_DEBUG_2) << user->nick << " matched akick " << (autokick->HasFlag(AK_ISNICK) ? autokick->nc->display : autokick->mask);
|
||||
autokick->last_used = Anope::CurTime;
|
||||
if (autokick->HasFlag(AK_ISNICK))
|
||||
mask = this->GetIdealBan(user);
|
||||
else
|
||||
mask = autokick->mask;
|
||||
reason = autokick->reason.empty() ? Config->CSAutokickReason : autokick->reason;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!do_kick && this->HasFlag(CI_RESTRICTED) && this->AccessFor(user).empty() && (!this->founder || user->Account() != this->founder))
|
||||
{
|
||||
do_kick = true;
|
||||
|
||||
if (mask.empty())
|
||||
mask = this->GetIdealBan(user);
|
||||
if (reason.empty())
|
||||
reason = Language::Translate(user->Account(), CHAN_NOT_ALLOWED_TO_JOIN);
|
||||
}
|
||||
|
||||
if (!do_kick)
|
||||
return false;
|
||||
|
||||
Log(LOG_DEBUG) << "Autokicking "<< user->GetMask() << " from " << this->name;
|
||||
Log(LOG_DEBUG) << "Autokicking " << user->nick << " (" << mask << ") from " << this->name;
|
||||
|
||||
/* If the channel isn't syncing and doesn't have any users, join ChanServ
|
||||
* Note that the user AND POSSIBLY the botserv bot exist here
|
||||
@@ -1016,14 +966,11 @@ bool ChannelInfo::CheckKick(User *user)
|
||||
*/
|
||||
if (this->c->users.size() == (this->bi && this->c->FindUser(this->bi) ? 2 : 1) && !this->c->HasFlag(CH_INHABIT) && !this->c->HasFlag(CH_SYNCING))
|
||||
{
|
||||
/* Set +si to prevent rejoin */
|
||||
if (set_modes)
|
||||
{
|
||||
c->SetMode(NULL, CMODE_NOEXTERNAL);
|
||||
c->SetMode(NULL, CMODE_TOPIC);
|
||||
c->SetMode(NULL, CMODE_SECRET);
|
||||
c->SetMode(NULL, CMODE_INVITE);
|
||||
}
|
||||
/* Set +ntsi to prevent rejoin */
|
||||
c->SetMode(NULL, CMODE_NOEXTERNAL);
|
||||
c->SetMode(NULL, CMODE_TOPIC);
|
||||
c->SetMode(NULL, CMODE_SECRET);
|
||||
c->SetMode(NULL, CMODE_INVITE);
|
||||
|
||||
/* Join ChanServ and set a timer for this channel to part ChanServ later */
|
||||
this->c->Hold();
|
||||
|
||||
Reference in New Issue
Block a user