Changeset View
Changeset View
Standalone View
Standalone View
source/ps/UserReport.cpp
Show All 22 Lines | |||||
#include "lib/utf8.h" | #include "lib/utf8.h" | ||||
#include "lib/external_libraries/curl.h" | #include "lib/external_libraries/curl.h" | ||||
#include "lib/external_libraries/zlib.h" | #include "lib/external_libraries/zlib.h" | ||||
#include "lib/file/archive/stream.h" | #include "lib/file/archive/stream.h" | ||||
#include "lib/os_path.h" | #include "lib/os_path.h" | ||||
#include "lib/sysdep/sysdep.h" | #include "lib/sysdep/sysdep.h" | ||||
#include "ps/ConfigDB.h" | #include "ps/ConfigDB.h" | ||||
#include "ps/Filesystem.h" | #include "ps/Filesystem.h" | ||||
#include "ps/GUID.h" | |||||
#include "ps/Profiler2.h" | #include "ps/Profiler2.h" | ||||
#include "ps/Pyrogenesis.h" | #include "ps/Pyrogenesis.h" | ||||
#include "ps/Threading.h" | #include "ps/Threading.h" | ||||
#include <condition_variable> | #include <condition_variable> | ||||
#include <deque> | #include <deque> | ||||
#include <fstream> | #include <fstream> | ||||
#include <mutex> | #include <mutex> | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | struct CUserReport | ||||
std::string m_Type; | std::string m_Type; | ||||
int m_Version; | int m_Version; | ||||
std::string m_Data; | std::string m_Data; | ||||
}; | }; | ||||
class CUserReporterWorker | class CUserReporterWorker | ||||
{ | { | ||||
public: | public: | ||||
CUserReporterWorker(const std::string& userID, const std::string& url) : | CUserReporterWorker(const CStr& userID, const CStr& url) : | ||||
m_URL(url), m_UserID(userID), m_Enabled(false), m_Shutdown(false), m_Status("disabled"), | m_URL(url), m_UserID(userID), m_Enabled(false), m_Shutdown(false), m_Status("disabled"), | ||||
m_PauseUntilTime(timer_Time()), m_LastUpdateTime(timer_Time()) | m_PauseUntilTime(timer_Time()), m_LastUpdateTime(timer_Time()) | ||||
{ | { | ||||
// Set up libcurl: | // Set up libcurl: | ||||
m_Curl = curl_easy_init(); | m_Curl = curl_easy_init(); | ||||
ENSURE(m_Curl); | ENSURE(m_Curl); | ||||
▲ Show 20 Lines • Show All 408 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
} | } | ||||
CUserReporter::~CUserReporter() | CUserReporter::~CUserReporter() | ||||
{ | { | ||||
ENSURE(!m_Worker); // Deinitialize should have been called before shutdown | ENSURE(!m_Worker); // Deinitialize should have been called before shutdown | ||||
} | } | ||||
std::string CUserReporter::LoadUserID() | CStr CUserReporter::LoadUserID() | ||||
{ | { | ||||
std::string userID; | CStr userID; | ||||
// Read the user ID from user.cfg (if there is one) | // Read the user ID from user.cfg (if there is one) | ||||
CFG_GET_VAL("userreport.id", userID); | CFG_GET_VAL("userreport.id", userID); | ||||
// If we don't have a validly-formatted user ID, generate a new one | if (userID.length() == 16) | ||||
if (userID.length() != 16) | return userID; | ||||
{ | |||||
u8 bytes[8] = {0}; | |||||
sys_generate_random_bytes(bytes, ARRAY_SIZE(bytes)); | |||||
// ignore failures - there's not much we can do about it | |||||
userID = ""; | // We don't have a validly-formatted user ID, generate a new one | ||||
for (size_t i = 0; i < ARRAY_SIZE(bytes); ++i) | const CStr newUserID = PS::GenerateGUID(); | ||||
{ | |||||
char hex[3]; | |||||
sprintf_s(hex, ARRAY_SIZE(hex), "%02x", (unsigned int)bytes[i]); | |||||
userID += hex; | |||||
} | |||||
g_ConfigDB.SetValueString(CFG_USER, "userreport.id", userID); | g_ConfigDB.SetValueString(CFG_USER, "userreport.id", newUserID); | ||||
g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.id", userID); | g_ConfigDB.WriteValueToFile(CFG_USER, "userreport.id", newUserID); | ||||
} | |||||
return userID; | return newUserID; | ||||
Stan: implicit cast. | |||||
Done Inline Actionsps_generate_guid implicitly converts the other way. phosit: `ps_generate_guid` implicitly converts the other way.
I'll make `ps_generate_guid` to return a… | |||||
Not Done Inline ActionsOk Stan: Ok | |||||
} | } | ||||
bool CUserReporter::IsReportingEnabled() | bool CUserReporter::IsReportingEnabled() | ||||
{ | { | ||||
int version = -1; | int version = -1; | ||||
CFG_GET_VAL("userreport.enabledversion", version); | CFG_GET_VAL("userreport.enabledversion", version); | ||||
return (version >= REPORTER_VERSION); | return (version >= REPORTER_VERSION); | ||||
} | } | ||||
Show All 15 Lines | std::string CUserReporter::GetStatus() | ||||
return m_Worker->GetStatus(); | return m_Worker->GetStatus(); | ||||
} | } | ||||
void CUserReporter::Initialize() | void CUserReporter::Initialize() | ||||
{ | { | ||||
ENSURE(!m_Worker); // must only be called once | ENSURE(!m_Worker); // must only be called once | ||||
std::string userID = LoadUserID(); | CStr userID = LoadUserID(); | ||||
std::string url; | CStr url; | ||||
CFG_GET_VAL("userreport.url_upload", url); | CFG_GET_VAL("userreport.url_upload", url); | ||||
m_Worker = new CUserReporterWorker(userID, url); | m_Worker = new CUserReporterWorker(userID, url); | ||||
m_Worker->SetEnabled(IsReportingEnabled()); | m_Worker->SetEnabled(IsReportingEnabled()); | ||||
} | } | ||||
void CUserReporter::Deinitialize() | void CUserReporter::Deinitialize() | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
implicit cast.