Add keepalive advanced preference.

This commit is contained in:
Pentarctagon 2022-10-01 22:01:35 -05:00 committed by Pentarctagon
parent 94962e6365
commit 03598585c1
4 changed files with 27 additions and 11 deletions

View file

@ -71,15 +71,6 @@
default=yes
[/advanced_preference]
#[advanced_preference]
# field=dummy_slider
# name="Dummy Slider"
# type=int
# default=42
# min=0
# max=50
#[/advanced_preference]
[advanced_preference]
field=chat_message_aging
name= _ "Chat message aging"
@ -170,3 +161,14 @@
max=150
step=5
[/advanced_preference]
[advanced_preference]
field=keepalive_timeout
name= _ "Server disconnect timeout"
description= _ "The amount of time in seconds before a disconnect is detected. If currently logged into the multiplayer server, you must log out and then log back in for this to take effect."
type=int
default=10
min=10
max=300
step=5
[/advanced_preference]

View file

@ -505,6 +505,16 @@ int font_scaled(int size)
return (size * font_scaling()) / 100;
}
int keepalive_timeout()
{
return prefs["keepalive_timeout"].to_int(10);
}
void keepalive_timeout(int seconds)
{
prefs["keepalive_timeout"] = std::abs(seconds);
}
bool idle_anim()
{
return get("idle_anim", true);

View file

@ -106,6 +106,9 @@ namespace preferences {
void set_font_scaling(int scale);
int font_scaled(int size);
int keepalive_timeout();
void keepalive_timeout(int seconds);
bool idle_anim();
void set_idle_anim(const bool ison);

View file

@ -20,6 +20,7 @@
#include "gettext.hpp"
#include "gui/dialogs/loading_screen.hpp"
#include "log.hpp"
#include "preferences/general.hpp"
#include "serialization/parser.hpp"
#include "tls_root_store.hpp"
@ -165,12 +166,12 @@ void wesnothd_connection::handle_connect(const boost::system::error_code& ec, en
}
// worker thread
// TODO: have timeout set via advanced preferences
void wesnothd_connection::handshake()
{
MPTEST_LOG;
set_keepalive(10);
DBG_NW << "Connecting with keepalive of: " << preferences::keepalive_timeout();
set_keepalive(preferences::keepalive_timeout());
static const uint32_t handshake = 0;
static const uint32_t tls_handshake = htonl(uint32_t(1));