|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
10 #include "../stdafx.h"
16 #include "../survey.h"
17 #include "../3rdparty/fmt/chrono.h"
18 #include "../3rdparty/fmt/std.h"
20 #include "../safeguards.h"
40 std::string NetworkSurveyHandler::CreatePayload(Reason reason,
bool for_preview)
42 nlohmann::json survey;
45 survey[
"reason"] = reason;
47 survey[
"date"] = fmt::format(
"{:%Y-%m-%d %H:%M:%S} (UTC)", fmt::gmtime(time(
nullptr)));
51 survey[
"key"] = for_preview ?
"(redacted)" : SURVEY_KEY;
57 auto &info = survey[
"info"];
68 auto &game = survey[
"game"];
77 int indent = for_preview ? 4 : -1;
78 return survey.dump(indent);
89 if constexpr (!NetworkSurveyHandler::IsSurveyPossible()) {
90 Debug(net, 4,
"Survey: not possible to send survey; most likely due to missing JSON library at compile-time");
95 Debug(net, 5,
"Survey: user is not participating in survey; skipping survey");
99 Debug(net, 1,
"Survey: sending survey results");
103 std::unique_lock<std::mutex>
lock(this->
mutex);
106 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now() + std::chrono::seconds(2);
108 while (!this->
transmitted && std::chrono::steady_clock::now() < end) {
110 this->
transmitted_cv.wait_for(lock, std::chrono::milliseconds(30));
117 Debug(net, 1,
"Survey: failed to send survey results");
124 if (data ==
nullptr) {
125 Debug(net, 1,
"Survey: survey results sent");
void SurveyConfiguration(nlohmann::json &survey)
Convert generic game information to JSON.
std::atomic< bool > transmitted
Whether the survey has been transmitted.
void SurveyLibraries(nlohmann::json &survey)
Convert compiled libraries information to JSON.
void SurveyTimers(nlohmann::json &survey)
Convert timer information to JSON.
std::mutex lock
synchronization for playback status fields
std::string _savegame_id
Unique ID of the current savegame.
static void Connect(const std::string &uri, HTTPCallback *callback, const std::string data="")
Connect to the given URI.
ClientSettings _settings_client
The current settings for this game.
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
const char * NetworkSurveyUriString()
Get the URI string for the survey from the environment variable OTTD_SURVEY_URI, or when it has not b...
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
void SurveySettings(nlohmann::json &survey, bool skip_if_default)
Convert settings to JSON.
std::condition_variable transmitted_cv
Condition variable to inform changes to transmitted.
std::mutex mutex
Mutex for the condition variable.
void SurveyOpenTTD(nlohmann::json &survey)
Convert generic OpenTTD information to JSON.
void SurveyCompanies(nlohmann::json &survey)
Convert company information to JSON.
@ PREVIEW
User is previewing the survey result.
void SurveyGrfs(nlohmann::json &survey)
Convert GRF information to JSON.
void Transmit(Reason reason, bool blocking=false)
Transmit the survey.
void OnFailure() override
An error has occurred and the connection has been closed.
@ LEAVE
User is leaving the game (but not exiting the application).
void SurveyCompiler(nlohmann::json &survey)
Convert compiler information to JSON.
Socket handler for the survey connection.
void OnReceiveData(std::unique_ptr< char[]> data, size_t length) override
We're receiving data.
NetworkSettings network
settings related to the network
void SurveyGameScript(nlohmann::json &survey)
Convert game-script information to JSON.
void SurveyFont(nlohmann::json &survey)
Convert font information to JSON.
void SurveyPlugins(nlohmann::json &survey)
Convert plugin information to JSON.
@ EXIT
User is exiting the application.
NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, { {NetworkSurveyHandler::Reason::PREVIEW, "preview"}, {NetworkSurveyHandler::Reason::LEAVE, "leave"}, {NetworkSurveyHandler::Reason::EXIT, "exit"}, {NetworkSurveyHandler::Reason::CRASH, "crash"}, }) std
Create the payload for the survey.
ParticipateSurvey participate_survey
Participate in the automated survey.
static const byte NETWORK_SURVEY_VERSION
What version of the survey do we use?