Skip to content

Commit

Permalink
Made the user_id (which is apparently necessary on the server to calc…
Browse files Browse the repository at this point in the history
…ulate

number of configurations correctly) a random number, that is saved in the
config file.
  • Loading branch information
hiker committed Sep 19, 2014
1 parent 2600b17 commit c058967
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/config/hardware_stats.cpp
Expand Up @@ -22,6 +22,7 @@
#include "graphics/glwrap.hpp"
#include "graphics/irr_driver.hpp"
#include "online/http_request.hpp"
#include "utils/random_generator.hpp"
#include "utils/string_utils.hpp"

#ifdef __APPLE__
Expand Down Expand Up @@ -85,6 +86,12 @@ void reportHardwareStats()
// number is increased, a new report will be sent.
const int report_version = 1;
if(UserConfigParams::m_last_hw_report_version>=report_version) return;
while(UserConfigParams::m_random_identifier==0)
{
RandomGenerator rg;
UserConfigParams::m_random_identifier = rg.get(1<<30);
user_config->saveConfig();
}

Json json;
#ifdef WIN32
Expand Down Expand Up @@ -178,22 +185,25 @@ void reportHardwareStats()
{
Log::info("HW report", "Upload successful.");
UserConfigParams::m_last_hw_report_version = m_version;
// The callback is executed by the main thread, so no need
// to worry about locks when writing the file.
user_config->saveConfig();
}
} // callback

}; // HWReportRequest
// ------------------------------------------------------------------------

Online::HTTPRequest *request = new HWReportRequest(report_version);
request->addParameter("user_id", 3);
request->addParameter("user_id", UserConfigParams::m_random_identifier);
request->addParameter("time", StkTime::getTimeSinceEpoch());
request->addParameter("type", "hwdetect");
request->addParameter("version", report_version);
request->addParameter("data", json.toString());
request->setURL("http://stats.supertuxkart.net/upload/v1/");
//request->setURL("http://127.0.0.1:8000/upload/v1/");
// FIXME: For now: don't submit
//request->queue();
request->queue();

} // reportHardwareStats

Expand Down
10 changes: 9 additions & 1 deletion src/config/user_config.hpp
Expand Up @@ -680,9 +680,17 @@ namespace UserConfigParams
"wasn't asked, 1: allowed, 2: "
"not allowed") );

PARAM_PREFIX GroupUserConfigParam m_hw_report_group
PARAM_DEFAULT( GroupUserConfigParam("HWReport",
"Everything related to hardware configuration.") );

PARAM_PREFIX IntUserConfigParam m_last_hw_report_version
PARAM_DEFAULT( IntUserConfigParam(0, "Version of hardware report "
PARAM_DEFAULT( IntUserConfigParam(0, "report-version", &m_hw_report_group,
"Version of hardware report "
"that was reported last") );
PARAM_PREFIX IntUserConfigParam m_random_identifier
PARAM_DEFAULT( IntUserConfigParam(0, "random-identifier", &m_hw_report_group,
"A random number to avoid duplicated reports") );

// ---- User management

Expand Down

0 comments on commit c058967

Please sign in to comment.