17#include "../3rdparty/fmt/chrono.h"
42 nlohmann::json survey;
45 survey[
"reason"] = reason;
46 survey[
"date"] = fmt::format(
"{:%Y-%m-%d %H:%M:%S} (UTC)", fmt::gmtime(time(
nullptr)));
50 survey[
"key"] = for_preview ?
"(redacted)" : SURVEY_KEY;
58 auto &info = survey[
"info"];
69 auto &game = survey[
"game"];
78 int indent = for_preview ? 4 : -1;
79 return survey.dump(indent);
104 std::unique_lock<std::mutex>
lock(this->
mutex);
107 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now() + std::chrono::seconds(2);
109 while (!this->
transmitted && std::chrono::steady_clock::now() < end) {
125 if (data ==
nullptr) {
static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data="")
Connect to the given URI.
Socket handler for the survey connection.
void OnFailure() override
An error has occurred and the connection has been closed.
std::atomic< bool > transmitted
Whether the survey has been transmitted.
std::condition_variable transmitted_cv
Condition variable to inform changes to transmitted.
static constexpr bool IsSurveyPossible()
Check whether a survey is possible.
void OnReceiveData(std::unique_ptr< char[]> data, size_t length) override
We're receiving data.
Reason
Reason why the survey data is being sent.
@ Preview
User is previewing the survey result.
@ Leave
User is leaving the game (but not exiting the application).
@ Exit
User is exiting the application.
std::mutex mutex
Mutex for the condition variable.
std::string CreatePayload(Reason reason, bool for_preview=false)
Create the payload for the survey.
void Transmit(Reason reason, bool blocking=false)
Transmit the survey.
std::string_view NetworkSurveyUriString()
Get the URI string for the survey from the environment variable OTTD_SURVEY_URI, or when it has not b...
Configuration options of the network stuff.
static const uint8_t NETWORK_SURVEY_VERSION
What version of the survey do we use?
Functions related to debugging.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Net
Net message facility.
@ Debug1
Debug #1 - High level debug messages.
@ Info
Info, information you might care about.
@ Error
Error, but we are recovering.
void NetworkBackgroundLoop()
We have to do some (simple) background stuff that runs normally, even when we are not in multiplayer.
Network functions used by other parts of OpenTTD.
NetworkSurveyHandler _survey
The handler for sending surveys for statistics.
Part of the network protocol handling opt-in survey.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.
void SurveySettings(nlohmann::json &survey, bool skip_if_default)
Convert settings to JSON.
void SurveyPlugins(nlohmann::json &survey)
Convert plugin information to JSON.
void SurveyTimers(nlohmann::json &survey)
Convert timer information to JSON.
void SurveyGameSession(nlohmann::json &survey)
Convert game session information to JSON.
void SurveyGameScript(nlohmann::json &survey)
Convert game-script information to JSON.
void SurveyConfiguration(nlohmann::json &survey)
Convert generic game information to JSON.
void SurveyOpenTTD(nlohmann::json &survey)
Convert generic OpenTTD information to JSON.
void SurveyFont(nlohmann::json &survey)
Convert font information to JSON.
void SurveyCompanies(nlohmann::json &survey)
Convert company information to JSON.
void SurveyCompiler(nlohmann::json &survey)
Convert compiler information to JSON.
void SurveyLibraries(nlohmann::json &survey)
Convert compiled libraries information to JSON.
void SurveyGrfs(nlohmann::json &survey)
Convert GRF information to JSON.
Functions to survey the current game / system, for crashlog and network-survey.
std::mutex lock
synchronization for playback status fields