Factorize GetGuidFilePath
This commit is contained in:
parent
4ff1337358
commit
6b780150a3
@ -326,6 +326,16 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Auth::GetGUIDFilePath()
|
||||||
|
{
|
||||||
|
const auto appdata = Components::FileSystem::GetAppdataPath();
|
||||||
|
Utils::IO::CreateDir(appdata.string());
|
||||||
|
|
||||||
|
const auto guidPath = appdata / "guid.dat";
|
||||||
|
|
||||||
|
return guidPath.string();
|
||||||
|
}
|
||||||
|
|
||||||
void ClientConnectFailedStub(Game::netsrc_t sock, Game::netadr_t adr, const char* data)
|
void ClientConnectFailedStub(Game::netsrc_t sock, Game::netadr_t adr, const char* data)
|
||||||
{
|
{
|
||||||
Logger::PrintFail2Ban("Failed connect attempt from IP address: {}\n", Network::AdrToString(adr));
|
Logger::PrintFail2Ban("Failed connect attempt from IP address: {}\n", Network::AdrToString(adr));
|
||||||
@ -359,7 +369,8 @@ namespace Components
|
|||||||
cert.set_ctoken(ComputeToken.toString());
|
cert.set_ctoken(ComputeToken.toString());
|
||||||
cert.set_privatekey(GuidKey.serialize(PK_PRIVATE));
|
cert.set_privatekey(GuidKey.serialize(PK_PRIVATE));
|
||||||
|
|
||||||
Utils::IO::WriteFile("players/guid.dat", cert.SerializeAsString());
|
const auto guidPath = GetGUIDFilePath();
|
||||||
|
Utils::IO::WriteFile(guidPath, cert.SerializeAsString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,24 +387,21 @@ namespace Components
|
|||||||
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
|
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
|
||||||
if (!force && GuidKey.isValid()) return;
|
if (!force && GuidKey.isValid()) return;
|
||||||
|
|
||||||
const auto appdata = Components::FileSystem::GetAppdataPath();
|
const auto guidPath = GetGUIDFilePath();
|
||||||
Utils::IO::CreateDir(appdata.string());
|
|
||||||
|
|
||||||
const auto guidPath = appdata / "guid.dat";
|
|
||||||
|
|
||||||
#ifndef REGENERATE_INVALID_KEY
|
#ifndef REGENERATE_INVALID_KEY
|
||||||
// Migrate old file
|
// Migrate old file
|
||||||
const auto oldGuidPath = "players/guid.dat";
|
const auto oldGuidPath = "players/guid.dat";
|
||||||
if (Utils::IO::FileExists(oldGuidPath))
|
if (Utils::IO::FileExists(oldGuidPath))
|
||||||
{
|
{
|
||||||
if (MoveFileA(oldGuidPath, guidPath.string().data()))
|
if (MoveFileA(oldGuidPath, guidPath.data()))
|
||||||
{
|
{
|
||||||
Utils::IO::RemoveFile(oldGuidPath);
|
Utils::IO::RemoveFile(oldGuidPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const auto guidFile = Utils::IO::ReadFile(guidPath.string());
|
const auto guidFile = Utils::IO::ReadFile(guidPath);
|
||||||
|
|
||||||
Proto::Auth::Certificate cert;
|
Proto::Auth::Certificate cert;
|
||||||
if (cert.ParseFromString(guidFile))
|
if (cert.ParseFromString(guidFile))
|
||||||
|
@ -55,6 +55,8 @@ namespace Components
|
|||||||
static char* Info_ValueForKeyStub(const char* s, const char* key);
|
static char* Info_ValueForKeyStub(const char* s, const char* key);
|
||||||
static void DirectConnectPrivateClientStub();
|
static void DirectConnectPrivateClientStub();
|
||||||
|
|
||||||
|
static std::string GetGUIDFilePath();
|
||||||
|
|
||||||
static void Frame();
|
static void Frame();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user