Go back to 1.8.4 netcode

This commit is contained in:
twinaphex 2020-05-10 00:57:59 +02:00
parent 1fc64df5f6
commit 3ad4b057f9
10 changed files with 1742 additions and 1669 deletions

View File

@ -1830,6 +1830,7 @@ ifeq ($(HAVE_NETWORKING), 1)
# Netplay # Netplay
DEFINES += -DHAVE_NETWORK_CMD DEFINES += -DHAVE_NETWORK_CMD
OBJ += network/netplay/netplay_delta.o \ OBJ += network/netplay/netplay_delta.o \
network/netplay/netplay_frontend.o \
network/netplay/netplay_handshake.o \ network/netplay/netplay_handshake.o \
network/netplay/netplay_init.o \ network/netplay/netplay_init.o \
network/netplay/netplay_io.o \ network/netplay/netplay_io.o \

View File

@ -1205,6 +1205,7 @@ NETPLAY
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
#include "../network/netplay/netplay_delta.c" #include "../network/netplay/netplay_delta.c"
#include "../network/netplay/netplay_handshake.c" #include "../network/netplay/netplay_handshake.c"
#include "../network/netplay/netplay_frontend.c"
#include "../network/netplay/netplay_init.c" #include "../network/netplay/netplay_init.c"
#include "../network/netplay/netplay_io.c" #include "../network/netplay/netplay_io.c"
#include "../network/netplay/netplay_keyboard.c" #include "../network/netplay/netplay_keyboard.c"

View File

@ -86,6 +86,32 @@ enum rarch_netplay_share_analog_preference
RARCH_NETPLAY_SHARE_ANALOG_LAST RARCH_NETPLAY_SHARE_ANALOG_LAST
}; };
int16_t input_state_net(unsigned port, unsigned device,
unsigned idx, unsigned id);
void video_frame_net(const void *data, unsigned width,
unsigned height, size_t pitch);
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)
* @server : server address to connect to (client only)
* @port : TCP port to host on/connect to
*
* Initializes netplay.
*
* If netplay is already initialized, will return false (0).
*
* Returns: true (1) if successful, otherwise false (0).
**/
bool init_netplay(void *direct_host, const char *server, unsigned port);
void deinit_netplay(void); void deinit_netplay(void);
bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data); bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data);

File diff suppressed because it is too large Load Diff

View File

@ -94,12 +94,16 @@ void netplay_log_connection(const struct sockaddr_storage *their_addr,
} }
if (str) if (str)
{
snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM_NAME), snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM_NAME),
nick, str); nick, str);
}
else else
{
snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM), snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM),
nick); nick);
} }
}
#else #else
void netplay_log_connection(const struct sockaddr_storage *their_addr, void netplay_log_connection(const struct sockaddr_storage *their_addr,
@ -195,12 +199,11 @@ static uint32_t simple_rand_uint32(void)
* Initialize our handshake and send the first part of the handshake protocol. * Initialize our handshake and send the first part of the handshake protocol.
*/ */
bool netplay_handshake_init_send(netplay_t *netplay, bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection, struct netplay_connection *connection)
const char *netplay_password,
const char *netplay_spectate_password)
{ {
uint32_t header[6]; uint32_t header[6];
unsigned conn_salt = 0; unsigned conn_salt = 0;
settings_t *settings = config_get_ptr();
header[0] = htonl(netplay_magic); header[0] = htonl(netplay_magic);
header[1] = htonl(netplay_platform_magic()); header[1] = htonl(netplay_platform_magic());
@ -210,8 +213,8 @@ bool netplay_handshake_init_send(netplay_t *netplay,
header[5] = htonl(netplay_impl_magic()); header[5] = htonl(netplay_impl_magic());
if (netplay->is_server && if (netplay->is_server &&
(netplay_password[0] || (settings->paths.netplay_password[0] ||
netplay_spectate_password[0])) settings->paths.netplay_spectate_password[0]))
{ {
/* Demand a password */ /* Demand a password */
if (simple_rand_next == 1) if (simple_rand_next == 1)
@ -493,7 +496,7 @@ static void netplay_handshake_ready(netplay_t *netplay,
* *
* Send an INFO command. * Send an INFO command.
*/ */
static bool netplay_handshake_info(netplay_t *netplay, bool netplay_handshake_info(netplay_t *netplay,
struct netplay_connection *connection) struct netplay_connection *connection)
{ {
struct info_buf_s info_buf; struct info_buf_s info_buf;
@ -542,7 +545,7 @@ static bool netplay_handshake_info(netplay_t *netplay,
* *
* Send a SYNC command. * Send a SYNC command.
*/ */
static bool netplay_handshake_sync(netplay_t *netplay, bool netplay_handshake_sync(netplay_t *netplay,
struct netplay_connection *connection) struct netplay_connection *connection)
{ {
/* If we're the server, now we send sync info */ /* If we're the server, now we send sync info */
@ -687,11 +690,8 @@ static bool netplay_handshake_sync(netplay_t *netplay,
* Data receiver for the second stage of handshake, receiving the other side's * Data receiver for the second stage of handshake, receiving the other side's
* nickname. * nickname.
*/ */
static bool netplay_handshake_pre_nick(netplay_t *netplay, bool netplay_handshake_pre_nick(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input, struct netplay_connection *connection, bool *had_input)
const char *netplay_password,
const char *netplay_spectate_password
)
{ {
struct nick_buf_s nick_buf; struct nick_buf_s nick_buf;
ssize_t recvd; ssize_t recvd;
@ -724,9 +724,11 @@ static bool netplay_handshake_pre_nick(netplay_t *netplay,
if (netplay->is_server) if (netplay->is_server)
{ {
settings_t *settings = config_get_ptr();
/* There's a password, so just put them in PRE_PASSWORD mode */ /* There's a password, so just put them in PRE_PASSWORD mode */
if ( netplay_password[0] || if ( settings->paths.netplay_password[0] ||
netplay_spectate_password[0]) settings->paths.netplay_spectate_password[0])
connection->mode = NETPLAY_CONNECTION_PRE_PASSWORD; connection->mode = NETPLAY_CONNECTION_PRE_PASSWORD;
else else
{ {
@ -751,10 +753,8 @@ static bool netplay_handshake_pre_nick(netplay_t *netplay,
* Data receiver for the third, optional stage of server handshake, receiving * Data receiver for the third, optional stage of server handshake, receiving
* the password and sending core/content info. * the password and sending core/content info.
*/ */
static bool netplay_handshake_pre_password(netplay_t *netplay, bool netplay_handshake_pre_password(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input, struct netplay_connection *connection, bool *had_input)
const char *netplay_password,
const char *netplay_spectate_password)
{ {
struct password_buf_s password_buf; struct password_buf_s password_buf;
char password[8+NETPLAY_PASS_LEN]; /* 8 for salt */ char password[8+NETPLAY_PASS_LEN]; /* 8 for salt */
@ -762,6 +762,7 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
ssize_t recvd; ssize_t recvd;
char msg[512]; char msg[512];
bool correct = false; bool correct = false;
settings_t *settings = config_get_ptr();
msg[0] = '\0'; msg[0] = '\0';
@ -788,10 +789,10 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
correct = false; correct = false;
snprintf(password, sizeof(password), "%08X", connection->salt); snprintf(password, sizeof(password), "%08X", connection->salt);
if (netplay_password[0]) if (settings->paths.netplay_password[0])
{ {
strlcpy(password + 8, strlcpy(password + 8,
netplay_password, sizeof(password)-8); settings->paths.netplay_password, sizeof(password)-8);
sha256_hash(hash, (uint8_t *) password, strlen(password)); sha256_hash(hash, (uint8_t *) password, strlen(password));
@ -801,10 +802,10 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
connection->can_play = true; connection->can_play = true;
} }
} }
if (netplay_spectate_password[0]) if (settings->paths.netplay_spectate_password[0])
{ {
strlcpy(password + 8, strlcpy(password + 8,
netplay_spectate_password, sizeof(password)-8); settings->paths.netplay_spectate_password, sizeof(password)-8);
sha256_hash(hash, (uint8_t *) password, strlen(password)); sha256_hash(hash, (uint8_t *) password, strlen(password));
@ -832,7 +833,7 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
* Data receiver for the third stage of server handshake, receiving * Data receiver for the third stage of server handshake, receiving
* the password. * the password.
*/ */
static bool netplay_handshake_pre_info(netplay_t *netplay, bool netplay_handshake_pre_info(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input) struct netplay_connection *connection, bool *had_input)
{ {
struct info_buf_s info_buf; struct info_buf_s info_buf;
@ -936,9 +937,8 @@ static bool netplay_handshake_pre_info(netplay_t *netplay,
* Data receiver for the client's third handshake stage, receiving the * Data receiver for the client's third handshake stage, receiving the
* synchronization information. * synchronization information.
*/ */
static bool netplay_handshake_pre_sync(netplay_t *netplay, bool netplay_handshake_pre_sync(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input, struct netplay_connection *connection, bool *had_input)
bool netplay_start_as_spectator)
{ {
uint32_t cmd[2]; uint32_t cmd[2];
uint32_t new_frame_count, client_num; uint32_t new_frame_count, client_num;
@ -1069,8 +1069,7 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
snprintf(msg, sizeof(msg), snprintf(msg, sizeof(msg),
msg_hash_to_str(MSG_NETPLAY_CHANGED_NICK), netplay->nick); msg_hash_to_str(MSG_NETPLAY_CHANGED_NICK), netplay->nick);
RARCH_LOG("%s\n", msg); RARCH_LOG("%s\n", msg);
runloop_msg_queue_push(msg, 1, 180, false, NULL, runloop_msg_queue_push(msg, 1, 180, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
} }
/* Now check the SRAM */ /* Now check the SRAM */
@ -1103,8 +1102,7 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
uint32_t quickbuf; uint32_t quickbuf;
while (remote_sram_size > 0) while (remote_sram_size > 0)
{ {
RECV(&quickbuf, (remote_sram_size > sizeof(uint32_t)) RECV(&quickbuf, (remote_sram_size > sizeof(uint32_t)) ? sizeof(uint32_t) : remote_sram_size)
? sizeof(uint32_t) : remote_sram_size)
{ {
RARCH_ERR("%s\n", RARCH_ERR("%s\n",
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_SRAM_DATA_FROM_HOST)); msg_hash_to_str(MSG_FAILED_TO_RECEIVE_SRAM_DATA_FROM_HOST));
@ -1132,8 +1130,11 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
netplay_recv_flush(&connection->recv_packet_buffer); netplay_recv_flush(&connection->recv_packet_buffer);
/* Ask to switch to playing mode if we should */ /* Ask to switch to playing mode if we should */
if (!netplay_start_as_spectator) {
settings_t *settings = config_get_ptr();
if (!settings->bools.netplay_start_as_spectator)
return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING); return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING);
}
return true; return true;
} }
@ -1154,32 +1155,16 @@ bool netplay_handshake(netplay_t *netplay,
ret = netplay_handshake_init(netplay, connection, had_input); ret = netplay_handshake_init(netplay, connection, had_input);
break; break;
case NETPLAY_CONNECTION_PRE_NICK: case NETPLAY_CONNECTION_PRE_NICK:
{ ret = netplay_handshake_pre_nick(netplay, connection, had_input);
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_nick(netplay, connection, had_input,
settings->paths.netplay_password,
settings->paths.netplay_spectate_password
);
}
break; break;
case NETPLAY_CONNECTION_PRE_PASSWORD: case NETPLAY_CONNECTION_PRE_PASSWORD:
{ ret = netplay_handshake_pre_password(netplay, connection, had_input);
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_password(netplay, connection, had_input,
settings->paths.netplay_password,
settings->paths.netplay_spectate_password
);
}
break; break;
case NETPLAY_CONNECTION_PRE_INFO: case NETPLAY_CONNECTION_PRE_INFO:
ret = netplay_handshake_pre_info(netplay, connection, had_input); ret = netplay_handshake_pre_info(netplay, connection, had_input);
break; break;
case NETPLAY_CONNECTION_PRE_SYNC: case NETPLAY_CONNECTION_PRE_SYNC:
{ ret = netplay_handshake_pre_sync(netplay, connection, had_input);
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_sync(netplay, connection, had_input,
settings->bools.netplay_start_as_spectator);
}
break; break;
case NETPLAY_CONNECTION_NONE: case NETPLAY_CONNECTION_NONE:
default: default:

View File

@ -418,8 +418,6 @@ static bool netplay_init_buffers(netplay_t *netplay)
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port, netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
bool stateless_mode, int check_frames, bool stateless_mode, int check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick, const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
const char *netplay_password,
const char *netplay_spectate_password,
uint64_t quirks) uint64_t quirks)
{ {
netplay_t *netplay = (netplay_t*)calloc(1, sizeof(*netplay)); netplay_t *netplay = (netplay_t*)calloc(1, sizeof(*netplay));
@ -489,9 +487,7 @@ netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
else else
{ {
/* Start our handshake */ /* Start our handshake */
netplay_handshake_init_send(netplay, &netplay->connections[0], netplay_handshake_init_send(netplay, &netplay->connections[0]);
netplay_password,
netplay_spectate_password);
netplay->connections[0].mode = NETPLAY_CONNECTION_INIT; netplay->connections[0].mode = NETPLAY_CONNECTION_INIT;
netplay->self_mode = NETPLAY_CONNECTION_INIT; netplay->self_mode = NETPLAY_CONNECTION_INIT;

View File

@ -730,7 +730,7 @@ static void handle_play_spectate(netplay_t *netplay, uint32_t client_num,
case NETPLAY_CMD_PLAY: case NETPLAY_CMD_PLAY:
{ {
uint32_t mode, devices = 0, device; uint32_t mode, devices = 0, device;
uint8_t share_mode = 0; uint8_t share_mode;
bool slave = false; bool slave = false;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
@ -1248,7 +1248,6 @@ static bool netplay_get_cmd(netplay_t *netplay,
mode = ntohl(payload[1]); mode = ntohl(payload[1]);
client_num = mode & 0xFFFF; client_num = mode & 0xFFFF;
if (client_num >= MAX_CLIENTS) if (client_num >= MAX_CLIENTS)
{ {
RARCH_ERR("Received NETPLAY_CMD_MODE for a higher player number than we support.\n"); RARCH_ERR("Received NETPLAY_CMD_MODE for a higher player number than we support.\n");

View File

@ -723,7 +723,7 @@ uint8_t netplay_settings_share_mode(unsigned share_digital, unsigned share_analo
* *
* Poll the network if necessary. * Poll the network if necessary.
*/ */
void input_poll_net(netplay_t *netplay); void input_poll_net(void);
/*************************************************************** /***************************************************************
* NETPLAY-HANDSHAKE.C * NETPLAY-HANDSHAKE.C
@ -735,9 +735,7 @@ void input_poll_net(netplay_t *netplay);
* Initialize our handshake and send the first part of the handshake protocol. * Initialize our handshake and send the first part of the handshake protocol.
*/ */
bool netplay_handshake_init_send(netplay_t *netplay, bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection, struct netplay_connection *connection);
const char *netplay_password,
const char *netplay_spectate_password);
/** /**
* netplay_handshake * netplay_handshake
@ -790,8 +788,6 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay);
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port, netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
bool stateless_mode, int check_frames, bool stateless_mode, int check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick, const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
const char *netplay_password,
const char *netplay_spectate_password,
uint64_t quirks); uint64_t quirks);
/** /**
@ -969,10 +965,7 @@ bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim);
* *
* Pre-frame for Netplay synchronization. * Pre-frame for Netplay synchronization.
*/ */
bool netplay_sync_pre_frame(netplay_t *netplay, bool netplay_sync_pre_frame(netplay_t *netplay);
const char *netplay_password,
const char *netplay_spectate_password
);
/** /**
* netplay_sync_post_frame * netplay_sync_post_frame

View File

@ -551,10 +551,7 @@ static void netplay_handle_frame_hash(netplay_t *netplay,
* *
* Pre-frame for Netplay synchronization. * Pre-frame for Netplay synchronization.
*/ */
bool netplay_sync_pre_frame(netplay_t *netplay, bool netplay_sync_pre_frame(netplay_t *netplay)
const char *netplay_password,
const char *netplay_spectate_password
)
{ {
retro_ctx_serialize_info_t serial_info; retro_ctx_serialize_info_t serial_info;
@ -729,15 +726,14 @@ bool netplay_sync_pre_frame(netplay_t *netplay,
goto process; goto process;
} }
netplay_handshake_init_send(netplay, connection, netplay_handshake_init_send(netplay, connection);
netplay_password, netplay_spectate_password);
} }
} }
process: process:
netplay->can_poll = true; netplay->can_poll = true;
input_poll_net(netplay); input_poll_net();
return (netplay->stall != NETPLAY_STALL_NO_CONNECTION); return (netplay->stall != NETPLAY_STALL_NO_CONNECTION);
} }
@ -752,7 +748,6 @@ process:
void netplay_sync_post_frame(netplay_t *netplay, bool stalled) void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
{ {
uint32_t lo_frame_count, hi_frame_count; uint32_t lo_frame_count, hi_frame_count;
retro_time_t current_time = cpu_features_get_time_usec();
/* Unless we're stalling, we've just finished running a frame */ /* Unless we're stalling, we've just finished running a frame */
if (!stalled) if (!stalled)
@ -879,14 +874,15 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
while (netplay->replay_frame_count < netplay->run_frame_count) while (netplay->replay_frame_count < netplay->run_frame_count)
{ {
retro_time_t tm; retro_time_t start, tm;
struct delta_frame *ptr = &netplay->buffer[netplay->replay_ptr]; struct delta_frame *ptr = &netplay->buffer[netplay->replay_ptr];
retro_time_t start = current_time;
serial_info.data = ptr->state; serial_info.data = ptr->state;
serial_info.size = netplay->state_size; serial_info.size = netplay->state_size;
serial_info.data_const = NULL; serial_info.data_const = NULL;
start = cpu_features_get_time_usec();
/* Remember the current state */ /* Remember the current state */
memset(serial_info.data, 0, serial_info.size); memset(serial_info.data, 0, serial_info.size);
core_serialize(&serial_info); core_serialize(&serial_info);
@ -923,7 +919,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
#endif #endif
/* Get our time window */ /* Get our time window */
tm = current_time - start; tm = cpu_features_get_time_usec() - start;
netplay->frame_run_time_sum -= netplay->frame_run_time[netplay->frame_run_time_ptr]; netplay->frame_run_time_sum -= netplay->frame_run_time[netplay->frame_run_time_ptr];
netplay->frame_run_time[netplay->frame_run_time_ptr] = tm; netplay->frame_run_time[netplay->frame_run_time_ptr] = tm;
netplay->frame_run_time_sum += tm; netplay->frame_run_time_sum += tm;
@ -983,6 +979,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
{ {
if (netplay->self_frame_count + 3 < lo_frame_count) if (netplay->self_frame_count + 3 < lo_frame_count)
{ {
retro_time_t cur_time = cpu_features_get_time_usec();
uint32_t cur_behind = lo_frame_count - netplay->self_frame_count; uint32_t cur_behind = lo_frame_count - netplay->self_frame_count;
/* We're behind, but we'll only try to catch up if we're actually /* We're behind, but we'll only try to catch up if we're actually
@ -990,12 +987,11 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
if (netplay->catch_up_time == 0) if (netplay->catch_up_time == 0)
{ {
/* Record our current time to check for catch-up later */ /* Record our current time to check for catch-up later */
netplay->catch_up_time = current_time; netplay->catch_up_time = cur_time;
netplay->catch_up_behind = cur_behind; netplay->catch_up_behind = cur_behind;
} }
else if (current_time - netplay->catch_up_time else if (cur_time - netplay->catch_up_time > CATCH_UP_CHECK_TIME_USEC)
> CATCH_UP_CHECK_TIME_USEC)
{ {
/* Time to check how far behind we are */ /* Time to check how far behind we are */
if (netplay->catch_up_behind <= cur_behind) if (netplay->catch_up_behind <= cur_behind)
@ -1009,7 +1005,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
else else
{ {
/* Check again in another period */ /* Check again in another period */
netplay->catch_up_time = current_time; netplay->catch_up_time = cur_time;
netplay->catch_up_behind = cur_behind; netplay->catch_up_behind = cur_behind;
} }
} }

File diff suppressed because it is too large Load Diff