further refinement of the netplay workflow

This commit is contained in:
radius 2017-05-16 00:15:06 -05:00
parent ea0202a39d
commit 1de95c6413
8 changed files with 47 additions and 25 deletions

View File

@ -3464,15 +3464,9 @@ finish:
sizeof(struct netplay_room));
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, file_list);
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
{
menu_entries_append_enum(file_list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ENABLE_HOST),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST),
MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST,
MENU_SETTING_ACTION, 0, 0);
}
else if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER_ENABLED, NULL))
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL))
{
menu_entries_append_enum(file_list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DISABLE_HOST),
@ -3480,7 +3474,9 @@ finish:
MENU_ENUM_LABEL_NETPLAY_DISCONNECT,
MENU_SETTING_ACTION, 0, 0);
}
else
else if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) &&
!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL) &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_CONNECTED, NULL))
{
menu_entries_append_enum(file_list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DISCONNECT),
@ -3488,6 +3484,14 @@ finish:
MENU_ENUM_LABEL_NETPLAY_DISCONNECT,
MENU_SETTING_ACTION, 0, 0);
}
else
{
menu_entries_append_enum(file_list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ENABLE_HOST),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST),
MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST,
MENU_SETTING_ACTION, 0, 0);
}
menu_entries_append_enum(file_list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS),

View File

@ -3128,15 +3128,8 @@ static int menu_displaylist_parse_netplay_room_list(
#ifdef HAVE_NETWORKING
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
{
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ENABLE_HOST),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST),
MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST,
MENU_SETTING_ACTION, 0, 0);
}
else if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER_ENABLED, NULL))
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL))
{
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DISABLE_HOST),
@ -3144,7 +3137,9 @@ static int menu_displaylist_parse_netplay_room_list(
MENU_ENUM_LABEL_NETPLAY_DISCONNECT,
MENU_SETTING_ACTION, 0, 0);
}
else
else if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) &&
!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_SERVER, NULL) &&
netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_CONNECTED, NULL))
{
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_DISCONNECT),
@ -3152,6 +3147,14 @@ static int menu_displaylist_parse_netplay_room_list(
MENU_ENUM_LABEL_NETPLAY_DISCONNECT,
MENU_SETTING_ACTION, 0, 0);
}
else
{
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ENABLE_HOST),
msg_hash_to_str(MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST),
MENU_ENUM_LABEL_NETPLAY_ENABLE_HOST,
MENU_SETTING_ACTION, 0, 0);
}
menu_entries_append_enum(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_REFRESH_ROOMS),

View File

@ -40,7 +40,8 @@ enum rarch_netplay_ctl_state
RARCH_NETPLAY_CTL_ENABLE_CLIENT,
RARCH_NETPLAY_CTL_DISABLE,
RARCH_NETPLAY_CTL_IS_ENABLED,
RARCH_NETPLAY_CTL_IS_SERVER_ENABLED,
RARCH_NETPLAY_CTL_IS_SERVER,
RARCH_NETPLAY_CTL_IS_CONNECTED,
RARCH_NETPLAY_CTL_IS_DATA_INITED,
RARCH_NETPLAY_CTL_PAUSE,
RARCH_NETPLAY_CTL_UNPAUSE,

View File

@ -1124,10 +1124,13 @@ static void netplay_toggle_play_spectate(netplay_t *netplay)
bool netplay_disconnect(netplay_t *netplay)
{
size_t i;
if (!netplay)
return true;
for (i = 0; i < netplay->connections_size; i++)
netplay_hangup(netplay, &netplay->connections[i]);
deinit_netplay();
return true;
}
@ -1137,6 +1140,7 @@ void deinit_netplay(void)
{
netplay_free(netplay_data);
netplay_enabled = false;
netplay_is_client = false;
is_mitm = false;
}
netplay_data = NULL;
@ -1271,11 +1275,13 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
ret = false;
goto done;
case RARCH_NETPLAY_CTL_IS_SERVER_ENABLED:
case RARCH_NETPLAY_CTL_IS_SERVER:
ret = netplay_enabled && !netplay_is_client;
RARCH_LOG("TEST: %d = %d && %d", ret, netplay_enabled, netplay_is_client);
goto done;
case RARCH_NETPLAY_CTL_IS_CONNECTED:
ret = false;
goto done;
default:
goto done;
}
@ -1292,9 +1298,11 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
goto done;
case RARCH_NETPLAY_CTL_IS_ENABLED:
goto done;
case RARCH_NETPLAY_CTL_IS_SERVER_ENABLED:
case RARCH_NETPLAY_CTL_IS_SERVER:
ret = netplay_enabled && !netplay_is_client;
RARCH_LOG("TEST: %d = %d && %d", ret, netplay_enabled, netplay_is_client);
goto done;
case RARCH_NETPLAY_CTL_IS_CONNECTED:
ret = netplay_data->is_connected;
goto done;
case RARCH_NETPLAY_CTL_POST_FRAME:
netplay_post_frame(netplay_data);

View File

@ -450,6 +450,7 @@ static void netplay_handshake_ready(netplay_t *netplay, struct netplay_connectio
}
else
{
netplay->is_connected = true;
snprintf(msg, sizeof(msg), "%s: \"%s\"",
msg_hash_to_str(MSG_CONNECTED_TO),
connection->nick);

View File

@ -423,6 +423,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
netplay->connected_players = 0;
netplay->player_max = 1;
netplay->is_server = (direct_host == NULL && server == NULL);
netplay->is_connected = false;;
netplay->nat_traversal = netplay->is_server ? nat_traversal : false;
netplay->stateless_mode = stateless_mode;
netplay->check_frames = check_frames;

View File

@ -111,6 +111,7 @@ void netplay_hangup(netplay_t *netplay, struct netplay_connection *connection)
else
{
dmsg = msg_hash_to_str(MSG_NETPLAY_CLIENT_HANGUP);
netplay->is_connected = false;
}
RARCH_LOG("%s\n", dmsg);
runloop_msg_queue_push(dmsg, 1, 180, false);

View File

@ -330,6 +330,9 @@ struct netplay
/* Are we the server? */
bool is_server;
/* Are we the connected? */
bool is_connected;
/* Our nickname */
char nick[NETPLAY_NICK_LEN];