Skip to content

Commit

Permalink
add menu option to select different MITM server locations
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Parker committed Feb 2, 2018
1 parent efc35e4 commit df27e70
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ static const int netplay_check_frames = 600;

static const bool netplay_use_mitm_server = false;

static const char *netplay_mitm_server = "nyc";

#ifdef HAVE_NETWORKING
static const unsigned netplay_share_digital = RARCH_NETPLAY_SHARE_DIGITAL_NO_PREFERENCE;

Expand Down
5 changes: 5 additions & 0 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@ static struct config_array_setting *populate_settings_array(settings_t *settings
SETTING_ARRAY("bundle_assets_dst_path", settings->arrays.bundle_assets_dst, false, NULL, true);
SETTING_ARRAY("bundle_assets_dst_path_subdir", settings->arrays.bundle_assets_dst_subdir, false, NULL, true);
SETTING_ARRAY("led_driver", settings->arrays.led_driver, false, NULL, true);
SETTING_ARRAY("netplay_mitm_server", settings->arrays.netplay_mitm_server, false, NULL, true);
*size = count;

return tmp;
Expand Down Expand Up @@ -1551,6 +1552,7 @@ static void config_set_defaults(void)
const char *def_led = config_get_default_led();
const char *def_location = config_get_default_location();
const char *def_record = config_get_default_record();
const char *def_mitm = netplay_mitm_server;
struct config_float_setting *float_settings = populate_settings_float (settings, &float_settings_size);
struct config_bool_setting *bool_settings = populate_settings_bool (settings, &bool_settings_size);
struct config_int_setting *int_settings = populate_settings_int (settings, &int_settings_size);
Expand Down Expand Up @@ -1630,6 +1632,9 @@ static void config_set_defaults(void)
if (def_record)
strlcpy(settings->arrays.record_driver,
def_record, sizeof(settings->arrays.record_driver));
if (def_mitm)
strlcpy(settings->arrays.netplay_mitm_server,
def_mitm, sizeof(settings->arrays.netplay_mitm_server));
#ifdef HAVE_MENU
if (def_menu)
strlcpy(settings->arrays.menu_driver,
Expand Down
2 changes: 2 additions & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,8 @@ typedef struct settings
char bundle_assets_src[PATH_MAX_LENGTH];
char bundle_assets_dst[PATH_MAX_LENGTH];
char bundle_assets_dst_subdir[PATH_MAX_LENGTH];

char netplay_mitm_server[255];
} arrays;

struct
Expand Down
2 changes: 2 additions & 0 deletions intl/msg_hash_ja.h
Original file line number Diff line number Diff line change
Expand Up @@ -3041,6 +3041,8 @@ MSG_HASH(
)
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_USE_MITM_SERVER,
"MITMサーバーを使用")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_MITM_SERVER,
"MITMサーバーの設置場所")
MSG_HASH(MENU_ENUM_SUBLABEL_NETPLAY_USE_MITM_SERVER,
"中間者のサーバーにネットプレイ接続を転送する。ファイアウォールやNAT/UPnPが問題の時に便利。")
MSG_HASH(MENU_ENUM_LABEL_VALUE_ADD_TO_MIXER,
Expand Down
2 changes: 2 additions & 0 deletions intl/msg_hash_lbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ MSG_HASH(MENU_ENUM_LABEL_SHADER_PIPELINE_BOKEH,
"shader_pipeline_bokeh")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER,
"netplay_use_mitm_server")
MSG_HASH(MENU_ENUM_LABEL_NETPLAY_MITM_SERVER,
"netplay_mitm_server")
MSG_HASH(MENU_ENUM_LABEL_ADD_TO_MIXER,
"audio_add_to_mixer")
MSG_HASH(MENU_ENUM_LABEL_ADD_TO_MIXER_AND_COLLECTION,
Expand Down
12 changes: 9 additions & 3 deletions intl/msg_hash_us.c
Original file line number Diff line number Diff line change
Expand Up @@ -1655,9 +1655,15 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
break;
case MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER:
snprintf(s, len,
"When hosting, relay connection through a\n"
"man-in-the-middle server\n"
"to get around firewalls or NAT/UPnP issues.\n");
"When hosting a netplay session, relay connection through a \n"
"man-in-the-middle server \n"
"to get around firewalls or NAT/UPnP issues. \n");
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
snprintf(s, len,
"Specifies the man-in-the-middle server \n"
"to use for netplay. A server that is \n"
"located closer to you may have less latency. \n");
break;
case MENU_ENUM_LABEL_VIDEO_MAX_SWAPCHAIN_IMAGES:
snprintf(s, len,
Expand Down
4 changes: 4 additions & 0 deletions intl/msg_hash_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,10 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_USE_MITM_SERVER,
"Use Relay Server")
MSG_HASH(MENU_ENUM_SUBLABEL_NETPLAY_USE_MITM_SERVER,
"Forward netplay connections through a man-in-the-middle server. Useful if the host is behind a firewall or has NAT/UPnP problems.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_NETPLAY_MITM_SERVER,
"Relay Server Location")
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_ADD_TO_MIXER,
"Add to mixer")
MSG_HASH(MENU_ENUM_LABEL_VALUE_ADD_TO_MIXER_AND_COLLECTION,
Expand Down
34 changes: 34 additions & 0 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,36 @@ static void menu_action_setting_disp_set_label_pipeline(

}

static void menu_action_setting_disp_set_label_netplay_mitm_server(
file_list_t* list,
unsigned *w, unsigned type, unsigned i,
const char *label,
char *s, size_t len,
const char *entry_label,
const char *path,
char *s2, size_t len2)
{
settings_t *settings = config_get_ptr();

*s = '\0';
*w = 19;
strlcpy(s2, path, len2);

if (!settings)
return;

if (!string_is_empty(settings->arrays.netplay_mitm_server))
{
unsigned i;

for (i = 0; i < ARRAY_SIZE(netplay_mitm_server_list); i++)
{
if (string_is_equal(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[i].name))
strlcpy(s, netplay_mitm_server_list[i].description, len);
}
}
}

static void menu_action_setting_disp_set_label_shader_watch_for_changes(
file_list_t* list,
unsigned *w, unsigned type, unsigned i,
Expand Down Expand Up @@ -2199,6 +2229,10 @@ int menu_cbs_init_bind_get_string_representation(menu_file_list_cbs_t *cbs,
BIND_ACTION_GET_VALUE(cbs,
menu_action_setting_disp_set_label_achievement_information);
return 0;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_GET_VALUE(cbs,
menu_action_setting_disp_set_label_netplay_mitm_server);
return 0;
default:
break;
}
Expand Down
42 changes: 42 additions & 0 deletions menu/cbs/menu_cbs_left.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "../../managers/cheat_manager.h"
#include "../../file_path_special.h"
#include "../../retroarch.h"
#include "../../network/netplay/netplay.h"

#ifndef BIND_ACTION_LEFT
#define BIND_ACTION_LEFT(cbs, name) \
Expand Down Expand Up @@ -324,6 +325,44 @@ static int action_left_shader_num_passes(unsigned type, const char *label,
return 0;
}

static int action_left_netplay_mitm_server(unsigned type, const char *label,
bool wraparound)
{
settings_t *settings = config_get_ptr();
int i;
bool found = false;
int list_len = ARRAY_SIZE(netplay_mitm_server_list);

for (i = 0; i < list_len; i++)
{
/* find the currently selected server in the list */
if (string_is_equal(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[i].name))
{
/* move to the previous one in the list, wrap around if necessary */
if (i - 1 >= 0)
{
found = true;
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[i - 1].name, sizeof(settings->arrays.netplay_mitm_server));
break;
}
else if (wraparound)
{
found = true;
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[list_len - 1].name, sizeof(settings->arrays.netplay_mitm_server));
break;
}
}
}

if (!found)
{
/* current entry was invalid, go back to the end */
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[list_len - 1].name, sizeof(settings->arrays.netplay_mitm_server));
}

return 0;
}

static int action_left_shader_watch_for_changes(unsigned type, const char *label,
bool wraparound)
{
Expand Down Expand Up @@ -490,6 +529,9 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_VIDEO_SHADER_DEFAULT_FILTER:
BIND_ACTION_LEFT(cbs, action_left_shader_filter_default);
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_LEFT(cbs, action_left_netplay_mitm_server);
break;
case MENU_ENUM_LABEL_SHADER_WATCH_FOR_CHANGES:
BIND_ACTION_LEFT(cbs, action_left_shader_watch_for_changes);
break;
Expand Down
42 changes: 42 additions & 0 deletions menu/cbs/menu_cbs_right.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../ui/ui_companion_driver.h"
#include "../../network/netplay/netplay.h"

#ifndef BIND_ACTION_RIGHT
#define BIND_ACTION_RIGHT(cbs, name) \
Expand Down Expand Up @@ -327,6 +328,44 @@ static int action_right_shader_num_passes(unsigned type, const char *label,
return 0;
}

static int action_right_netplay_mitm_server(unsigned type, const char *label,
bool wraparound)
{
settings_t *settings = config_get_ptr();
unsigned i;
bool found = false;
unsigned list_len = ARRAY_SIZE(netplay_mitm_server_list);

for (i = 0; i < list_len; i++)
{
/* find the currently selected server in the list */
if (string_is_equal(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[i].name))
{
/* move to the next one in the list, wrap around if necessary */
if (i + 1 < list_len)
{
found = true;
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[i + 1].name, sizeof(settings->arrays.netplay_mitm_server));
break;
}
else if (wraparound)
{
found = true;
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[0].name, sizeof(settings->arrays.netplay_mitm_server));
break;
}
}
}

if (!found)
{
/* current entry was invalid, go back to the start */
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server_list[0].name, sizeof(settings->arrays.netplay_mitm_server));
}

return 0;
}

static int action_right_shader_watch_for_changes(unsigned type, const char *label,
bool wraparound)
{
Expand Down Expand Up @@ -600,6 +639,9 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_VIDEO_SHADER_DEFAULT_FILTER:
BIND_ACTION_RIGHT(cbs, action_right_shader_filter_default);
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_RIGHT(cbs, action_right_netplay_mitm_server);
break;
case MENU_ENUM_LABEL_SHADER_WATCH_FOR_CHANGES:
BIND_ACTION_RIGHT(cbs, action_right_shader_watch_for_changes);
break;
Expand Down
11 changes: 11 additions & 0 deletions menu/cbs/menu_cbs_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ static int action_start_shader_filter_pass(unsigned type, const char *label)
return menu_shader_manager_clear_pass_filter(pass);
}

static int action_start_netplay_mitm_server(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
strlcpy(settings->arrays.netplay_mitm_server, netplay_mitm_server, sizeof(settings->arrays.netplay_mitm_server));
return 0;
}

static int action_start_shader_watch_for_changes(unsigned type, const char *label)
{
settings_t *settings = config_get_ptr();
Expand Down Expand Up @@ -299,6 +306,10 @@ static int menu_cbs_init_bind_start_compare_label(menu_file_list_cbs_t *cbs)
break;
case MENU_ENUM_LABEL_SCREEN_RESOLUTION:
BIND_ACTION_START(cbs, action_start_video_resolution);
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_START(cbs, action_start_netplay_mitm_server);
break;
default:
return -1;
}
Expand Down
4 changes: 4 additions & 0 deletions menu/cbs/menu_cbs_sublabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ default_sublabel_macro(action_bind_sublabel_video_viewport_custom_width,
default_sublabel_macro(action_bind_sublabel_video_viewport_custom_x, MENU_ENUM_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_core_delete, MENU_ENUM_SUBLABEL_CORE_DELETE)

static int action_bind_sublabel_cheevos_entry(
Expand Down Expand Up @@ -1472,6 +1473,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_use_mitm_server);
break;
case MENU_ENUM_LABEL_NETPLAY_MITM_SERVER:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_netplay_mitm_server);
break;
case MENU_ENUM_LABEL_CORE_DELETE:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_core_delete);
default:
Expand Down
4 changes: 4 additions & 0 deletions menu/menu_displaylist.c
Original file line number Diff line number Diff line change
Expand Up @@ -5498,6 +5498,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
MENU_ENUM_LABEL_NETPLAY_USE_MITM_SERVER,
PARSE_ONLY_BOOL, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY_MITM_SERVER,
PARSE_ONLY_STRING, false) != -1)
count++;
if (menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY_IP_ADDRESS,
PARSE_ONLY_STRING, false) != -1)
Expand Down
21 changes: 21 additions & 0 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ static void setting_get_string_representation_uint_autosave_interval(void *data,
}
#endif

static void setting_get_string_representation_netplay_mitm_server(void *data,
char *s, size_t len)
{

}

#ifdef HAVE_LANGEXTRA
static void setting_get_string_representation_uint_user_language(void *data,
char *s, size_t len)
Expand Down Expand Up @@ -6718,6 +6724,21 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_NONE);

CONFIG_STRING(
list, list_info,
settings->arrays.netplay_mitm_server,
sizeof(settings->arrays.netplay_mitm_server),
MENU_ENUM_LABEL_NETPLAY_MITM_SERVER,
MENU_ENUM_LABEL_VALUE_NETPLAY_MITM_SERVER,
netplay_mitm_server,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler);
(*list)[list_info->index - 1].get_string_representation =
&setting_get_string_representation_netplay_mitm_server;

CONFIG_STRING(
list, list_info,
settings->paths.netplay_server,
Expand Down
1 change: 1 addition & 0 deletions msg_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_NETPLAY_COMPAT_CONTENT_FOUND,

MENU_LABEL(NETPLAY_USE_MITM_SERVER),
MENU_LABEL(NETPLAY_MITM_SERVER),

MSG_LAST
};
Expand Down
10 changes: 10 additions & 0 deletions network/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@

typedef struct netplay netplay_t;

typedef struct mitm_server {
const char *name;
const char *description;
} mitm_server_t;

static const mitm_server_t netplay_mitm_server_list[] = {
{ "nyc", "New York City, USA" },
{ "madrid", "Madrid, Spain" },
};

enum rarch_netplay_ctl_state
{
RARCH_NETPLAY_CTL_NONE = 0,
Expand Down
3 changes: 3 additions & 0 deletions retroarch.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ video_message_bgcolor_opacity = 1.0
# Force game hosting to go through a man-in-the-middle server to get around firewalls and NAT/UPnP problems.
# netplay_use_mitm_server = false

# The requested MITM server to use.
# netplay_mitm_server = "nyc"

#### Misc

# Enable rewinding. This will take a performance hit when playing, so it is disabled by default.
Expand Down

0 comments on commit df27e70

Please sign in to comment.