diff --git a/configuration.c b/configuration.c index fe8dd6a973..6e2c5d9a5b 100644 --- a/configuration.c +++ b/configuration.c @@ -1456,7 +1456,8 @@ static struct config_path_setting *populate_settings_path( SETTING_PATH("core_updater_buildbot_cores_url", settings->paths.network_buildbot_url, false, NULL, true); SETTING_PATH("core_updater_buildbot_assets_url", settings->paths.network_buildbot_assets_url, false, NULL, true); #ifdef HAVE_NETWORKING - SETTING_PATH("netplay_ip_address", settings->paths.netplay_server, false, NULL, true); + SETTING_PATH("netplay_ip_address", settings->paths.netplay_server, false, NULL, true); + SETTING_PATH("netplay_custom_mitm_server", settings->paths.netplay_custom_mitm_server, false, NULL, true); SETTING_PATH("netplay_password", settings->paths.netplay_password, false, NULL, true); SETTING_PATH("netplay_spectate_password", settings->paths.netplay_spectate_password, false, NULL, true); #endif diff --git a/configuration.h b/configuration.h index dd357d3e24..f276b43398 100644 --- a/configuration.h +++ b/configuration.h @@ -455,6 +455,7 @@ typedef struct settings char netplay_spectate_password[128]; char netplay_server[255]; + char netplay_custom_mitm_server[255]; char network_buildbot_url[255]; char network_buildbot_assets_url[255]; diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 81372de215..5c97460abd 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -3930,6 +3930,10 @@ MSG_HASH( MENU_ENUM_LABEL_NETPLAY_MITM_SERVER, "netplay_mitm_server" ) +MSG_HASH( + MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER, + "netplay_custom_mitm_server" + ) MSG_HASH( MENU_ENUM_LABEL_ADD_TO_MIXER, "audio_add_to_mixer" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 760d30f1ce..44eb79b80e 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -5274,6 +5274,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_NETPLAY_MITM_SERVER, "Choose a specific relay server to use. Geographically closer locations tend to have lower latency." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_NETPLAY_CUSTOM_MITM_SERVER, + "Custom Relay Server Address" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_NETPLAY_CUSTOM_MITM_SERVER, + "Input the address of your custom relay server here. Format: address or address|port" + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_NETPLAY_IP_ADDRESS, "Server Address" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index dba1a8b868..b743ec89dd 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -926,6 +926,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_viewport_custom_x, DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_viewport_custom_y, MENU_ENUM_SUBLABEL_VIDEO_VIEWPORT_CUSTOM_Y) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_use_mitm_server, MENU_ENUM_SUBLABEL_NETPLAY_USE_MITM_SERVER) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_mitm_server, MENU_ENUM_SUBLABEL_NETPLAY_MITM_SERVER) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_custom_mitm_server, MENU_ENUM_SUBLABEL_NETPLAY_CUSTOM_MITM_SERVER) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_core_lock, MENU_ENUM_SUBLABEL_CORE_LOCK) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_core_delete, MENU_ENUM_SUBLABEL_CORE_DELETE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_pause_hardcode_mode, MENU_ENUM_SUBLABEL_ACHIEVEMENT_PAUSE) @@ -4284,6 +4285,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_mitm_server); break; + case MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_custom_mitm_server); + break; case MENU_ENUM_LABEL_CORE_LOCK: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_core_lock); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index d832eca565..5e157515f4 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -7291,14 +7291,15 @@ unsigned menu_displaylist_build_list( break; case DISPLAYLIST_NETWORK_SETTINGS_LIST: { - bool netplay_allow_slaves = settings->bools.netplay_allow_slaves; - bool netplay_use_mitm_server = settings->bools.netplay_use_mitm_server; - bool network_cmd_enable = settings->bools.network_cmd_enable; + bool netplay_allow_slaves = settings->bools.netplay_allow_slaves; + bool netplay_use_mitm_server = settings->bools.netplay_use_mitm_server; + bool network_cmd_enable = settings->bools.network_cmd_enable; menu_displaylist_build_info_selective_t build_list[] = { {MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, PARSE_ONLY_BOOL, true }, {MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER, PARSE_ONLY_BOOL, true }, {MENU_ENUM_LABEL_NETPLAY_MITM_SERVER, PARSE_ONLY_STRING, false}, + {MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER, PARSE_ONLY_STRING, false}, {MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS, PARSE_ONLY_STRING, true}, {MENU_ENUM_LABEL_NETPLAY_TCP_UDP_PORT, PARSE_ONLY_UINT, true}, {MENU_ENUM_LABEL_NETPLAY_MAX_CONNECTIONS, PARSE_ONLY_UINT, true}, @@ -7331,6 +7332,10 @@ unsigned menu_displaylist_build_list( if (netplay_use_mitm_server) build_list[i].checked = true; break; + case MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER: + if (netplay_use_mitm_server) + build_list[i].checked = true; + break; default: break; } @@ -9948,6 +9953,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, {MENU_ENUM_LABEL_NETPLAY_PUBLIC_ANNOUNCE, PARSE_ONLY_BOOL, true }, {MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER, PARSE_ONLY_BOOL, true }, {MENU_ENUM_LABEL_NETPLAY_MITM_SERVER, PARSE_ONLY_STRING, false}, + {MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER, PARSE_ONLY_STRING, false}, {MENU_ENUM_LABEL_NETPLAY_PASSWORD, PARSE_ONLY_STRING, true}, {MENU_ENUM_LABEL_NETPLAY_SPECTATE_PASSWORD, PARSE_ONLY_STRING, true}, }; @@ -9985,6 +9991,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, if (settings->bools.netplay_use_mitm_server) build_list[i].checked = true; break; + case MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER: + if (settings->bools.netplay_use_mitm_server) + build_list[i].checked = true; + break; default: break; } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index cc04b26426..712fe982ee 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -19176,6 +19176,22 @@ static bool setting_append_list( (*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_netplay_mitm_server; + CONFIG_STRING( + list, list_info, + settings->paths.netplay_custom_mitm_server, + sizeof(settings->paths.netplay_custom_mitm_server), + MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER, + MENU_ENUM_LABEL_VALUE_NETPLAY_CUSTOM_MITM_SERVER, + "", + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler); + SETTINGS_DATA_LIST_CURRENT_ADD_FLAGS(list, list_info, SD_FLAG_ALLOW_INPUT); + (*list)[list_info->index - 1].ui_type = ST_UI_TYPE_STRING_LINE_EDIT; + (*list)[list_info->index - 1].action_start = setting_generic_action_start_default; + CONFIG_STRING( list, list_info, settings->paths.netplay_server, diff --git a/msg_hash.h b/msg_hash.h index 30dd45cd18..39b915605e 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -2912,6 +2912,7 @@ enum msg_hash_enums MENU_LABEL(NETPLAY_USE_MITM_SERVER), MENU_LABEL(NETPLAY_MITM_SERVER), + MENU_LABEL(NETPLAY_CUSTOM_MITM_SERVER), MENU_LABEL(VIDEO_WINDOW_SHOW_DECORATIONS), MENU_LABEL(VIDEO_WINDOW_SAVE_POSITION), MENU_LABEL(VIDEO_WINDOW_CUSTOM_SIZE_ENABLE), diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index 7b71589998..15f996d343 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -141,6 +141,7 @@ static const mitm_server_t netplay_mitm_server_list[] = { { "madrid", "Madrid, Spain" }, { "saopaulo", "Sao Paulo, Brazil" }, { "singapore", "Singapore" }, + { "custom", "Custom" }, }; struct netplay_room diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 04434812dc..25fe571067 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -7854,7 +7854,10 @@ static void netplay_announce(netplay_t *netplay) char *gamename = NULL; char *subsystemname = NULL; char *frontend_ident = NULL; - char *mitm_session = NULL; + char *mitm_session = ""; + const char *mitm_custom_addr = ""; + int mitm_custom_port = 0; + int is_mitm = 0; settings_t *settings = config_get_ptr(); net_driver_state_t *net_st = &networking_driver_st; struct netplay_room *host_room = &net_st->host_room; @@ -7915,7 +7918,17 @@ static void netplay_announce(netplay_t *netplay) sizeof(frontend_architecture)); net_http_urlencode(&frontend_ident, frontend_architecture); - net_http_urlencode(&mitm_session, host_room->mitm_session); + if (!string_is_empty(host_room->mitm_session)) + { + is_mitm = 1; + net_http_urlencode(&mitm_session, host_room->mitm_session); + + if (string_is_equal(host_room->mitm_handle, "custom")) + { + mitm_custom_addr = host_room->mitm_address; + mitm_custom_port = host_room->mitm_port; + } + } snprintf(buf, sizeof(buf), "username=%s&" @@ -7931,7 +7944,9 @@ static void netplay_announce(netplay_t *netplay) "retroarch_version=%s&" "frontend=%s&" "subsystem_name=%s&" - "mitm_session=%s", + "mitm_session=%s&" + "mitm_custom_addr=%s&" + "mitm_custom_port=%d", username, corename, coreversion, @@ -7941,11 +7956,13 @@ static void netplay_announce(netplay_t *netplay) host_room->mitm_handle, !string_is_empty(settings->paths.netplay_password) ? 1 : 0, !string_is_empty(settings->paths.netplay_spectate_password) ? 1 : 0, - !string_is_empty(host_room->mitm_session) ? 1 : 0, + is_mitm, PACKAGE_VERSION, frontend_ident, subsystemname, - mitm_session); + mitm_session, + mitm_custom_addr, + mitm_custom_port); free(username); free(corename); @@ -8019,26 +8036,52 @@ static void netplay_mitm_query_cb(retro_task_t *task, void *task_data, static bool netplay_mitm_query(const char *mitm_name) { - char query[512]; net_driver_state_t *net_st = &networking_driver_st; struct netplay_room *host_room = &net_st->host_room; -#ifndef NETPLAY_TEST_BUILD - const char *url = "http://lobby.libretro.com/tunnel"; -#else - const char *url = "http://lobbytest.libretro.com/tunnel"; -#endif if (string_is_empty(mitm_name)) return false; - snprintf(query, sizeof(query), "%s?name=%s", url, mitm_name); + /* We don't need to query, + if we are using a custom relay server. */ + if (string_is_equal(mitm_name, "custom")) + { + char addr[256]; + char sess[sizeof(addr)]; + unsigned port; + settings_t *settings = config_get_ptr(); + const char *custom_server = + settings->paths.netplay_custom_mitm_server; - if (!task_push_http_transfer(query, - true, NULL, netplay_mitm_query_cb, NULL)) - return false; + addr[0] = '\0'; + sess[0] = '\0'; + port = 0; - /* Make sure we've the tunnel address before continuing. */ - task_queue_wait(NULL, NULL); + netplay_decode_hostname(custom_server, + addr, &port, sess, sizeof(addr)); + + strlcpy(host_room->mitm_address, addr, + sizeof(host_room->mitm_address)); + host_room->mitm_port = port; + } + else + { + char query[512]; +#ifndef NETPLAY_TEST_BUILD + const char *url = "http://lobby.libretro.com/tunnel"; +#else + const char *url = "http://lobbytest.libretro.com/tunnel"; +#endif + + snprintf(query, sizeof(query), "%s?name=%s", url, mitm_name); + + if (!task_push_http_transfer(query, + true, NULL, netplay_mitm_query_cb, NULL)) + return false; + + /* Make sure we've the tunnel address before continuing. */ + task_queue_wait(NULL, NULL); + } return !string_is_empty(host_room->mitm_address) && host_room->mitm_port; diff --git a/ui/drivers/qt/qt_options.cpp b/ui/drivers/qt/qt_options.cpp index 200ab442b1..4fb0cf0064 100644 --- a/ui/drivers/qt/qt_options.cpp +++ b/ui/drivers/qt/qt_options.cpp @@ -498,6 +498,8 @@ QGroupBox *NetplayPage::createMitmServerGroup() groupBox->addRow(radioButton); } + groupBox->add(MENU_ENUM_LABEL_NETPLAY_CUSTOM_MITM_SERVER); + connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onRadioButtonClicked(int)));