can now connect when starting a game too

This commit is contained in:
radius 2017-01-20 16:04:10 -05:00
parent 42dc8c7e15
commit 0de43b954e
5 changed files with 58 additions and 9 deletions

View File

@ -2441,6 +2441,20 @@ bool command_event(enum event_command cmd, void *data)
}
}
break;
case CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED:
{
char *hostname = (char *) data;
settings_t *settings = config_get_ptr();
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
if (!init_netplay_deferred(
hostname, settings->netplay.port))
{
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
return false;
}
}
break;
case CMD_EVENT_NETPLAY_FLIP_PLAYERS:
netplay_driver_ctl(RARCH_NETPLAY_CTL_FLIP_PLAYERS, NULL);
break;
@ -2453,6 +2467,7 @@ bool command_event(enum event_command cmd, void *data)
case CMD_EVENT_NETWORK_INIT:
case CMD_EVENT_NETPLAY_INIT:
case CMD_EVENT_NETPLAY_INIT_DIRECT:
case CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED:
case CMD_EVENT_NETPLAY_FLIP_PLAYERS:
case CMD_EVENT_NETPLAY_GAME_WATCH:
return false;

View File

@ -171,6 +171,8 @@ enum event_command
CMD_EVENT_NETPLAY_INIT,
/* Initializes netplay system with a direct host specified. */
CMD_EVENT_NETPLAY_INIT_DIRECT,
/* Initializes netplay system with a direct host specified after loading content. */
CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED,
/* Deinitializes netplay system. */
CMD_EVENT_NETPLAY_DEINIT,
/* Flip netplay players. */

View File

@ -3125,21 +3125,29 @@ static int action_ok_netplay_connect_room(const char *path,
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
char tmp_hostname[512];
/* For testing purposes
strlcpy(tmp_hostname, "192.168.1.241", sizeof(tmp_hostname));*/
strlcpy(tmp_hostname, netplay_room_list[idx - 1].address, sizeof(tmp_hostname));
/* If we haven't yet started, this will load on its own */
if (!content_is_inited())
{
runloop_msg_queue_push(
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_START_WHEN_LOADED),
1, 480, true);
return 0;
/* Enable Netplay itself */
if (!command_event(CMD_EVENT_NETPLAY_INIT_DIRECT_DEFERRED, (void *) tmp_hostname))
return -1;
}
else
{
/* Enable Netplay itself */
if (!command_event(CMD_EVENT_NETPLAY_INIT, (void *) tmp_hostname))
return -1;
}
char tmp_hostname[512];
strlcpy(tmp_hostname, netplay_room_list[idx - 1].address, sizeof(tmp_hostname));
/* Enable Netplay itself */
if (!command_event(CMD_EVENT_NETPLAY_INIT, (void *) tmp_hostname))
return -1;
#else
return -1;

View File

@ -57,6 +57,8 @@ void audio_sample_net(int16_t left, int16_t right);
size_t audio_sample_batch_net(const int16_t *data, size_t frames);
bool init_netplay_deferred(const char* server, unsigned port);
/**
* init_netplay
* @direct_host : Host to connect to directly, if applicable (client only)

View File

@ -21,6 +21,7 @@
#include <boolean.h>
#include <compat/strl.h>
#include <retro_assert.h>
#include <string/stdstring.h>
#include "netplay_private.h"
@ -43,6 +44,11 @@ static netplay_t *netplay_data = NULL;
/* Used to avoid recursive netplay calls */
static bool in_netplay = false;
/* Used for deferred netplay initialization */
static bool netplay_client_deferred = false;
static char server_address_deferred[512] = "";
static unsigned server_port_deferred = 0;
/**
* netplay_is_alive:
* @netplay : pointer to netplay object
@ -156,6 +162,22 @@ static bool get_self_input_state(netplay_t *netplay)
return true;
}
bool init_netplay_deferred(const char* server, unsigned port)
{
RARCH_LOG("deferred! %s\n", server);
if (!string_is_empty(server) && port != 0)
{
strlcpy(server_address_deferred, server, sizeof(server_address_deferred));
server_port_deferred = port;
netplay_client_deferred = true;
}
else
netplay_client_deferred = false;
return netplay_client_deferred;
}
/**
* netplay_poll:
* @netplay : pointer to netplay object
@ -924,7 +946,7 @@ bool init_netplay(void *direct_host, const char *server, unsigned port)
netplay_data = (netplay_t*)netplay_new(
netplay_is_client ? direct_host : NULL,
netplay_is_client ? server : NULL,
netplay_is_client ? (!netplay_client_deferred ? server : server_address_deferred) : NULL,
port ? port : RARCH_DEFAULT_PORT,
settings->netplay.stateless_mode, settings->netplay.check_frames, &cbs,
settings->netplay.nat_traversal, settings->username,