Adding remaining netplay menu options

A couple fixes are still necessary for the client, in particular to
recover a "lost" hostname, but now it is possible to start server or
client mid-stream, and to disconnect intentionally.
This commit is contained in:
Gregor Richards 2016-09-28 23:18:34 -04:00
parent 03c9dab93a
commit 567da56048
5 changed files with 71 additions and 55 deletions

View File

@ -3288,6 +3288,11 @@ static int action_ok_netplay_enable_host(const char *path,
/* Kill it! */
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
}
else
{
/* We were already hosting! */
return generic_action_ok_command(CMD_EVENT_RESUME);
}
}
global->netplay.is_client = false;
@ -3305,19 +3310,52 @@ static int action_ok_netplay_enable_host(const char *path,
if (!netplay_was_on && !core_set_netplay_callbacks())
return -1;
return 0;
return generic_action_ok_command(CMD_EVENT_RESUME);
}
static int action_ok_netplay_enable_client(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
return 0;
bool netplay_was_on = false;
global_t *global = global_get_ptr();
global->netplay.enable = true;
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
{
netplay_was_on = true;
/* Kill it! */
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
}
global->netplay.is_client = true;
/* FIXME global->netplay.server[0] = '\0'; */
/* FIXME: We can't do anything without a host specified */
if (!global->netplay.server[0])
strcpy(global->netplay.server, "127.0.0.1");
/* If we haven't yet started, this will load on its own */
if (!content_is_inited())
return 0;
/* Enable Netplay itself */
if (!command_event(CMD_EVENT_NETPLAY_INIT, NULL))
return -1;
/* Then make sure we use Netplay's callbacks */
if (!netplay_was_on && !core_set_netplay_callbacks())
return -1;
return generic_action_ok_command(CMD_EVENT_RESUME);
}
static int action_ok_netplay_disconnect(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
return 0;
netplay_driver_ctl(RARCH_NETPLAY_CTL_DISCONNECT, NULL);
return generic_action_ok_command(CMD_EVENT_RESUME);
}
static int is_rdb_entry(enum msg_hash_enums enum_idx)

View File

@ -4275,15 +4275,15 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_ADD_CONTENT_LIST,
PARSE_ACTION, false);
#if defined(HAVE_NETWORKING)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_ONLINE_UPDATER,
PARSE_ACTION, false);
#endif
#if defined(HAVE_NETPLAY)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_NETPLAY,
PARSE_ACTION, false);
#endif
#if defined(HAVE_NETWORKING)
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_ONLINE_UPDATER,
PARSE_ACTION, false);
#endif
menu_displaylist_parse_settings_enum(menu, info,
MENU_ENUM_LABEL_SETTINGS, PARSE_ACTION, false);

View File

@ -2187,17 +2187,6 @@ static bool setting_append_list(
parent_group);
menu_settings_list_current_add_enum_idx(list, list_info, MENU_ENUM_LABEL_ADD_CONTENT_LIST);
#if defined(HAVE_NETWORKING)
CONFIG_ACTION(
list, list_info,
msg_hash_to_str(MENU_ENUM_LABEL_ONLINE_UPDATER),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ONLINE_UPDATER),
&group_info,
&subgroup_info,
parent_group);
menu_settings_list_current_add_enum_idx(list, list_info, MENU_ENUM_LABEL_ONLINE_UPDATER);
#endif
#if defined(HAVE_NETPLAY)
CONFIG_ACTION(
list, list_info,
@ -2209,6 +2198,17 @@ static bool setting_append_list(
menu_settings_list_current_add_enum_idx(list, list_info, MENU_ENUM_LABEL_NETPLAY);
#endif
#if defined(HAVE_NETWORKING)
CONFIG_ACTION(
list, list_info,
msg_hash_to_str(MENU_ENUM_LABEL_ONLINE_UPDATER),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ONLINE_UPDATER),
&group_info,
&subgroup_info,
parent_group);
menu_settings_list_current_add_enum_idx(list, list_info, MENU_ENUM_LABEL_ONLINE_UPDATER);
#endif
CONFIG_ACTION(
list, list_info,
msg_hash_to_str(MENU_ENUM_LABEL_SETTINGS),

View File

@ -1272,38 +1272,18 @@ void netplay_load_savestate(netplay_t *netplay, retro_ctx_serialize_info_t *seri
}
/**
* netplay_reconnect
* netplay_disconnect
* @netplay : pointer to netplay object
*
* Reconnect netplay. Only does anything as a client, and only if netplay isn't
* currently connected.
* Disconnect netplay.
*
* Returns: true (1) if successful, false (0) if unsuccessful, false (0) if not
* client or already connected.
* Returns: true (1) if successful. At present, cannot fail.
**/
bool netplay_reconnect(netplay_t *netplay)
bool netplay_disconnect(netplay_t *netplay)
{
/* FIXME: This function has some things remembered in netplay, some things
* brought back from global */
global_t *global = global_get_ptr();
if (!netplay || netplay->has_connection || netplay->is_server)
{
return false;
}
if (!init_socket(netplay, global->netplay.server, netplay->tcp_port))
{
RARCH_WARN("Failed to reconnect Netplay.\n");
runloop_msg_queue_push("Failed to reconnect Netplay.", 0, 480, false);
}
/* FIXME: Connection info is weirdly conflated into info_cb */
if (!netplay_info_cb(netplay, netplay->stall_frames))
{
return false;
}
if (!netplay || !netplay->has_connection)
return true;
hangup(netplay);
return true;
}
@ -1416,8 +1396,8 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
case RARCH_NETPLAY_CTL_LOAD_SAVESTATE:
netplay_load_savestate((netplay_t*)netplay_data, (retro_ctx_serialize_info_t*)data, true);
break;
case RARCH_NETPLAY_CTL_RECONNECT:
return netplay_reconnect((netplay_t*)netplay_data);
case RARCH_NETPLAY_CTL_DISCONNECT:
return netplay_disconnect((netplay_t*)netplay_data);
default:
case RARCH_NETPLAY_CTL_NONE:
break;

View File

@ -39,7 +39,7 @@ enum rarch_netplay_ctl_state
RARCH_NETPLAY_CTL_PAUSE,
RARCH_NETPLAY_CTL_UNPAUSE,
RARCH_NETPLAY_CTL_LOAD_SAVESTATE,
RARCH_NETPLAY_CTL_RECONNECT
RARCH_NETPLAY_CTL_DISCONNECT
};
enum netplay_cmd
@ -196,16 +196,14 @@ void netplay_frontend_paused(netplay_t *netplay, bool paused);
void netplay_load_savestate(netplay_t *netplay, retro_ctx_serialize_info_t *serial_info, bool save);
/**
* netplay_reconnect
* netplay_disconnect
* @netplay : pointer to netplay object
*
* Reconnect netplay. Only does anything as a client, and only if netplay isn't
* currently connected.
* Disconnect netplay.
*
* Returns: true (1) if successful, false (0) if unsuccessful, false (0) if not
* client or already connected.
* Returns: true (1) if successful. At present, cannot fail.
**/
bool netplay_reconnect(netplay_t *netplay);
bool netplay_disconnect(netplay_t *netplay);
/**
* init_netplay: