mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Rework how guest nicks work.
- Use the config setting as a string template instead of as a prefix. - Allow users of IRCds that have UIDs to use that as the guest nick. - Fall back to a UID before killing if a guest nick can not be found.
This commit is contained in:
@@ -203,13 +203,17 @@ module
|
||||
releasetimeout = 1m
|
||||
|
||||
/*
|
||||
* When a user's nick is forcibly changed to enforce a "nick kill", their new nick will start
|
||||
* with this value. The rest will be made up of 6 or 7 digits.
|
||||
* Make sure this is a valid nick and Nicklen+7 is not longer than the allowed Nicklen on your ircd.
|
||||
* When a user's nick is forcibly changed to enforce nickname protection their new
|
||||
* nick will be based on this value. Any # in the value will be replaced with a random
|
||||
* number. If your IRCd has support for unique identifiers you can also set this to an
|
||||
* empty string to change a user's nick to their unique identifier.
|
||||
*
|
||||
* This directive is optional. If not set it defaults to "Guest"
|
||||
* Make sure this is a valid nick and that it is is not longer than the maximum nick
|
||||
* length on your IRCd.
|
||||
*
|
||||
* This directive is optional. If not set it defaults to "Guest####"
|
||||
*/
|
||||
guestnickprefix = "Guest"
|
||||
guestnick = "Guest####"
|
||||
|
||||
/*
|
||||
* If set, Anope does not allow ownership of nick names, only ownership of accounts.
|
||||
|
||||
@@ -19,4 +19,5 @@ public:
|
||||
virtual void Validate(User *u) = 0;
|
||||
virtual void Collide(User *u, NickAlias *na) = 0;
|
||||
virtual void Release(NickAlias *na) = 0;
|
||||
virtual bool IsGuestNick(const Anope::string &nick) const = 0;
|
||||
};
|
||||
|
||||
@@ -174,6 +174,24 @@ public:
|
||||
OnShutdown();
|
||||
}
|
||||
|
||||
bool IsGuestNick(const Anope::string &nick) const
|
||||
{
|
||||
const auto guestnick = Config->GetModule(this)->Get<Anope::string>("guestnick", "Guest####");
|
||||
if (guestnick.empty())
|
||||
return false; // No guest nick.
|
||||
|
||||
const auto minlen = std::min(nick.length(), guestnick.length());
|
||||
for (size_t idx = 0; idx < minlen; ++idx)
|
||||
{
|
||||
if (guestnick[idx] == '#' && !isdigit(nick[idx]))
|
||||
return false;
|
||||
|
||||
if (Anope::tolower(guestnick[idx]) != Anope::tolower(nick[idx]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Validate(User *u) override
|
||||
{
|
||||
NickAlias *na = NickAlias::Find(u->nick);
|
||||
@@ -238,30 +256,47 @@ public:
|
||||
|
||||
if (IRCD->CanSVSNick)
|
||||
{
|
||||
unsigned nicklen = IRCD->MaxNick;
|
||||
const Anope::string &guestprefix = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
|
||||
|
||||
auto guestnickok = false;
|
||||
Anope::string guestnick;
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
for (auto i = 0; i < 10; ++i)
|
||||
{
|
||||
guestnick = guestprefix + Anope::ToString(static_cast<uint16_t>(Anope::RandomNumber()));
|
||||
if (guestnick.length() > nicklen)
|
||||
guestnick = guestnick.substr(0, nicklen);
|
||||
}
|
||||
while (User::Find(guestnick) && i++ < 10);
|
||||
guestnick.clear();
|
||||
for (auto guestnickchr : Config->GetModule(this)->Get<Anope::string>("guestnick", "Guest####").substr(0, IRCD->MaxNick))
|
||||
{
|
||||
if (guestnickchr == '#')
|
||||
guestnick.append(Anope::ToString(abs(Anope::RandomNumber()) % 10));
|
||||
else
|
||||
guestnick.push_back(guestnickchr);
|
||||
}
|
||||
|
||||
if (i == 11)
|
||||
u->Kill(*NickServ, "Services nickname-enforcer kill");
|
||||
else
|
||||
// A guest nick is valid if it is non-empty and is not in use.
|
||||
if (!guestnick.empty() && !User::Find(guestnick, true))
|
||||
{
|
||||
guestnickok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we can't find a guest nick and the IRCd supports
|
||||
// uids then we should use that as the backup guest
|
||||
// nickname.
|
||||
if (!guestnickok && IRCD->RequiresID)
|
||||
{
|
||||
guestnickok = true;
|
||||
guestnick = u->GetUID();
|
||||
}
|
||||
|
||||
if (guestnickok)
|
||||
{
|
||||
u->SendMessage(*NickServ, _("Your nickname is now being changed to \002%s\002"), guestnick.c_str());
|
||||
IRCD->SendForceNickChange(u, guestnick, Anope::CurTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
u->Kill(*NickServ, "Services nickname-enforcer kill");
|
||||
|
||||
// We can't change the user's nickname or we can't find an
|
||||
// acceptable guest nick, give them the boot.
|
||||
u->Kill(*NickServ, "Enforcement of services protected nickname");
|
||||
}
|
||||
|
||||
void Release(NickAlias *na) override
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "module.h"
|
||||
#include "modules/ns_cert.h"
|
||||
|
||||
static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
|
||||
|
||||
class NSGroupRequest final
|
||||
: public IdentifyRequest
|
||||
{
|
||||
@@ -142,7 +144,6 @@ public:
|
||||
}
|
||||
|
||||
NickAlias *target, *na = NickAlias::Find(source.GetNick());
|
||||
const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
|
||||
time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
|
||||
unsigned maxaliases = Config->GetModule(this->owner)->Get<unsigned>("maxaliases");
|
||||
if (!(target = NickAlias::Find(nick)))
|
||||
@@ -165,12 +166,8 @@ public:
|
||||
source.Reply(NICK_IDENTIFY_REQUIRED);
|
||||
else if (maxaliases && target->nc->aliases->size() >= maxaliases && !target->nc->IsServicesOper())
|
||||
source.Reply(_("There are too many nicks in your group."));
|
||||
else if (source.GetNick().length() <= guestnick.length() + 7 &&
|
||||
source.GetNick().length() >= guestnick.length() + 1 &&
|
||||
!source.GetNick().find_ci(guestnick) && !source.GetNick().substr(guestnick.length()).find_first_not_of("1234567890"))
|
||||
{
|
||||
else if (nickserv && nickserv->IsGuestNick(source.GetNick()))
|
||||
source.Reply(NICK_CANNOT_BE_REGISTERED, source.GetNick().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
bool ok = false;
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
static bool SendRegmail(User *u, const NickAlias *na, BotInfo *bi);
|
||||
|
||||
static ServiceReference<NickServService> nickserv("NickServService", "NickServ");
|
||||
|
||||
class CommandNSConfirm final
|
||||
: public Command
|
||||
{
|
||||
@@ -133,7 +135,6 @@ public:
|
||||
{
|
||||
User *u = source.GetUser();
|
||||
Anope::string u_nick = source.GetNick();
|
||||
size_t nicklen = u_nick.length();
|
||||
Anope::string pass = params[0];
|
||||
Anope::string email = params.size() > 1 ? params[1] : "";
|
||||
const Anope::string &nsregister = Config->GetModule(this->owner)->Get<const Anope::string>("registration");
|
||||
@@ -160,13 +161,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
/* Prevent "Guest" nicks from being registered. -TheShadow */
|
||||
|
||||
/* Guest nick can now have a series of between 1 and 7 digits.
|
||||
* --lara
|
||||
*/
|
||||
const Anope::string &guestnick = Config->GetModule("nickserv")->Get<const Anope::string>("guestnickprefix", "Guest");
|
||||
if (nicklen <= guestnick.length() + 7 && nicklen >= guestnick.length() + 1 && !u_nick.find_ci(guestnick) && u_nick.substr(guestnick.length()).find_first_not_of("1234567890") == Anope::string::npos)
|
||||
if (nickserv && nickserv->IsGuestNick(u_nick))
|
||||
{
|
||||
source.Reply(NICK_CANNOT_BE_REGISTERED, u_nick.c_str());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user