Finish out feature

- Add periodic timer for heartbeat
- Add option to settings for opting out from heartbeat/player metrics
- Change base URL to permanent URL
This commit is contained in:
oldmud0 2021-12-18 20:29:55 -06:00
parent b682d69e49
commit f1107aeac5
7 changed files with 37 additions and 6 deletions

View File

@ -491,6 +491,9 @@ public:
// Get the default scaling method
QString get_default_scaling();
// Get whether to opt out of player count metrics sent to the master server
bool get_player_count_optout();
// Currently defined subtheme
QString subtheme;

View File

@ -177,6 +177,8 @@ private:
QWidget *ui_privacy_tab;
QVBoxLayout *ui_privacy_layout;
QCheckBox *ui_privacy_optout_cb;
QFrame *ui_privacy_separator;
QTextBrowser *ui_privacy_policy;
bool needs_default_audiodev();

View File

@ -28,10 +28,12 @@ public:
AOApplication *ao_app;
QNetworkAccessManager *http;
QTcpSocket *server_socket;
QTimer *heartbeat_timer;
QString ms_baseurl = "https://ms3.oldmud0.workers.dev";
QString ms_baseurl = "https://servers.aceattorneyonline.com";
const int timeout_milliseconds = 5000;
const int heartbeat_interval = 60 * 5;
bool partial_packet = false;
QString temp_packet = "";
@ -47,8 +49,8 @@ public slots:
void request_document(MSDocumentType document_type,
const std::function<void(QString)> &cb);
void send_heartbeat();
private slots:
void heartbeat_playing();
void ms_request_finished(QNetworkReply *reply,
const std::function<void()> &cb);

View File

@ -908,7 +908,16 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app)
ui_settings_tabs->addTab(ui_privacy_tab, tr("Privacy"));
ui_privacy_layout = new QVBoxLayout(ui_privacy_tab);
ui_privacy_layout->setContentsMargins(0, 0, 0, 0);
ui_privacy_optout_cb = new QCheckBox(ui_privacy_tab);
ui_privacy_optout_cb->setText(tr("Do not include me in public player counts"));
ui_privacy_layout->addWidget(ui_privacy_optout_cb);
ui_privacy_separator = new QFrame(ui_privacy_tab);
ui_privacy_separator->setObjectName(QString::fromUtf8("line"));
ui_privacy_separator->setFrameShape(QFrame::HLine);
ui_privacy_separator->setFrameShadow(QFrame::Sunken);
ui_privacy_layout->addWidget(ui_privacy_separator);
ui_privacy_policy = new QTextBrowser(ui_privacy_tab);
QSizePolicy privacySizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
@ -993,6 +1002,7 @@ void AOOptionsDialog::update_values() {
ui_blips_volume_spinbox->setValue(ao_app->get_default_blip());
ui_bliprate_spinbox->setValue(ao_app->read_blip_rate());
ui_default_showname_textbox->setText(ao_app->get_default_showname());
ui_privacy_optout_cb->setChecked(ao_app->get_player_count_optout());
ao_app->net_manager->request_document(MSDocumentType::PrivacyPolicy, [this](QString document) {
if (document.isEmpty())
@ -1079,11 +1089,11 @@ void AOOptionsDialog::save_pressed()
configini->setValue("casing_can_host_cases",
ui_casing_cm_cases_textbox->text());
configini->setValue("player_count_optout", ui_privacy_optout_cb->isChecked());
if (audioChanged)
ao_app->initBASS();
callwordsini->close();
// We most probably pressed "Restore defaults" at some point. Since we're saving our settings, remove the temporary file.
if (QFile::exists(ao_app->get_base_path() + "config.temp"))
QFile::remove(ao_app->get_base_path() + "config.temp");

View File

@ -56,6 +56,7 @@ int main(int argc, char *argv[])
main_app.construct_lobby();
main_app.net_manager->get_server_list(std::bind(&Lobby::list_servers, main_app.w_lobby));
main_app.net_manager->send_heartbeat();
main_app.w_lobby->show();
return main_app.exec();
}

View File

@ -14,6 +14,7 @@ NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent)
server_socket = new QTcpSocket(this);
http = new QNetworkAccessManager(this);
heartbeat_timer = new QTimer(this);
connect(server_socket, SIGNAL(readyRead()), this,
SLOT(handle_server_packet()));
@ -24,6 +25,9 @@ NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent)
ao_app->configini->value("master", "").value<QString>();
if (!master_config.isEmpty())
ms_baseurl = master_config;
connect(heartbeat_timer, &QTimer::timeout, this, &NetworkManager::send_heartbeat);
heartbeat_timer->start(heartbeat_interval);
}
NetworkManager::~NetworkManager() {}
@ -69,12 +73,15 @@ void NetworkManager::ms_request_finished(QNetworkReply *reply,
reply->deleteLater();
}
void NetworkManager::heartbeat_playing()
void NetworkManager::send_heartbeat()
{
// Ping the server periodically to tell the MS that you've been playing
// within a 5 minute window, so that the the number of people playing within
// that time period can be counted and an accurate player count be displayed.
// What do I care about your personal information, I really don't want it.
if (ao_app->get_player_count_optout())
return;
QNetworkRequest req(QUrl(ms_baseurl + "/playing"));
req.setRawHeader("User-Agent", get_user_agent().toUtf8());
req.setTransferTimeout(timeout_milliseconds);

View File

@ -1095,3 +1095,9 @@ QString AOApplication::get_default_scaling()
{
return configini->value("default_scaling", "fast").value<QString>();
}
bool AOApplication::get_player_count_optout()
{
return configini->value("player_count_optout", "false").value<QString>()
.startsWith("true");
}