Move FindNick to UserManager.

This commit is contained in:
Sadie Powell 2020-02-09 16:13:04 +00:00
parent 1cdffcaad7
commit 61070d4894
42 changed files with 59 additions and 55 deletions

View File

@ -339,13 +339,6 @@ class CoreExport InspIRCd
*/
size_t BindPorts(FailedPortList &failed_ports);
/** Find a user in the nick hash.
* If the user cant be found in the nick hash check the uuid hash
* @param nick The nickname to find
* @return A pointer to the user, or NULL if the user does not exist
*/
User* FindNick(const std::string &nick);
/** Find a user in the nick hash ONLY
*/
User* FindNickOnly(const std::string &nick);

View File

@ -192,6 +192,13 @@ class CoreExport UserManager
*/
already_sent_t NextAlreadySentId();
/** Find a user by their nickname or UUID.
* IMPORTANT: You probably want to use FindNick or FindUUID instead of this.
* @param nickuuid The nickname or UUID of the user to find.
* @return If the user was found then a pointer to a User object; otherwise, nullptr.
*/
User* Find(const std::string& nickuuid);
/** Find a user by their UUID.
* @param uuid The UUID of the user to find.
* @return If the user was found then a pointer to a User object; otherwise, nullptr.

View File

@ -425,7 +425,7 @@ void CommandParser::TranslateSingleParam(TranslateType to, const std::string& it
case TR_NICK:
{
/* Translate single nickname */
User* user = ServerInstance->FindNick(item);
User* user = ServerInstance->Users.Find(item);
if (user)
dest.append(user->uuid);
else

View File

@ -51,7 +51,7 @@ CmdResult CommandInvite::Handle(User* user, const Params& parameters)
if (IS_LOCAL(user))
u = ServerInstance->FindNickOnly(parameters[0]);
else
u = ServerInstance->FindNick(parameters[0]);
u = ServerInstance->Users.Find(parameters[0]);
Channel* c = ServerInstance->FindChan(parameters[1]);
time_t timeout = 0;

View File

@ -48,7 +48,7 @@ CmdResult CommandKick::Handle(User* user, const Params& parameters)
if (IS_LOCAL(user))
u = ServerInstance->FindNickOnly(parameters[1]);
else
u = ServerInstance->FindNick(parameters[1]);
u = ServerInstance->Users.Find(parameters[1]);
if (!c)
{

View File

@ -237,7 +237,7 @@ class CommandMessage : public Command
else
{
// Remote users can only specify a nick or UUID as the target.
target = ServerInstance->FindNick(parameters[0]);
target = ServerInstance->Users.Find(parameters[0]);
}
if (!target || target->registered != REG_ALL)

View File

@ -91,7 +91,7 @@ CmdResult CommandMode::Handle(User* user, const Params& parameters)
if (IS_LOCAL(user))
targetuser = ServerInstance->FindNickOnly(target);
else
targetuser = ServerInstance->FindNick(target);
targetuser = ServerInstance->Users.Find(target);
}
if ((!targetchannel || !CanSeeChan(user, targetchannel)) && (!targetuser))

View File

@ -65,7 +65,7 @@ CmdResult CommandKill::Handle(User* user, const Params& parameters)
return CMD_FAILURE;
}
User* target = ServerInstance->FindNick(parameters[0]);
User* target = ServerInstance->Users.Find(parameters[0]);
if (!target)
{
user->WriteNumeric(Numerics::NoSuchNick(parameters[0]));

View File

@ -45,7 +45,7 @@ CmdResult CommandEline::Handle(User* user, const Params& parameters)
if (parameters.size() >= 3)
{
IdentHostPair ih;
User* find = ServerInstance->FindNick(target);
User* find = ServerInstance->Users.Find(target);
if ((find) && (find->registered == REG_ALL))
{
ih.first = "*";

View File

@ -46,7 +46,7 @@ CmdResult CommandGline::Handle(User* user, const Params& parameters)
if (parameters.size() >= 3)
{
IdentHostPair ih;
User* find = ServerInstance->FindNick(target);
User* find = ServerInstance->Users.Find(target);
if ((find) && (find->registered == REG_ALL))
{
ih.first = "*";

View File

@ -46,7 +46,7 @@ CmdResult CommandKline::Handle(User* user, const Params& parameters)
if (parameters.size() >= 3)
{
IdentHostPair ih;
User* find = ServerInstance->FindNick(target);
User* find = ServerInstance->Users.Find(target);
if ((find) && (find->registered == REG_ALL))
{
ih.first = "*";

View File

@ -50,7 +50,7 @@ CmdResult CommandZline::Handle(User* user, const Params& parameters)
return CMD_FAILURE;
}
User *u = ServerInstance->FindNick(target);
User *u = ServerInstance->Users.Find(target);
if ((u) && (u->registered == REG_ALL))
{

View File

@ -39,13 +39,6 @@
#include <iostream>
/* Find a user record by nickname and return a pointer to it */
User* InspIRCd::FindNick(const std::string &nick)
{
if (!nick.empty() && isdigit(*nick.begin()))
return FindUUID(nick);
return FindNickOnly(nick);
}
User* InspIRCd::FindNickOnly(const std::string &nick)
{
user_hash::iterator iter = this->Users.clientlist.find(nick);

View File

@ -190,7 +190,7 @@ ModeAction PrefixMode::OnModeChange(User* source, User*, Channel* chan, std::str
if (IS_LOCAL(source))
target = ServerInstance->FindNickOnly(parameter);
else
target = ServerInstance->FindNick(parameter);
target = ServerInstance->Users.Find(parameter);
if (!target)
{

View File

@ -107,7 +107,7 @@ struct CallerIDExtInfo : public ExtensionItem
while (s.GetToken(tok))
{
User *u = ServerInstance->FindNick(tok);
User *u = ServerInstance->Users.Find(tok);
if ((u) && (u->registered == REG_ALL) && (!u->quitting))
{
if (dat->accepting.insert(u).second)
@ -166,7 +166,7 @@ class CommandAccept : public Command
User* target;
if (!cmdfrom || !IS_LOCAL(cmdfrom))
target = ServerInstance->FindNick(tok);
target = ServerInstance->Users.Find(tok);
else
target = ServerInstance->FindNickOnly(tok);

View File

@ -162,7 +162,7 @@ class CommandCheck : public Command
Channel *targchan;
std::string chliststr;
targuser = ServerInstance->FindNick(parameters[0]);
targuser = ServerInstance->Users.Find(parameters[0]);
targchan = ServerInstance->FindChan(parameters[0]);
/*

View File

@ -58,7 +58,7 @@ class CommandChghost : public Command
}
}
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
// Allow services to change the host of unregistered users
if ((!dest) || ((dest->registered != REG_ALL) && (!user->server->IsULine())))

View File

@ -42,7 +42,7 @@ class CommandChgident : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
if ((!dest) || (dest->registered != REG_ALL))
{

View File

@ -41,7 +41,7 @@ class CommandChgname : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
if ((!dest) || (dest->registered != REG_ALL))
{

View File

@ -242,7 +242,7 @@ ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, ModeHandler*
if (IS_LOCAL(user))
dest = ServerInstance->FindNickOnly(param);
else
dest = ServerInstance->FindNick(param);
dest = ServerInstance->Users.Find(param);
if (!dest)
return MOD_RES_PASSTHRU;

View File

@ -172,7 +172,7 @@ class CommandTagMsg : public Command
else
{
// Remote users can only specify a nick or UUID as the target.
target = ServerInstance->FindNick(parameters[0]);
target = ServerInstance->Users.Find(parameters[0]);
}
if (!target || target->registered != REG_ALL)

View File

@ -50,7 +50,7 @@ class CommandNicklock : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* target = ServerInstance->FindNick(parameters[0]);
User* target = ServerInstance->Users.Find(parameters[0]);
if ((!target) || (target->registered != REG_ALL))
{
@ -110,7 +110,7 @@ class CommandNickunlock : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* target = ServerInstance->FindNick(parameters[0]);
User* target = ServerInstance->Users.Find(parameters[0]);
if (!target)
{

View File

@ -93,7 +93,7 @@ class NetworkPrefix : public PrefixMode
ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding) override
{
User* theuser = ServerInstance->FindNick(parameter);
User* theuser = ServerInstance->Users.Find(parameter);
// remove own privs?
if (source == theuser && !adding)
return MOD_RES_ALLOW;

View File

@ -99,7 +99,7 @@ class ModulePassForward : public Module
if (!nickrequired.empty())
{
/* Check if nick exists and its server is ulined */
User* u = ServerInstance->FindNick(nickrequired);
User* u = ServerInstance->Users.Find(nickrequired);
if (!u || !u->server->IsULine())
return;
}

View File

@ -75,7 +75,7 @@ class RemoveBase : public Command
if (IS_LOCAL(user))
target = ServerInstance->FindNickOnly(username);
else
target = ServerInstance->FindNick(username);
target = ServerInstance->Users.Find(username);
/* And the channel we're meant to be removing them from */
channel = ServerInstance->FindChan(channame);

View File

@ -49,7 +49,7 @@ class CommandSajoin : public Command
const std::string& channel = parameters[channelindex];
const std::string& nickname = parameters.size() > 1 ? parameters[0] : user->nick;
User* dest = ServerInstance->FindNick(nickname);
User* dest = ServerInstance->Users.Find(nickname);
if ((dest) && (dest->registered == REG_ALL))
{
if (user != dest && !user->HasPrivPermission("users/sajoin-others"))

View File

@ -37,7 +37,7 @@ class CommandSakick : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[1]);
User* dest = ServerInstance->Users.Find(parameters[1]);
Channel* channel = ServerInstance->FindChan(parameters[0]);
if ((dest) && (dest->registered == REG_ALL) && (channel))

View File

@ -40,7 +40,7 @@ class CommandSanick : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* target = ServerInstance->FindNick(parameters[0]);
User* target = ServerInstance->Users.Find(parameters[0]);
/* Do local sanity checks and bails */
if (IS_LOCAL(user))

View File

@ -42,7 +42,7 @@ class CommandSapart : public Command
if (CommandParser::LoopCall(user, this, parameters, 1))
return CMD_FAILURE;
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
Channel* channel = ServerInstance->FindChan(parameters[1]);
std::string reason;

View File

@ -41,7 +41,7 @@ class CommandSaquit : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
if ((dest) && (dest->registered == REG_ALL))
{
if (dest->server->IsULine())

View File

@ -92,7 +92,7 @@ class ModuleServProtectMode : public Module, public Whois::EventListener, public
/* Check if the parameter is a valid nick/uuid
*/
User *u = ServerInstance->FindNick(param);
User *u = ServerInstance->Users.Find(param);
if (u)
{
Membership* memb = chan->GetUser(u);

View File

@ -59,11 +59,11 @@ class WhoisNoticeCmd : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
if (!dest)
return CMD_FAILURE;
User* source = ServerInstance->FindNick(parameters[1]);
User* source = ServerInstance->Users.Find(parameters[1]);
if (IS_LOCAL(dest) && source)
HandleFast(dest, source);

View File

@ -74,7 +74,7 @@ class CommandShun : public Command
std::string target = parameters[0];
User *find = ServerInstance->FindNick(target);
User *find = ServerInstance->Users.Find(target);
if ((find) && (find->registered == REG_ALL))
target = std::string("*!*@") + find->GetIPString();

View File

@ -116,7 +116,7 @@ void SpanningTreeUtilities::RouteCommand(TreeServer* origin, CommandBase* thiscm
else
{
// user target?
User* d = ServerInstance->FindNick(dest);
User* d = ServerInstance->Users.Find(dest);
if (!d || IS_LOCAL(d))
return;
TreeServer* tsd = TreeServer::Get(d)->GetRoute();

View File

@ -29,7 +29,7 @@
CmdResult CommandSVSNick::Handle(User* user, Params& parameters)
{
User* u = ServerInstance->FindNick(parameters[0]);
User* u = ServerInstance->Users.Find(parameters[0]);
if (u && IS_LOCAL(u))
{

View File

@ -34,7 +34,7 @@ std::string Translate::ModeChangeListToParams(const Modes::ChangeList::List& mod
if (mh->IsPrefixMode())
{
User* target = ServerInstance->FindNick(item.param);
User* target = ServerInstance->Users.Find(item.param);
if (target)
{
ret.append(target->uuid);

View File

@ -99,7 +99,7 @@ TreeServer* SpanningTreeUtilities::FindRouteTarget(const std::string& target)
if (server)
return server;
User* const user = ServerInstance->FindNick(target);
User* const user = ServerInstance->Users.Find(target);
if (user)
return TreeServer::Get(user);

View File

@ -110,7 +110,7 @@ class AuthQuery : public SQL::Query
void OnError(SQL::Error& error) override
{
User* user = ServerInstance->FindNick(uid);
User* user = ServerInstance->Users.Find(uid);
if (!user)
return;
pendingExt.set(user, AUTH_STATE_FAIL);

View File

@ -128,7 +128,7 @@ class OperQuery : public SQL::Query
// Call /oper after placing all blocks from the SQL table into the config->oper_blocks list.
void OperExec()
{
User* user = ServerInstance->FindNick(uid);
User* user = ServerInstance->Users.Find(uid);
LocalUser* localuser = IS_LOCAL(user);
// This should never be true
if (!localuser)

View File

@ -50,7 +50,7 @@ class CommandSwhois : public Command
CmdResult Handle(User* user, const Params& parameters) override
{
User* dest = ServerInstance->FindNick(parameters[0]);
User* dest = ServerInstance->Users.Find(parameters[0]);
if (!dest) // allow setting swhois using SWHOIS before reg
{

View File

@ -53,7 +53,7 @@ class CommandUninvite : public Command
if (IS_LOCAL(user))
u = ServerInstance->FindNickOnly(parameters[0]);
else
u = ServerInstance->FindNick(parameters[0]);
u = ServerInstance->Users.Find(parameters[0]);
Channel* c = ServerInstance->FindChan(parameters[1]);

View File

@ -435,6 +435,17 @@ already_sent_t UserManager::NextAlreadySentId()
return already_sent_id;
}
User* UserManager::Find(const std::string& nickuuid)
{
if (nickuuid.empty())
return nullptr;
if (isdigit(nickuuid[0]))
return FindUUID(nickuuid);
return FindNick(nickuuid);
}
User* UserManager::FindUUID(const std::string& uuid)
{
if (uuid.empty())