From 7ce05549a106ca03d8d38587c9535cde52825003 Mon Sep 17 00:00:00 2001 From: blattersturm Date: Fri, 30 Apr 2021 11:01:40 +0200 Subject: [PATCH] tweak(net): more verbose errors for Steam auth Fixes !32. --- .../src/SteamIdentityProvider.cpp | 12 +++++-- code/components/glue/src/ConnectToNative.cpp | 34 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/code/components/citizen-server-impl/src/SteamIdentityProvider.cpp b/code/components/citizen-server-impl/src/SteamIdentityProvider.cpp index d40a88ab95..1e8a4067d0 100644 --- a/code/components/citizen-server-impl/src/SteamIdentityProvider.cpp +++ b/code/components/citizen-server-impl/src/SteamIdentityProvider.cpp @@ -88,15 +88,19 @@ static InitFunction initFunction([]() return; } + HttpRequestOptions opts; + opts.addErrorBody = true; + httpClient->DoGetRequest( fmt::format("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v1/?key={0}&appid={1}&ticket={2}", g_steamApiKey->GetValue(), STEAM_APPID, it->second), - [this, cb, clientPtr](bool result, const char* data, size_t size) + opts, + [this, cb, clientPtr](bool success, const char* data, size_t size) { std::string response{ data, size }; try { - if (result) + if (success) { json object = json::parse(response)["response"]; @@ -112,6 +116,10 @@ static InitFunction initFunction([]() else { trace("Steam authentication for %s^7 failed: %s\n", clientPtr->GetName(), response); + if (response.find("
key=
") != std::string::npos) + { + trace("^2Your Steam Web API key may be invalid. This can happen if you've changed your Steam password, Steam Guard details or changed/reverted your server's .cfg file. Please re-register a key on ^4https://steamcommunity.com/dev/apikey^2 and insert it in your server startup file.^7\n"); + } } cb({}); diff --git a/code/components/glue/src/ConnectToNative.cpp b/code/components/glue/src/ConnectToNative.cpp index 704e6eb69c..9f99e1da0c 100644 --- a/code/components/glue/src/ConnectToNative.cpp +++ b/code/components/glue/src/ConnectToNative.cpp @@ -459,21 +459,47 @@ static InitFunction initFunction([] () g_connected = false; }); - netLibrary->OnConnectionError.Connect([] (const char* error) + netLibrary->OnConnectionError.Connect([] (const char* errorStr) { + std::string error(errorStr); #ifdef GTA_FIVE - if (strstr(error, "This server requires a different game build")) + if (strstr(error.c_str(), "This server requires a different game build")) { RestartGameToOtherBuild(); } #endif + if (strstr(error.c_str(), "steam") || strstr(error.c_str(), "Steam")) + { + if (auto steam = GetSteam()) + { + if (steam->IsSteamRunning()) + { + if (IClientEngine* steamClient = steam->GetPrivateClient()) + { + InterfaceMapper steamUser(steamClient->GetIClientUser(steam->GetHSteamUser(), steam->GetHSteamPipe(), "CLIENTUSER_INTERFACE_VERSION001")); + + if (steamUser.IsValid()) + { + uint64_t steamID = 0; + steamUser.Invoke("GetSteamID", &steamID); + + if ((steamID & 0xFFFFFFFF00000000) != 0) + { + error += "\nThis is a Steam authentication failure, but you are running Steam and it is signed in. The server owner can find more information in their server console."; + } + } + } + } + } + } + console::Printf("no_console", "OnConnectionError: %s\n", error); g_connected = false; rapidjson::Document document; - document.SetString(error, document.GetAllocator()); + document.SetString(error.c_str(), document.GetAllocator()); rapidjson::StringBuffer sbuffer; rapidjson::Writer writer(sbuffer); @@ -482,7 +508,7 @@ static InitFunction initFunction([] () nui::PostFrameMessage("mpMenu", fmt::sprintf(R"({ "type": "connectFailed", "message": %s })", sbuffer.GetString())); - ep.Call("connectionError", std::string(error)); + ep.Call("connectionError", error); }); netLibrary->OnConnectionProgress.Connect([] (const std::string& message, int progress, int totalProgress)