This commit is contained in:
twinaphex 2017-05-21 09:16:45 +02:00
parent f653cf4e7c
commit 0bb1de9561

View File

@ -152,14 +152,14 @@ static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
}
else
{
/* I'll build my own addrinfo! With blackjack and hookers! */
struct netplay_host *host = (struct netplay_host *) direct_host;
hints.ai_family = host->addr.sa_family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
hints.ai_addrlen = host->addrlen;
hints.ai_addr = &host->addr;
res = &hints;
/* I'll build my own addrinfo! */
struct netplay_host *host = (struct netplay_host *)direct_host;
hints.ai_family = host->addr.sa_family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
hints.ai_addrlen = host->addrlen;
hints.ai_addr = &host->addr;
res = &hints;
}
@ -169,7 +169,7 @@ static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
if (!direct_host && !server && res->ai_family == AF_INET6)
{
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) res->ai_addr;
sin6->sin6_addr = in6addr_any;
sin6->sin6_addr = in6addr_any;
}
#endif
@ -192,8 +192,8 @@ static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
if (direct_host || server)
{
netplay->connections[0].active = true;
netplay->connections[0].fd = fd;
netplay->connections[0].addr = sad;
netplay->connections[0].fd = fd;
netplay->connections[0].addr = sad;
}
else
{
@ -214,7 +214,8 @@ static bool init_tcp_socket(netplay_t *netplay, void *direct_host,
return ret;
}
static bool init_socket(netplay_t *netplay, void *direct_host, const char *server, uint16_t port)
static bool init_socket(netplay_t *netplay, void *direct_host,
const char *server, uint16_t port)
{
if (!network_init())
return false;
@ -321,8 +322,8 @@ bool netplay_try_init_serialization(netplay_t *netplay)
/* Check if we can actually save */
serial_info.data_const = NULL;
serial_info.data = netplay->buffer[netplay->run_ptr].state;
serial_info.size = netplay->state_size;
serial_info.data = netplay->buffer[netplay->run_ptr].state;
serial_info.size = netplay->state_size;
if (!core_serialize(&serial_info))
return false;
@ -368,8 +369,7 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay)
static bool netplay_init_buffers(netplay_t *netplay)
{
if (!netplay)
return false;
struct delta_frame *delta_frames = NULL;
/* Enough to get ahead or behind by MAX_STALL_FRAMES frames */
netplay->buffer_size = NETPLAY_MAX_STALL_FRAMES + 1;
@ -379,12 +379,14 @@ static bool netplay_init_buffers(netplay_t *netplay)
if (netplay->is_server)
netplay->buffer_size *= 2;
netplay->buffer = (struct delta_frame*)calloc(netplay->buffer_size,
sizeof(*netplay->buffer));
delta_frames = (struct delta_frame*)calloc(netplay->buffer_size,
sizeof(*delta_frames));
if (!netplay->buffer)
if (!delta_frames)
return false;
netplay->buffer = delta_frames;
if (!(netplay->quirks & (NETPLAY_QUIRK_NO_SAVESTATES|NETPLAY_QUIRK_INITIALIZATION)))
netplay_init_serialization(netplay);
@ -417,36 +419,38 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
if (!netplay)
return NULL;
netplay->listen_fd = -1;
netplay->tcp_port = port;
netplay->cbs = *cb;
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;
netplay->listen_fd = -1;
netplay->tcp_port = port;
netplay->cbs = *cb;
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;
netplay->crc_validity_checked = false;
netplay->crcs_valid = true;
netplay->quirks = quirks;
netplay->self_mode = netplay->is_server ?
netplay->crcs_valid = true;
netplay->quirks = quirks;
netplay->self_mode = netplay->is_server ?
NETPLAY_CONNECTION_SPECTATING :
NETPLAY_CONNECTION_NONE;
if (netplay->is_server)
{
netplay->connections = NULL;
netplay->connections_size = 0;
netplay->connections = NULL;
netplay->connections_size = 0;
}
else
{
netplay->connections = &netplay->one_connection;
netplay->connections_size = 1;
netplay->connections = &netplay->one_connection;
netplay->connections_size = 1;
netplay->connections[0].fd = -1;
}
strlcpy(netplay->nick, nick[0] ? nick : RARCH_DEFAULT_NICK, sizeof(netplay->nick));
strlcpy(netplay->nick, nick[0]
? nick : RARCH_DEFAULT_NICK,
sizeof(netplay->nick));
if (!init_socket(netplay, direct_host, server, port))
{
@ -463,11 +467,13 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
if (!netplay->is_server)
{
netplay_handshake_init_send(netplay, &netplay->connections[0]);
netplay->connections[0].mode = netplay->self_mode = NETPLAY_CONNECTION_INIT;
netplay->connections[0].mode = NETPLAY_CONNECTION_INIT;
netplay->self_mode = NETPLAY_CONNECTION_INIT;
}
/* FIXME: Not really the right place to do this, socket initialization needs
* to be fixed in general */
/* FIXME: Not really the right place to do this,
* socket initialization needs to be fixed in general. */
if (netplay->is_server)
{
if (!socket_nonblock(netplay->listen_fd))