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
DEFINES += -DHAVE_NETWORK_CMD
OBJ += network/netplay/netplay_delta.o \
network/netplay/netplay_frontend.o \
network/netplay/netplay_handshake.o \
network/netplay/netplay_init.o \
network/netplay/netplay_io.o \

View File

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

View File

@ -86,6 +86,32 @@ enum rarch_netplay_share_analog_preference
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);
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,11 +94,15 @@ void netplay_log_connection(const struct sockaddr_storage *their_addr,
}
if (str)
{
snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM_NAME),
nick, str);
}
else
{
snprintf(s, len, msg_hash_to_str(MSG_GOT_CONNECTION_FROM),
nick);
}
}
#else
@ -195,12 +199,11 @@ static uint32_t simple_rand_uint32(void)
* Initialize our handshake and send the first part of the handshake protocol.
*/
bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection,
const char *netplay_password,
const char *netplay_spectate_password)
struct netplay_connection *connection)
{
uint32_t header[6];
unsigned conn_salt = 0;
unsigned conn_salt = 0;
settings_t *settings = config_get_ptr();
header[0] = htonl(netplay_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());
if (netplay->is_server &&
(netplay_password[0] ||
netplay_spectate_password[0]))
(settings->paths.netplay_password[0] ||
settings->paths.netplay_spectate_password[0]))
{
/* Demand a password */
if (simple_rand_next == 1)
@ -493,7 +496,7 @@ static void netplay_handshake_ready(netplay_t *netplay,
*
* Send an INFO command.
*/
static bool netplay_handshake_info(netplay_t *netplay,
bool netplay_handshake_info(netplay_t *netplay,
struct netplay_connection *connection)
{
struct info_buf_s info_buf;
@ -542,7 +545,7 @@ static bool netplay_handshake_info(netplay_t *netplay,
*
* Send a SYNC command.
*/
static bool netplay_handshake_sync(netplay_t *netplay,
bool netplay_handshake_sync(netplay_t *netplay,
struct netplay_connection *connection)
{
/* 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
* nickname.
*/
static bool netplay_handshake_pre_nick(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input,
const char *netplay_password,
const char *netplay_spectate_password
)
bool netplay_handshake_pre_nick(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input)
{
struct nick_buf_s nick_buf;
ssize_t recvd;
@ -724,9 +724,11 @@ static bool netplay_handshake_pre_nick(netplay_t *netplay,
if (netplay->is_server)
{
settings_t *settings = config_get_ptr();
/* There's a password, so just put them in PRE_PASSWORD mode */
if ( netplay_password[0] ||
netplay_spectate_password[0])
if ( settings->paths.netplay_password[0] ||
settings->paths.netplay_spectate_password[0])
connection->mode = NETPLAY_CONNECTION_PRE_PASSWORD;
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
* the password and sending core/content info.
*/
static bool netplay_handshake_pre_password(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input,
const char *netplay_password,
const char *netplay_spectate_password)
bool netplay_handshake_pre_password(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input)
{
struct password_buf_s password_buf;
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;
char msg[512];
bool correct = false;
settings_t *settings = config_get_ptr();
msg[0] = '\0';
@ -788,10 +789,10 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
correct = false;
snprintf(password, sizeof(password), "%08X", connection->salt);
if (netplay_password[0])
if (settings->paths.netplay_password[0])
{
strlcpy(password + 8,
netplay_password, sizeof(password)-8);
settings->paths.netplay_password, sizeof(password)-8);
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;
}
}
if (netplay_spectate_password[0])
if (settings->paths.netplay_spectate_password[0])
{
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));
@ -832,7 +833,7 @@ static bool netplay_handshake_pre_password(netplay_t *netplay,
* Data receiver for the third stage of server handshake, receiving
* 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 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
* synchronization information.
*/
static bool netplay_handshake_pre_sync(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input,
bool netplay_start_as_spectator)
bool netplay_handshake_pre_sync(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input)
{
uint32_t cmd[2];
uint32_t new_frame_count, client_num;
@ -1069,8 +1069,7 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
snprintf(msg, sizeof(msg),
msg_hash_to_str(MSG_NETPLAY_CHANGED_NICK), netplay->nick);
RARCH_LOG("%s\n", msg);
runloop_msg_queue_push(msg, 1, 180, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
runloop_msg_queue_push(msg, 1, 180, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
/* Now check the SRAM */
@ -1103,8 +1102,7 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
uint32_t quickbuf;
while (remote_sram_size > 0)
{
RECV(&quickbuf, (remote_sram_size > sizeof(uint32_t))
? sizeof(uint32_t) : remote_sram_size)
RECV(&quickbuf, (remote_sram_size > sizeof(uint32_t)) ? sizeof(uint32_t) : remote_sram_size)
{
RARCH_ERR("%s\n",
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_SRAM_DATA_FROM_HOST));
@ -1125,15 +1123,18 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
#endif
/* We're ready! */
*had_input = true;
*had_input = true;
netplay->self_mode = NETPLAY_CONNECTION_SPECTATING;
connection->mode = NETPLAY_CONNECTION_PLAYING;
connection->mode = NETPLAY_CONNECTION_PLAYING;
netplay_handshake_ready(netplay, connection);
netplay_recv_flush(&connection->recv_packet_buffer);
/* Ask to switch to playing mode if we should */
if (!netplay_start_as_spectator)
return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING);
{
settings_t *settings = config_get_ptr();
if (!settings->bools.netplay_start_as_spectator)
return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING);
}
return true;
}
@ -1146,7 +1147,7 @@ static bool netplay_handshake_pre_sync(netplay_t *netplay,
bool netplay_handshake(netplay_t *netplay,
struct netplay_connection *connection, bool *had_input)
{
bool ret = false;
bool ret = false;
switch (connection->mode)
{
@ -1154,32 +1155,16 @@ bool netplay_handshake(netplay_t *netplay,
ret = netplay_handshake_init(netplay, connection, had_input);
break;
case NETPLAY_CONNECTION_PRE_NICK:
{
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_nick(netplay, connection, had_input,
settings->paths.netplay_password,
settings->paths.netplay_spectate_password
);
}
ret = netplay_handshake_pre_nick(netplay, connection, had_input);
break;
case NETPLAY_CONNECTION_PRE_PASSWORD:
{
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_password(netplay, connection, had_input,
settings->paths.netplay_password,
settings->paths.netplay_spectate_password
);
}
ret = netplay_handshake_pre_password(netplay, connection, had_input);
break;
case NETPLAY_CONNECTION_PRE_INFO:
ret = netplay_handshake_pre_info(netplay, connection, had_input);
break;
case NETPLAY_CONNECTION_PRE_SYNC:
{
settings_t *settings = config_get_ptr();
ret = netplay_handshake_pre_sync(netplay, connection, had_input,
settings->bools.netplay_start_as_spectator);
}
ret = netplay_handshake_pre_sync(netplay, connection, had_input);
break;
case NETPLAY_CONNECTION_NONE:
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,
bool stateless_mode, int check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
const char *netplay_password,
const char *netplay_spectate_password,
uint64_t quirks)
{
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
{
/* Start our handshake */
netplay_handshake_init_send(netplay, &netplay->connections[0],
netplay_password,
netplay_spectate_password);
netplay_handshake_init_send(netplay, &netplay->connections[0]);
netplay->connections[0].mode = NETPLAY_CONNECTION_INIT;
netplay->self_mode = NETPLAY_CONNECTION_INIT;

View File

@ -730,20 +730,20 @@ static void handle_play_spectate(netplay_t *netplay, uint32_t client_num,
case NETPLAY_CMD_PLAY:
{
uint32_t mode, devices = 0, device;
uint8_t share_mode = 0;
bool slave = false;
uint8_t share_mode;
bool slave = false;
settings_t *settings = config_get_ptr();
if (cmd_size != sizeof(uint32_t) || !in_payload)
return;
mode = ntohl(in_payload[0]);
mode = ntohl(in_payload[0]);
/* Check the requested mode */
slave = (mode & NETPLAY_CMD_PLAY_BIT_SLAVE)?true:false;
share_mode = (mode>>16) & 0xFF;
slave = (mode&NETPLAY_CMD_PLAY_BIT_SLAVE)?true:false;
share_mode = (mode>>16)&0xFF;
/* And the requested devices */
devices = mode & 0xFFFF;
devices = mode&0xFFFF;
/* Check if their slave mode request corresponds with what we allow */
if (connection)
@ -964,8 +964,8 @@ static bool netplay_get_cmd(netplay_t *netplay,
return false;
RECV(&client_num, sizeof(client_num))
return false;
frame_num = ntohl(frame_num);
client_num = ntohl(client_num);
frame_num = ntohl(frame_num);
client_num = ntohl(client_num);
client_num &= 0xFFFF;
if (netplay->is_server)
@ -1246,9 +1246,8 @@ static bool netplay_get_cmd(netplay_t *netplay,
if (frame < netplay->self_frame_count)
netplay->force_rewind = true;
mode = ntohl(payload[1]);
mode = ntohl(payload[1]);
client_num = mode & 0xFFFF;
if (client_num >= MAX_CLIENTS)
{
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.
*/
void input_poll_net(netplay_t *netplay);
void input_poll_net(void);
/***************************************************************
* 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.
*/
bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection,
const char *netplay_password,
const char *netplay_spectate_password);
struct netplay_connection *connection);
/**
* 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,
bool stateless_mode, int check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
const char *netplay_password,
const char *netplay_spectate_password,
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.
*/
bool netplay_sync_pre_frame(netplay_t *netplay,
const char *netplay_password,
const char *netplay_spectate_password
);
bool netplay_sync_pre_frame(netplay_t *netplay);
/**
* netplay_sync_post_frame

View File

@ -551,10 +551,7 @@ static void netplay_handle_frame_hash(netplay_t *netplay,
*
* Pre-frame for Netplay synchronization.
*/
bool netplay_sync_pre_frame(netplay_t *netplay,
const char *netplay_password,
const char *netplay_spectate_password
)
bool netplay_sync_pre_frame(netplay_t *netplay)
{
retro_ctx_serialize_info_t serial_info;
@ -729,15 +726,14 @@ bool netplay_sync_pre_frame(netplay_t *netplay,
goto process;
}
netplay_handshake_init_send(netplay, connection,
netplay_password, netplay_spectate_password);
netplay_handshake_init_send(netplay, connection);
}
}
process:
netplay->can_poll = true;
input_poll_net(netplay);
input_poll_net();
return (netplay->stall != NETPLAY_STALL_NO_CONNECTION);
}
@ -752,7 +748,6 @@ process:
void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
{
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 */
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)
{
retro_time_t tm;
retro_time_t start, tm;
struct delta_frame *ptr = &netplay->buffer[netplay->replay_ptr];
retro_time_t start = current_time;
serial_info.data = ptr->state;
serial_info.size = netplay->state_size;
serial_info.data_const = NULL;
start = cpu_features_get_time_usec();
/* Remember the current state */
memset(serial_info.data, 0, serial_info.size);
core_serialize(&serial_info);
@ -923,7 +919,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
#endif
/* 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[netplay->frame_run_time_ptr] = 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)
{
retro_time_t cur_time = cpu_features_get_time_usec();
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
@ -990,12 +987,11 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
if (netplay->catch_up_time == 0)
{
/* 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;
}
else if (current_time - netplay->catch_up_time
> CATCH_UP_CHECK_TIME_USEC)
else if (cur_time - netplay->catch_up_time > CATCH_UP_CHECK_TIME_USEC)
{
/* Time to check how far behind we are */
if (netplay->catch_up_behind <= cur_behind)
@ -1009,7 +1005,7 @@ void netplay_sync_post_frame(netplay_t *netplay, bool stalled)
else
{
/* Check again in another period */
netplay->catch_up_time = current_time;
netplay->catch_up_time = cur_time;
netplay->catch_up_behind = cur_behind;
}
}

File diff suppressed because it is too large Load Diff