; This file is part of OpenTTD.
; OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
; OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
; See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
;

; Network settings as stored in the main configuration file ("openttd.cfg").

[pre-amble]
static void UpdateClientConfigValues();
void ChangeNetworkRestartTime(bool reset);

static constexpr std::initializer_list<std::string_view> _server_game_type{"local"sv, "public"sv, "invite-only"sv};

static const SettingVariant _network_settings_table[] = {
[post-amble]
};
[templates]
SDTC_BOOL  =  SDTC_BOOL(              $var,        SettingFlags({$flags}), $def,                              $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $def_cb, $from, $to,        $cat, $extra, $startup),
SDTC_OMANY = SDTC_OMANY(              $var, $type, SettingFlags({$flags}), $def,             $max, $full,     $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $def_cb, $from, $to,        $cat, $extra, $startup),
SDTC_VAR   =   SDTC_VAR(              $var, $type, SettingFlags({$flags}), $def,       $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $str_cb, $help_cb, $val_cb, $def_cb, $range_cb, $from, $to,        $cat, $extra, $startup),

[validation]
SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
SDTC_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");

[defaults]
flags    =
interval = 0
str      = STR_NULL
strhelp  = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT
strval   = STR_NULL
pre_cb   = nullptr
post_cb  = nullptr
str_cb   = nullptr
help_cb  = nullptr
val_cb   = nullptr
def_cb   = nullptr
range_cb = nullptr
load     = nullptr
from     = SL_MIN_VERSION
to       = SL_MAX_VERSION
cat      = SC_ADVANCED
extra    = 0
startup  = false


[SDTC_VAR]
var      = network.sync_freq
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NotInConfig, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 100
min      = 0
max      = 100
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.frame_freq
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NotInConfig, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 0
min      = 0
max      = 100
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.commands_per_frame
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 2
min      = 1
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.commands_per_frame_server
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 16
min      = 1
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.max_commands_in_queue
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 16
min      = 1
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.bytes_per_frame
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 8
min      = 1
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.bytes_per_frame_burst
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 256
min      = 1
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.max_init_time
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 100
min      = 0
max      = 32000
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.max_join_time
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 500
min      = 0
max      = 32000

[SDTC_VAR]
var      = network.max_download_time
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 1000
min      = 0
max      = 32000

[SDTC_VAR]
var      = network.max_password_time
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 2000
min      = 0
max      = 32000

[SDTC_VAR]
var      = network.max_lag_time
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 500
min      = 0
max      = 32000

[SDTC_BOOL]
var      = network.pause_on_join
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = true

[SDTC_VAR]
var      = network.server_port
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = NETWORK_DEFAULT_PORT
min      = 0
max      = 65535
cat      = SC_EXPERT

[SDTC_VAR]
var      = network.server_admin_port
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = NETWORK_ADMIN_PORT
min      = 0
max      = 65535
cat      = SC_EXPERT

[SDTC_BOOL]
var      = network.server_admin_chat
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = true
cat      = SC_EXPERT

[SDTC_BOOL]
var      = network.allow_insecure_admin_login
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = false
cat      = SC_EXPERT

[SDTC_OMANY]
var      = network.server_game_type
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = SERVER_GAME_TYPE_LOCAL
min      = SERVER_GAME_TYPE_LOCAL
max      = SERVER_GAME_TYPE_INVITE_ONLY
full     = _server_game_type
post_cb  = [](auto) { NetworkUpdateServerGameType(); }
cat      = SC_BASIC

[SDTC_BOOL]
var      = network.autoclean_companies
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = false

[SDTC_VAR]
var      = network.autoclean_protected
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::GuiZeroIsSpecial, SettingFlag::NetworkOnly
def      = 36
min      = 0
max      = 240

[SDTC_VAR]
var      = network.autoclean_novehicles
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::GuiZeroIsSpecial, SettingFlag::NetworkOnly
def      = 0
min      = 0
max      = 240

[SDTC_VAR]
var      = network.max_companies
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 15
min      = 1
max      = MAX_COMPANIES
post_cb  = [](auto) { UpdateClientConfigValues(); }
cat      = SC_BASIC

[SDTC_VAR]
var      = network.max_clients
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 25
min      = 2
max      = MAX_CLIENTS
post_cb  = [](auto) { UpdateClientConfigValues(); }
cat      = SC_BASIC

[SDTC_VAR]
var      = network.restart_game_year
type     = SLE_INT32
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::GuiZeroIsSpecial, SettingFlag::NetworkOnly
def      = 0
min      = CalendarTime::MIN_YEAR
max      = CalendarTime::MAX_YEAR
interval = 1

[SDTC_VAR]
var      = network.restart_hours
type     = SLE_UINT16
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::GuiZeroIsSpecial, SettingFlag::NetworkOnly
def      = 0
min      = 0
max      = UINT16_MAX
interval = 1
post_cb  = [](auto) { ChangeNetworkRestartTime(false); }

[SDTC_VAR]
var      = network.min_active_clients
type     = SLE_UINT8
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = 0
min      = 0
max      = MAX_CLIENTS

[SDTC_BOOL]
var      = network.reload_cfg
flags    = SettingFlag::NotInSave, SettingFlag::NoNetworkSync, SettingFlag::NetworkOnly
def      = false
cat      = SC_EXPERT
