Skip to content

Commit

Permalink
tweak(net): more verbose errors for Steam auth
Browse files Browse the repository at this point in the history
Fixes !32.
  • Loading branch information
blattersturm committed Apr 30, 2021
1 parent 8f794ba commit 7ce0554
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
12 changes: 10 additions & 2 deletions code/components/citizen-server-impl/src/SteamIdentityProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -112,6 +116,10 @@ static InitFunction initFunction([]()
else
{
trace("Steam authentication for %s^7 failed: %s\n", clientPtr->GetName(), response);
if (response.find("<pre>key=</pre>") != 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({});
Expand Down
34 changes: 30 additions & 4 deletions code/components/glue/src/ConnectToNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>("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<rapidjson::StringBuffer> writer(sbuffer);
Expand All @@ -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)
Expand Down

0 comments on commit 7ce0554

Please sign in to comment.