mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
(network) Get rid of all the settings pointer grabbing
This commit is contained in:
parent
e93244e0cb
commit
013117318c
@ -1039,7 +1039,10 @@ bool netplay_pre_frame(netplay_t *netplay)
|
||||
}
|
||||
}
|
||||
|
||||
sync_stalled = !netplay_sync_pre_frame(netplay);
|
||||
sync_stalled = !netplay_sync_pre_frame(netplay,
|
||||
settings->paths.netplay_password,
|
||||
settings->paths.netplay_spectate_password
|
||||
);
|
||||
|
||||
/* If we're disconnected, deinitialize */
|
||||
if (!netplay->is_server && !netplay->connections[0].active)
|
||||
@ -1466,6 +1469,8 @@ bool init_netplay(void *direct_host, const char *server, unsigned port)
|
||||
discord_get_own_username() ? discord_get_own_username() :
|
||||
#endif
|
||||
settings->paths.username,
|
||||
settings->paths.netplay_password,
|
||||
settings->paths.netplay_spectate_password,
|
||||
quirks);
|
||||
|
||||
if (netplay_data)
|
||||
|
@ -94,15 +94,11 @@ 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
|
||||
@ -199,11 +195,12 @@ 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)
|
||||
struct netplay_connection *connection,
|
||||
const char *netplay_password,
|
||||
const char *netplay_spectate_password)
|
||||
{
|
||||
uint32_t header[6];
|
||||
unsigned conn_salt = 0;
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned conn_salt = 0;
|
||||
|
||||
header[0] = htonl(netplay_magic);
|
||||
header[1] = htonl(netplay_platform_magic());
|
||||
@ -213,8 +210,8 @@ bool netplay_handshake_init_send(netplay_t *netplay,
|
||||
header[5] = htonl(netplay_impl_magic());
|
||||
|
||||
if (netplay->is_server &&
|
||||
(settings->paths.netplay_password[0] ||
|
||||
settings->paths.netplay_spectate_password[0]))
|
||||
(netplay_password[0] ||
|
||||
netplay_spectate_password[0]))
|
||||
{
|
||||
/* Demand a password */
|
||||
if (simple_rand_next == 1)
|
||||
@ -496,7 +493,7 @@ static void netplay_handshake_ready(netplay_t *netplay,
|
||||
*
|
||||
* Send an INFO command.
|
||||
*/
|
||||
bool netplay_handshake_info(netplay_t *netplay,
|
||||
static bool netplay_handshake_info(netplay_t *netplay,
|
||||
struct netplay_connection *connection)
|
||||
{
|
||||
struct info_buf_s info_buf;
|
||||
@ -545,7 +542,7 @@ bool netplay_handshake_info(netplay_t *netplay,
|
||||
*
|
||||
* Send a SYNC command.
|
||||
*/
|
||||
bool netplay_handshake_sync(netplay_t *netplay,
|
||||
static bool netplay_handshake_sync(netplay_t *netplay,
|
||||
struct netplay_connection *connection)
|
||||
{
|
||||
/* If we're the server, now we send sync info */
|
||||
@ -690,8 +687,11 @@ bool netplay_handshake_sync(netplay_t *netplay,
|
||||
* Data receiver for the second stage of handshake, receiving the other side's
|
||||
* nickname.
|
||||
*/
|
||||
bool netplay_handshake_pre_nick(netplay_t *netplay,
|
||||
struct netplay_connection *connection, bool *had_input)
|
||||
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
|
||||
)
|
||||
{
|
||||
struct nick_buf_s nick_buf;
|
||||
ssize_t recvd;
|
||||
@ -724,11 +724,9 @@ 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 ( settings->paths.netplay_password[0] ||
|
||||
settings->paths.netplay_spectate_password[0])
|
||||
if ( netplay_password[0] ||
|
||||
netplay_spectate_password[0])
|
||||
connection->mode = NETPLAY_CONNECTION_PRE_PASSWORD;
|
||||
else
|
||||
{
|
||||
@ -753,8 +751,10 @@ 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.
|
||||
*/
|
||||
bool netplay_handshake_pre_password(netplay_t *netplay,
|
||||
struct netplay_connection *connection, bool *had_input)
|
||||
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)
|
||||
{
|
||||
struct password_buf_s password_buf;
|
||||
char password[8+NETPLAY_PASS_LEN]; /* 8 for salt */
|
||||
@ -762,7 +762,6 @@ 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';
|
||||
|
||||
@ -789,10 +788,10 @@ bool netplay_handshake_pre_password(netplay_t *netplay,
|
||||
correct = false;
|
||||
snprintf(password, sizeof(password), "%08X", connection->salt);
|
||||
|
||||
if (settings->paths.netplay_password[0])
|
||||
if (netplay_password[0])
|
||||
{
|
||||
strlcpy(password + 8,
|
||||
settings->paths.netplay_password, sizeof(password)-8);
|
||||
netplay_password, sizeof(password)-8);
|
||||
|
||||
sha256_hash(hash, (uint8_t *) password, strlen(password));
|
||||
|
||||
@ -802,10 +801,10 @@ bool netplay_handshake_pre_password(netplay_t *netplay,
|
||||
connection->can_play = true;
|
||||
}
|
||||
}
|
||||
if (settings->paths.netplay_spectate_password[0])
|
||||
if (netplay_spectate_password[0])
|
||||
{
|
||||
strlcpy(password + 8,
|
||||
settings->paths.netplay_spectate_password, sizeof(password)-8);
|
||||
netplay_spectate_password, sizeof(password)-8);
|
||||
|
||||
sha256_hash(hash, (uint8_t *) password, strlen(password));
|
||||
|
||||
@ -833,7 +832,7 @@ bool netplay_handshake_pre_password(netplay_t *netplay,
|
||||
* Data receiver for the third stage of server handshake, receiving
|
||||
* the password.
|
||||
*/
|
||||
bool netplay_handshake_pre_info(netplay_t *netplay,
|
||||
static bool netplay_handshake_pre_info(netplay_t *netplay,
|
||||
struct netplay_connection *connection, bool *had_input)
|
||||
{
|
||||
struct info_buf_s info_buf;
|
||||
@ -937,8 +936,9 @@ bool netplay_handshake_pre_info(netplay_t *netplay,
|
||||
* Data receiver for the client's third handshake stage, receiving the
|
||||
* synchronization information.
|
||||
*/
|
||||
bool netplay_handshake_pre_sync(netplay_t *netplay,
|
||||
struct netplay_connection *connection, bool *had_input)
|
||||
static bool netplay_handshake_pre_sync(netplay_t *netplay,
|
||||
struct netplay_connection *connection, bool *had_input,
|
||||
bool netplay_start_as_spectator)
|
||||
{
|
||||
uint32_t cmd[2];
|
||||
uint32_t new_frame_count, client_num;
|
||||
@ -1069,7 +1069,8 @@ 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 */
|
||||
@ -1102,7 +1103,8 @@ 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));
|
||||
@ -1123,18 +1125,15 @@ 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 */
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
if (!settings->bools.netplay_start_as_spectator)
|
||||
return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING);
|
||||
}
|
||||
if (!netplay_start_as_spectator)
|
||||
return netplay_cmd_mode(netplay, NETPLAY_CONNECTION_PLAYING);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1147,7 +1146,7 @@ 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)
|
||||
{
|
||||
@ -1155,16 +1154,32 @@ bool netplay_handshake(netplay_t *netplay,
|
||||
ret = netplay_handshake_init(netplay, connection, had_input);
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
case NETPLAY_CONNECTION_PRE_INFO:
|
||||
ret = netplay_handshake_pre_info(netplay, connection, had_input);
|
||||
break;
|
||||
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;
|
||||
case NETPLAY_CONNECTION_NONE:
|
||||
default:
|
||||
|
@ -418,6 +418,8 @@ 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));
|
||||
@ -487,7 +489,9 @@ 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_handshake_init_send(netplay, &netplay->connections[0],
|
||||
netplay_password,
|
||||
netplay_spectate_password);
|
||||
|
||||
netplay->connections[0].mode = NETPLAY_CONNECTION_INIT;
|
||||
netplay->self_mode = NETPLAY_CONNECTION_INIT;
|
||||
|
@ -735,7 +735,9 @@ void input_poll_net(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);
|
||||
struct netplay_connection *connection,
|
||||
const char *netplay_password,
|
||||
const char *netplay_spectate_password);
|
||||
|
||||
/**
|
||||
* netplay_handshake
|
||||
@ -788,6 +790,8 @@ 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);
|
||||
|
||||
/**
|
||||
@ -965,7 +969,10 @@ 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);
|
||||
bool netplay_sync_pre_frame(netplay_t *netplay,
|
||||
const char *netplay_password,
|
||||
const char *netplay_spectate_password
|
||||
);
|
||||
|
||||
/**
|
||||
* netplay_sync_post_frame
|
||||
|
@ -551,7 +551,10 @@ static void netplay_handle_frame_hash(netplay_t *netplay,
|
||||
*
|
||||
* 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;
|
||||
|
||||
@ -726,7 +729,8 @@ bool netplay_sync_pre_frame(netplay_t *netplay)
|
||||
goto process;
|
||||
}
|
||||
|
||||
netplay_handshake_init_send(netplay, connection);
|
||||
netplay_handshake_init_send(netplay, connection,
|
||||
netplay_password, netplay_spectate_password);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user