Skip to content

Commit

Permalink
can now connect when starting a game too
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-asm committed Jan 20, 2017
1 parent 42dc8c7 commit 0de43b9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 9 deletions.
15 changes: 15 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions command.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
24 changes: 16 additions & 8 deletions menu/cbs/menu_cbs_ok.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

char tmp_hostname[512];
strlcpy(tmp_hostname, netplay_room_list[idx - 1].address, sizeof(tmp_hostname));
/* Enable Netplay itself */

/* Enable Netplay itself */
if (!command_event(CMD_EVENT_NETPLAY_INIT, (void *) tmp_hostname))
return -1;
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;
}

#else
return -1;
Expand Down
2 changes: 2 additions & 0 deletions network/netplay/netplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion network/netplay/netplay_frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <boolean.h>
#include <compat/strl.h>
#include <retro_assert.h>
#include <string/stdstring.h>

#include "netplay_private.h"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0de43b9

Please sign in to comment.