From aa77d688ec3728a8dc75976557a895acf1e2f57c Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Mon, 6 Feb 2017 13:45:58 -0500 Subject: [PATCH] Make announcing netplay on the public lobby optional. --- config.def.h | 3 +++ configuration.c | 1 + configuration.h | 1 + intl/msg_hash_lbl.h | 2 ++ intl/msg_hash_us.c | 7 +++++++ intl/msg_hash_us.h | 6 ++++++ menu/cbs/menu_cbs_sublabel.c | 4 ++++ menu/menu_displaylist.c | 4 ++++ menu/menu_setting.c | 15 +++++++++++++++ msg_hash.h | 1 + network/netplay/netplay_frontend.c | 20 ++++++++++++++++---- 11 files changed, 60 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 0866e35bda..6b01bc9e59 100644 --- a/config.def.h +++ b/config.def.h @@ -815,6 +815,9 @@ static const bool pause_nonactive = true; * It is measured in seconds. A value of 0 disables autosave. */ static const unsigned autosave_interval = 0; +/* Publicly announce netplay */ +static const bool netplay_public_announce = true; + /* Netplay without savestates/rewind */ static const bool netplay_stateless_mode = false; diff --git a/configuration.c b/configuration.c index 0954be6433..1266640cbe 100644 --- a/configuration.c +++ b/configuration.c @@ -728,6 +728,7 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("all_users_control_menu", &settings->input.all_users_control_menu, true, all_users_control_menu, false); SETTING_BOOL("menu_swap_ok_cancel_buttons", &settings->input.menu_swap_ok_cancel_buttons, true, menu_swap_ok_cancel_buttons, false); #ifdef HAVE_NETWORKING + SETTING_BOOL("netplay_public_announce", &settings->netplay.public_announce, true, netplay_public_announce, false); SETTING_BOOL("netplay_stateless_mode", &settings->netplay.stateless_mode, false, netplay_stateless_mode, false); SETTING_BOOL("netplay_client_swap_input", &settings->netplay.swap_input, true, netplay_client_swap_input, false); #endif diff --git a/configuration.h b/configuration.h index b851db61c0..a8f1e20e64 100644 --- a/configuration.h +++ b/configuration.h @@ -403,6 +403,7 @@ typedef struct settings #ifdef HAVE_NETWORKING struct { + bool public_announce; char server[255]; unsigned port; bool stateless_mode; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 9df3b15d90..277d837046 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -611,6 +611,8 @@ MSG_HASH(MENU_ENUM_LABEL_NETPLAY_PASSWORD, "netplay_password") MSG_HASH(MENU_ENUM_LABEL_NETPLAY_SETTINGS, "menu_netplay_settings") +MSG_HASH(MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, + "netplay_public_announce") MSG_HASH(MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD, "netplay_spectate_password") MSG_HASH(MENU_ENUM_LABEL_NETPLAY_SPECTATOR_MODE_ENABLE, diff --git a/intl/msg_hash_us.c b/intl/msg_hash_us.c index 1f4f1c8339..dfd157ff38 100644 --- a/intl/msg_hash_us.c +++ b/intl/msg_hash_us.c @@ -1535,6 +1535,13 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len) { "Increasing this value will increase \n" "performance, but introduce more latency."); break; + case MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE: + snprintf(s, len, + "Whether to announce netplay games publicly. \n" + " \n" + "If set to false, clients must manually connect \n" + "rather than using the public lobby."); + break; case MENU_ENUM_LABEL_NETPLAY_STATELESS_MODE: snprintf(s, len, "Whether to run netplay in a mode not requiring\n" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 5e20c7a319..a501071b04 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -990,6 +990,8 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_NICKNAME, "Username") MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_PASSWORD, "Server Password") +MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_PUBLIC_ANNOUNCE, + "Publicly Announce Netplay") MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_SETTINGS, "Netplay settings") MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_STATELESS_MODE, @@ -2619,6 +2621,10 @@ MSG_HASH( MENU_ENUM_SUBLABEL_NETPLAY_PASSWORD, "The password for connecting to the netplay host. Used only in host mode." ) +MSG_HASH( + MENU_ENUM_SUBLABEL_NETPLAY_PUBLIC_ANNOUNCE, + "Whether to announce netplay games publicly. If unset, clients must manually connect rather than using the public lobby." + ) MSG_HASH( MENU_ENUM_SUBLABEL_NETPLAY_SPECTATE_PASSWORD, "The password for connecting to the netplay host with only spectator privileges. Used only in host mode." diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 9360d9ad40..e57e66043e 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -184,6 +184,7 @@ default_sublabel_macro(action_bind_sublabel_overlay_opacity, MENU_ default_sublabel_macro(action_bind_sublabel_overlay_scale, MENU_ENUM_SUBLABEL_OVERLAY_SCALE) default_sublabel_macro(action_bind_sublabel_overlay_enable, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_ENABLE) default_sublabel_macro(action_bind_sublabel_overlay_preset, MENU_ENUM_SUBLABEL_OVERLAY_PRESET) +default_sublabel_macro(action_bind_sublabel_netplay_public_announce, MENU_ENUM_SUBLABEL_NETPLAY_PUBLIC_ANNOUNCE) default_sublabel_macro(action_bind_sublabel_netplay_ip_address, MENU_ENUM_SUBLABEL_NETPLAY_IP_ADDRESS) default_sublabel_macro(action_bind_sublabel_netplay_tcp_udp_port, MENU_ENUM_SUBLABEL_NETPLAY_TCP_UDP_PORT) default_sublabel_macro(action_bind_sublabel_netplay_password, MENU_ENUM_SUBLABEL_NETPLAY_PASSWORD) @@ -736,6 +737,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_STDIN_CMD_ENABLE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_stdin_cmd_enable); break; + case MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_public_announce); + break; case MENU_ENUM_LABEL_NETPLAY_NAT_TRAVERSAL: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_nat_traversal); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 14142c15da..a1a2b319fb 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -4793,6 +4793,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) unsigned user; unsigned count = 0; + if (menu_displaylist_parse_settings_enum(menu, info, + MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, + PARSE_ONLY_BOOL, false) != -1) + count++; if (menu_displaylist_parse_settings_enum(menu, info, MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS, PARSE_ONLY_STRING, false) != -1) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 428c725bf7..07983f0e81 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -5590,6 +5590,21 @@ static bool setting_append_list( #if defined(HAVE_NETWORK_CMD) unsigned user; #endif + CONFIG_BOOL( + list, list_info, + &settings->netplay.public_announce, + MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, + MENU_ENUM_LABEL_VALUE_NETPLAY_PUBLIC_ANNOUNCE, + true, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE); + CONFIG_STRING( list, list_info, settings->netplay.server, diff --git a/msg_hash.h b/msg_hash.h index c73d676756..510eac16c8 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1017,6 +1017,7 @@ enum msg_hash_enums MENU_LABEL(BLUETOOTH_ENABLE), MENU_LABEL(NETPLAY_CLIENT_SWAP_INPUT), MENU_LABEL(NETPLAY_DELAY_FRAMES), + MENU_LABEL(NETPLAY_PUBLIC_ANNOUNCE), MENU_LABEL(NETPLAY_STATELESS_MODE), MENU_LABEL(NETPLAY_CHECK_FRAMES), MENU_LABEL(NETPLAY_INPUT_LATENCY_FRAMES_MIN), diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 8e40d92403..eddf830df9 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -652,11 +652,22 @@ static void netplay_frontend_paused(netplay_t *netplay, bool paused) bool netplay_pre_frame(netplay_t *netplay) { bool sync_stalled; - reannounce ++; - if (netplay->is_server && (reannounce % 3600 == 0)) - netplay_announce(); + settings_t *settings = config_get_ptr(); + retro_assert(netplay); + if (settings->netplay.public_announce) + { + reannounce ++; + if (netplay->is_server && (reannounce % 3600 == 0)) + netplay_announce(); + } + else + { + /* Make sure that if announcement is turned on mid-game, it gets announced */ + reannounce = -1; + } + /* FIXME: This is an ugly way to learn we're not paused anymore */ if (netplay->local_paused) netplay_frontend_paused(netplay, false); @@ -1027,7 +1038,8 @@ bool init_netplay(void *direct_host, const char *server, unsigned port) msg_hash_to_str(MSG_WAITING_FOR_CLIENT), 0, 180, false); - netplay_announce(); + if (settings->netplay.public_announce) + netplay_announce(); } netplay_data = (netplay_t*)netplay_new(