mirror of
https://github.com/SantaSpeen/BeamMP-Server.git
synced 2025-07-03 06:55:25 +00:00
Config: Add basic opt-out for Sentry
This commit is contained in:
parent
3cd94380e2
commit
ffac000cd2
@ -3,7 +3,7 @@
|
||||
- ADDED Ctrl+C causes a graceful shutdown on windows (did already on linux)
|
||||
- ADDED more meaningful shutdown messages
|
||||
- ADDED even better backend connection error reporting
|
||||
-
|
||||
- ADDED `SendErrors` config in `ServerConfig.toml` to opt-out of error reporting
|
||||
|
||||
# v2.3.1
|
||||
|
||||
|
@ -30,7 +30,8 @@ public:
|
||||
, Private(false)
|
||||
, MaxCars(1)
|
||||
, DebugModeEnabled(false)
|
||||
, Port(30814) { }
|
||||
, Port(30814)
|
||||
, SendErrors(true) { }
|
||||
std::string ServerName;
|
||||
std::string ServerDesc;
|
||||
std::string Resource;
|
||||
@ -42,6 +43,7 @@ public:
|
||||
bool DebugModeEnabled;
|
||||
int Port;
|
||||
std::string CustomIP;
|
||||
bool SendErrors;
|
||||
[[nodiscard]] bool HasCustomIP() const { return !CustomIP.empty(); }
|
||||
};
|
||||
using TShutdownHandler = std::function<void()>;
|
||||
|
@ -18,6 +18,7 @@ static constexpr std::string_view StrName = "Name";
|
||||
static constexpr std::string_view StrDescription = "Description";
|
||||
static constexpr std::string_view StrResourceFolder = "ResourceFolder";
|
||||
static constexpr std::string_view StrAuthKey = "AuthKey";
|
||||
static constexpr std::string_view StrSendErrors = "SendErrors";
|
||||
|
||||
TConfig::TConfig() {
|
||||
if (!fs::exists(ConfigFileName) || !fs::is_regular_file(ConfigFileName)) {
|
||||
@ -32,6 +33,13 @@ TConfig::TConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
void WriteSendErrors(const std::string& name) {
|
||||
std::ofstream CfgFile { name, std::ios::out | std::ios::app };
|
||||
CfgFile << "# If SendErrors is `true`, the server will send helpful info about crashes and other issues back to the BeamMP developers. This info may include your config, who is on your server at the time of the error, and similar data. You can opt-out of this system by setting this to `false`."
|
||||
<< std::endl
|
||||
<< StrSendErrors << " = true" << std::endl;
|
||||
}
|
||||
|
||||
void TConfig::CreateConfigFile(std::string_view name) {
|
||||
// build from old config Server.cfg
|
||||
|
||||
@ -59,6 +67,7 @@ void TConfig::CreateConfigFile(std::string_view name) {
|
||||
{ StrDescription, Application::Settings.ServerDesc },
|
||||
{ StrResourceFolder, Application::Settings.Resource },
|
||||
{ StrAuthKey, Application::Settings.Key },
|
||||
//{ StrSendErrors, Application::Settings.SendErrors },
|
||||
|
||||
} } },
|
||||
|
||||
@ -72,6 +81,8 @@ void TConfig::CreateConfigFile(std::string_view name) {
|
||||
ofs << tbl << '\n';
|
||||
error("There was no \"" + std::string(ConfigFileName) + "\" file (this is normal for the first time running the server), so one was generated for you. It was automatically filled with the settings from your Server.cfg, if you have one. Please open ServerConfig.toml and ensure your AuthKey and other settings are filled in and correct, then restart the server. The old Server.cfg file will no longer be used and causes a warning if it exists from now on.");
|
||||
mFailed = true;
|
||||
ofs.close();
|
||||
WriteSendErrors(std::string(name));
|
||||
} else {
|
||||
error("Couldn't create " + std::string(name) + ". Check permissions, try again, and contact support if it continues not to work.");
|
||||
mFailed = true;
|
||||
@ -132,6 +143,13 @@ void TConfig::ParseFromFile(std::string_view name) {
|
||||
} else {
|
||||
throw std::runtime_error(std::string(StrAuthKey));
|
||||
}
|
||||
// added later, so behaves differently
|
||||
if (auto val = GeneralTable[StrSendErrors].value<bool>(); val.has_value()) {
|
||||
Application::Settings.SendErrors = val.value();
|
||||
} else {
|
||||
// dont throw, instead write it into the file and use default
|
||||
WriteSendErrors(std::string(name));
|
||||
}
|
||||
} catch (const std::exception& err) {
|
||||
error("Error parsing config file value: " + std::string(err.what()));
|
||||
mFailed = true;
|
||||
|
@ -34,9 +34,14 @@ TSentry::~TSentry() {
|
||||
|
||||
void TSentry::PrintWelcome() {
|
||||
if (mValid) {
|
||||
info("Sentry started");
|
||||
if (!Application::Settings.SendErrors) {
|
||||
mValid = false;
|
||||
info("Opted out of error reporting (SendErrors), Sentry disabled.");
|
||||
} else {
|
||||
info("Sentry started! Reporting errors automatically. You can opt-out of this in the ServerConfig.");
|
||||
}
|
||||
} else {
|
||||
info("Sentry disabled in unofficial build");
|
||||
info("Sentry disabled in unofficial build. Automatic error reporting disabled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user