Beispiel #1
0
	void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
	{
		User *u = source.GetUser();

		Anope::string nick;
		if (params.empty())
		{
			NickServ::Account* core = u->Account();
			if (core)
				nick = core->GetDisplay();
		}
		else
			nick = params[0];

		if (nick.empty())
		{
			this->SendSyntax(source);
			return;
		}

		const Anope::string &pass = params.size() > 1 ? params[1] : "";

		if (Anope::ReadOnly)
		{
			source.Reply(_("Sorry, nickname grouping is temporarily disabled."));
			return;
		}

		if (!IRCD->IsNickValid(u->nick))
		{
			source.Reply(_("\002{0}\002 may not be registered."), u->nick);
			return;
		}

		if (Config->GetModule("nickserv")->Get<bool>("restrictopernicks"))
			for (Oper *o : Serialize::GetObjects<Oper *>())
			{
				if (!u->HasMode("OPER") && u->nick.find_ci(o->GetName()) != Anope::string::npos)
				{
					source.Reply(_("\002{0}\002 may not be registered because it is too similar to an operator nick."), u->nick);
					return;
				}
			}

		NickServ::Nick *target, *na = NickServ::FindNick(u->nick);
		const Anope::string &guestnick = Config->GetModule("nickserv")->Get<Anope::string>("guestnickprefix", "Guest");
		time_t reg_delay = Config->GetModule("nickserv")->Get<time_t>("regdelay");
		unsigned maxaliases = Config->GetModule(this->GetOwner())->Get<unsigned>("maxaliases");
		if (!(target = NickServ::FindNick(nick)))
		{
			source.Reply(_("\002{0}\002 isn't registered."), nick);
			return;
		}

		if (Anope::CurTime < u->lastnickreg + reg_delay)
		{
			source.Reply(_("Please wait \002{0}\002 seconds before using the \002{1}\002 command again."), (reg_delay + u->lastnickreg) - Anope::CurTime, source.command);
			return;
		}

		if (target->GetAccount()->HasFieldS("NS_SUSPENDED"))
		{
			Log(LOG_COMMAND, source, this) << "and tried to group to suspended nick " << target->GetNick();
			source.Reply(_("\002{0}\002 is suspended."), target->GetNick());
			return;
		}

		if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
		{
			source.Reply(_("Your nick is already registered."));
			return;
		}

		if (na && target->GetAccount() == na->GetAccount())
		{
			source.Reply(_("You are already a member of the group of \002{0}\002."), target->GetNick());
			return;
		}

		if (na && na->GetAccount() != u->Account())
		{
			source.Reply(_("\002{0}\002 is already registered."), na->GetNick());
			return;
		}

		if (na && Config->GetModule(this->GetOwner())->Get<bool>("nogroupchange"))
		{
			source.Reply(_("You are already registered."));
			return;
		}

		if (maxaliases && target->GetAccount()->GetRefs<NickServ::Nick *>().size() >= maxaliases && !target->GetAccount()->IsServicesOper())
		{
			source.Reply(_("There are too many nicknames in your group."));
			return;
		}

		if (u->nick.length() <= guestnick.length() + 7 &&
			u->nick.length() >= guestnick.length() + 1 &&
			!u->nick.find_ci(guestnick) && !u->nick.substr(guestnick.length()).find_first_not_of("1234567890"))
		{
			source.Reply(_("\002{0}\002 may not be registered."), u->nick);
			return;
		}

		bool ok = false;
		if (!na && u->Account() == target->GetAccount())
			ok = true;

		if (certservice && certservice->Matches(u, target->GetAccount()))
			ok = true;

		if (ok == false && !pass.empty())
		{
			NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(source, this, u->nick, target), this->GetOwner(), target->GetAccount()->GetDisplay(), pass);
			EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req);
			req->Dispatch();
		}
		else
		{
			NSGroupRequestListener req(source, this, u->nick, target);

			if (ok)
				req.OnSuccess(nullptr);
			else
				req.OnFail(nullptr);
		}
	}