Authenticator: avoid move assignments to self (#5315)
If authentication was off cClientHandle::m_Username ended up moved into itself. Add a copy to avoid this. Thanks @Seadragon91!
This commit is contained in:
parent
1e4850a6c5
commit
1d72306bae
@ -335,8 +335,7 @@ bool cClientHandle::BungeeAuthenticate()
|
|||||||
|
|
||||||
void cClientHandle::Authenticate(AString && a_Name, const cUUID & a_UUID, Json::Value && a_Properties)
|
void cClientHandle::Authenticate(AString && a_Name, const cUUID & a_UUID, Json::Value && a_Properties)
|
||||||
{
|
{
|
||||||
{
|
cCSLock Lock(m_CSState);
|
||||||
cCSLock lock(m_CSState);
|
|
||||||
/*
|
/*
|
||||||
LOGD("Processing authentication for client %s @ %s (%p), state = %d",
|
LOGD("Processing authentication for client %s @ %s (%p), state = %d",
|
||||||
m_Username.c_str(), m_IPString.c_str(), static_cast<void *>(this), m_State.load()
|
m_Username.c_str(), m_IPString.c_str(), static_cast<void *>(this), m_State.load()
|
||||||
@ -378,7 +377,6 @@ void cClientHandle::Authenticate(AString && a_Name, const cUUID & a_UUID, Json::
|
|||||||
{
|
{
|
||||||
FinishAuthenticate();
|
FinishAuthenticate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -745,8 +743,8 @@ bool cClientHandle::HandleLogin()
|
|||||||
m_State = csAuthenticating;
|
m_State = csAuthenticating;
|
||||||
} // lock(m_CSState)
|
} // lock(m_CSState)
|
||||||
|
|
||||||
// Schedule for authentication; until then, let the player wait (but do not block)
|
// Schedule for authentication; until then, let the player wait (but do not block):
|
||||||
cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), std::move(m_Username), m_Protocol->GetAuthServerID());
|
cRoot::Get()->GetAuthenticator().Authenticate(GetUniqueID(), m_Username, m_Protocol->GetAuthServerID());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,17 +57,23 @@ void cAuthenticator::ReadSettings(cSettingsRepositoryInterface & a_Settings)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cAuthenticator::Authenticate(int a_ClientID, AString && a_Username, const AString & a_ServerHash)
|
void cAuthenticator::Authenticate(int a_ClientID, const std::string_view a_Username, const std::string_view a_ServerHash)
|
||||||
{
|
{
|
||||||
if (!m_ShouldAuthenticate)
|
if (!m_ShouldAuthenticate)
|
||||||
{
|
{
|
||||||
const auto UUID = cClientHandle::GenerateOfflineUUID(a_Username);
|
// An "authenticated" username, which is just what the client sent since auth is off.
|
||||||
cRoot::Get()->GetServer()->AuthenticateUser(a_ClientID, std::move(a_Username), UUID, Json::Value{});
|
std::string OfflineUsername(a_Username);
|
||||||
|
|
||||||
|
// A specially constructed UUID based wholly on the username.
|
||||||
|
const auto OfflineUUID = cClientHandle::GenerateOfflineUUID(OfflineUsername);
|
||||||
|
|
||||||
|
// "Authenticate" the user based on what little information we have:
|
||||||
|
cRoot::Get()->GetServer()->AuthenticateUser(a_ClientID, std::move(OfflineUsername), OfflineUUID, Json::Value());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cCSLock Lock(m_CS);
|
cCSLock Lock(m_CS);
|
||||||
m_Queue.emplace_back(a_ClientID, std::move(a_Username), a_ServerHash);
|
m_Queue.emplace_back(a_ClientID, a_Username, a_ServerHash);
|
||||||
m_QueueNonempty.Set();
|
m_QueueNonempty.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,17 +120,17 @@ void cAuthenticator::Execute(void)
|
|||||||
|
|
||||||
cAuthenticator::cUser User = std::move(m_Queue.front());
|
cAuthenticator::cUser User = std::move(m_Queue.front());
|
||||||
int & ClientID = User.m_ClientID;
|
int & ClientID = User.m_ClientID;
|
||||||
AString & UserName = User.m_Name;
|
AString & Username = User.m_Name;
|
||||||
AString & ServerID = User.m_ServerID;
|
AString & ServerID = User.m_ServerID;
|
||||||
m_Queue.pop_front();
|
m_Queue.pop_front();
|
||||||
Lock.Unlock();
|
Lock.Unlock();
|
||||||
|
|
||||||
cUUID UUID;
|
cUUID UUID;
|
||||||
Json::Value Properties;
|
Json::Value Properties;
|
||||||
if (AuthWithYggdrasil(UserName, ServerID, UUID, Properties))
|
if (AuthWithYggdrasil(Username, ServerID, UUID, Properties))
|
||||||
{
|
{
|
||||||
LOGINFO("User %s authenticated with UUID %s", UserName.c_str(), UUID.ToShortString().c_str());
|
LOGINFO("User %s authenticated with UUID %s", Username.c_str(), UUID.ToShortString().c_str());
|
||||||
cRoot::Get()->GetServer()->AuthenticateUser(ClientID, std::move(UserName), UUID, std::move(Properties));
|
cRoot::Get()->GetServer()->AuthenticateUser(ClientID, std::move(Username), UUID, std::move(Properties));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
void ReadSettings(cSettingsRepositoryInterface & a_Settings);
|
void ReadSettings(cSettingsRepositoryInterface & a_Settings);
|
||||||
|
|
||||||
/** Queues a request for authenticating a user. If the auth fails, the user will be kicked */
|
/** Queues a request for authenticating a user. If the auth fails, the user will be kicked */
|
||||||
void Authenticate(int a_ClientID, AString && a_Username, const AString & a_ServerHash);
|
void Authenticate(int a_ClientID, std::string_view a_Username, std::string_view a_ServerHash);
|
||||||
|
|
||||||
/** Starts the authenticator thread. The thread may be started and stopped repeatedly */
|
/** Starts the authenticator thread. The thread may be started and stopped repeatedly */
|
||||||
void Start(cSettingsRepositoryInterface & a_Settings);
|
void Start(cSettingsRepositoryInterface & a_Settings);
|
||||||
@ -58,7 +58,7 @@ private:
|
|||||||
AString m_Name;
|
AString m_Name;
|
||||||
AString m_ServerID;
|
AString m_ServerID;
|
||||||
|
|
||||||
cUser(int a_ClientID, const AString & a_Name, const AString & a_ServerID) :
|
cUser(int a_ClientID, const std::string_view a_Name, const std::string_view a_ServerID) :
|
||||||
m_ClientID(a_ClientID),
|
m_ClientID(a_ClientID),
|
||||||
m_Name(a_Name),
|
m_Name(a_Name),
|
||||||
m_ServerID(a_ServerID)
|
m_ServerID(a_ServerID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user