diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index 08931f79..36b49af3 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -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) { Logger::PrintFail2Ban("Failed connect attempt from IP address: {}\n", Network::AdrToString(adr)); @@ -358,8 +368,9 @@ namespace Components cert.set_token(GuidToken.toString()); cert.set_ctoken(ComputeToken.toString()); 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 (!force && GuidKey.isValid()) return; - const auto appdata = Components::FileSystem::GetAppdataPath(); - Utils::IO::CreateDir(appdata.string()); - - const auto guidPath = appdata / "guid.dat"; + const auto guidPath = GetGUIDFilePath(); #ifndef REGENERATE_INVALID_KEY // Migrate old file const auto oldGuidPath = "players/guid.dat"; if (Utils::IO::FileExists(oldGuidPath)) { - if (MoveFileA(oldGuidPath, guidPath.string().data())) + if (MoveFileA(oldGuidPath, guidPath.data())) { Utils::IO::RemoveFile(oldGuidPath); } } #endif - const auto guidFile = Utils::IO::ReadFile(guidPath.string()); + const auto guidFile = Utils::IO::ReadFile(guidPath); Proto::Auth::Certificate cert; if (cert.ParseFromString(guidFile)) diff --git a/src/Components/Modules/Auth.hpp b/src/Components/Modules/Auth.hpp index 4644281c..1d56c1b0 100644 --- a/src/Components/Modules/Auth.hpp +++ b/src/Components/Modules/Auth.hpp @@ -55,6 +55,8 @@ namespace Components static char* Info_ValueForKeyStub(const char* s, const char* key); static void DirectConnectPrivateClientStub(); + static std::string GetGUIDFilePath(); + static void Frame(); }; }