From 2a7929f123087d57aecfec31bbe8d285d1971e49 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Tue, 27 Dec 2016 16:41:27 -0500 Subject: [PATCH] Server prompt when connecting to netplay host --- command.c | 42 ++++++++++++++++++++++++++---------------- command.h | 4 +++- menu/cbs/menu_cbs_ok.c | 37 +++++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 27 deletions(-) diff --git a/command.c b/command.c index 657435fab2..aa4fe15306 100644 --- a/command.c +++ b/command.c @@ -2395,48 +2395,58 @@ bool command_event(enum event_command cmd, void *data) command_event(CMD_EVENT_BSV_MOVIE_DEINIT, NULL); bsv_movie_ctl(BSV_MOVIE_CTL_INIT, NULL); break; - case CMD_EVENT_NETPLAY_DEINIT: #ifdef HAVE_NETWORKING + case CMD_EVENT_NETPLAY_DEINIT: deinit_netplay(); -#endif break; case CMD_EVENT_NETWORK_DEINIT: -#ifdef HAVE_NETWORKING network_deinit(); -#endif break; case CMD_EVENT_NETWORK_INIT: -#ifdef HAVE_NETWORKING network_init(); -#endif break; case CMD_EVENT_NETPLAY_INIT: { -#ifdef HAVE_NETWORKING - settings_t *settings = config_get_ptr(); -#endif + char *hostname = (char *) data; + settings_t *settings = config_get_ptr(); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); -#ifdef HAVE_NETWORKING if (!init_netplay( - data, settings->netplay.server, + NULL, hostname ? hostname : settings->netplay.server, settings->netplay.port)) { command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); return false; } -#endif + } + break; + case CMD_EVENT_NETPLAY_INIT_DIRECT: + { + settings_t *settings = config_get_ptr(); + command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); + if (!init_netplay( + data, NULL, settings->netplay.port)) + { + command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); + return false; + } } break; case CMD_EVENT_NETPLAY_FLIP_PLAYERS: -#ifdef HAVE_NETWORKING netplay_driver_ctl(RARCH_NETPLAY_CTL_FLIP_PLAYERS, NULL); -#endif break; case CMD_EVENT_NETPLAY_GAME_WATCH: -#ifdef HAVE_NETWORKING netplay_driver_ctl(RARCH_NETPLAY_CTL_GAME_WATCH, NULL); -#endif break; +#else + case CMD_EVENT_NETPLAY_DEINIT: + case CMD_EVENT_NETWORK_DEINIT: + case CMD_EVENT_NETWORK_INIT: + case CMD_EVENT_NETPLAY_INIT: + case CMD_EVENT_NETPLAY_INIT_DIRECT: + case CMD_EVENT_NETPLAY_FLIP_PLAYERS: + case CMD_EVENT_NETPLAY_GAME_WATCH: + return false; +#endif case CMD_EVENT_FULLSCREEN_TOGGLE: { settings_t *settings = config_get_ptr(); diff --git a/command.h b/command.h index 3131915d0a..19d8009c86 100644 --- a/command.h +++ b/command.h @@ -167,8 +167,10 @@ enum event_command CMD_EVENT_NETWORK_DEINIT, /* Initializes network system. */ CMD_EVENT_NETWORK_INIT, - /* Initializes netplay system. */ + /* Initializes netplay system with a string or no host specified. */ CMD_EVENT_NETPLAY_INIT, + /* Initializes netplay system with a direct host specified. */ + CMD_EVENT_NETPLAY_INIT_DIRECT, /* Deinitializes netplay system. */ CMD_EVENT_NETPLAY_DEINIT, /* Flip netplay players. */ diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index f27c11747c..3c98971515 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -3132,7 +3132,7 @@ static int action_ok_netplay_lan_scan(const char *path, netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL); /* Enable Netplay */ - if (!command_event(CMD_EVENT_NETPLAY_INIT, (void *) host)) + if (!command_event(CMD_EVENT_NETPLAY_INIT_DIRECT, (void *) host)) return -1; return generic_action_ok_command(CMD_EVENT_RESUME); @@ -3597,6 +3597,19 @@ static int action_ok_netplay_enable_host(const char *path, #endif } +static void action_ok_netplay_enable_client_hostname_cb( + void *ignore, const char *hostname) +{ + char tmp_hostname[512]; + strlcpy(tmp_hostname, hostname, sizeof(tmp_hostname)); + if (hostname[0]) + command_event(CMD_EVENT_NETPLAY_INIT, (void *) tmp_hostname); + menu_input_dialog_end(); + + /* Force the menu to close */ + rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); +} + static int action_ok_netplay_enable_client(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -3607,15 +3620,6 @@ static int action_ok_netplay_enable_client(const char *path, command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL); - /* We can't do anything without a host specified */ - if (!settings->netplay.server[0]) - { - runloop_msg_queue_push( - "Please specify the Netplay server's IP address or hostname.", - 1, 480, true); - return -1; - } - /* If we haven't yet started, this will load on its own */ if (!content_is_inited()) { @@ -3625,6 +3629,19 @@ static int action_ok_netplay_enable_client(const char *path, return 0; } + /* If no host was specified in the config, ask for one */ + if (!settings->netplay.server[0]) + { + menu_input_ctx_line_t line; + memset(&line, 0, sizeof(line)); + line.label = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_IP_ADDRESS); + line.label_setting = "no_setting"; + line.cb = action_ok_netplay_enable_client_hostname_cb; + if (!menu_input_dialog_start(&line)) + return -1; + return 0; + } + /* Enable Netplay itself */ if (!command_event(CMD_EVENT_NETPLAY_INIT, NULL)) return -1;