| 1793 | } |
| 1794 | |
| 1795 | bool Achievements::Login(const char* username, const char* password, Error* error) |
| 1796 | { |
| 1797 | auto lock = GetLock(); |
| 1798 | |
| 1799 | // We need to use a temporary client if achievements aren't currently active. |
| 1800 | rc_client_t* client = s_client; |
| 1801 | HTTPDownloader* http = s_http_downloader.get(); |
| 1802 | const bool is_temporary_client = (client == nullptr); |
| 1803 | std::unique_ptr<HTTPDownloader> temporary_downloader; |
| 1804 | ScopedGuard temporary_client_guard = [&client, is_temporary_client, &temporary_downloader]() { |
| 1805 | if (is_temporary_client) |
| 1806 | DestroyClient(&client, &temporary_downloader); |
| 1807 | }; |
| 1808 | if (is_temporary_client) |
| 1809 | { |
| 1810 | if (!CreateClient(&client, &temporary_downloader)) |
| 1811 | { |
| 1812 | Error::SetString(error, "Failed to create client."); |
| 1813 | return false; |
| 1814 | } |
| 1815 | http = temporary_downloader.get(); |
| 1816 | } |
| 1817 | |
| 1818 | LoginWithPasswordParameters params = {username, error, nullptr, false}; |
| 1819 | |
| 1820 | params.request = rc_client_begin_login_with_password(client, username, password, ClientLoginWithPasswordCallback, ¶ms); |
| 1821 | if (!params.request) |
| 1822 | { |
| 1823 | Error::SetString(error, "Failed to create login request."); |
| 1824 | return false; |
| 1825 | } |
| 1826 | |
| 1827 | // Wait until the login request completes. |
| 1828 | http->WaitForAllRequests(); |
| 1829 | pxAssert(!params.request); |
| 1830 | |
| 1831 | // Success? Assume the callback set the error message. |
| 1832 | if (!params.result) |
| 1833 | return false; |
| 1834 | |
| 1835 | // If we were't a temporary client, get the game loaded. |
| 1836 | if (VMManager::HasValidVM() && !is_temporary_client) |
| 1837 | BeginLoadGame(); |
| 1838 | |
| 1839 | return true; |
| 1840 | } |
| 1841 | |
| 1842 | |
| 1843 | void Achievements::ClientLoginWithPasswordCallback(int result, const char* error_message, rc_client_t* client, void* userdata) |
nothing calls this directly
no test coverage detected