(Netplay) Cleanups

This commit is contained in:
twinaphex 2020-01-02 17:07:03 +01:00
parent c4e04a6d09
commit fa328c1590
5 changed files with 41 additions and 41 deletions

View File

@ -1328,15 +1328,13 @@ static void netplay_core_reset(netplay_t *netplay)
* *
* Get the preferred share mode * Get the preferred share mode
*/ */
uint8_t netplay_settings_share_mode(void) uint8_t netplay_settings_share_mode(unsigned share_digital, unsigned share_analog)
{ {
settings_t *settings = config_get_ptr(); uint8_t share_mode = 0;
uint8_t share_mode = 0;
if (settings->uints.netplay_share_digital if (share_digital || share_analog)
|| settings->uints.netplay_share_analog)
{ {
switch (settings->uints.netplay_share_digital) switch (share_digital)
{ {
case RARCH_NETPLAY_SHARE_DIGITAL_OR: case RARCH_NETPLAY_SHARE_DIGITAL_OR:
share_mode |= NETPLAY_SHARE_DIGITAL_OR; share_mode |= NETPLAY_SHARE_DIGITAL_OR;
@ -1350,7 +1348,7 @@ uint8_t netplay_settings_share_mode(void)
default: default:
share_mode |= NETPLAY_SHARE_NO_PREFERENCE; share_mode |= NETPLAY_SHARE_NO_PREFERENCE;
} }
switch (settings->uints.netplay_share_analog) switch (share_analog)
{ {
case RARCH_NETPLAY_SHARE_ANALOG_MAX: case RARCH_NETPLAY_SHARE_ANALOG_MAX:
share_mode |= NETPLAY_SHARE_ANALOG_MAX; share_mode |= NETPLAY_SHARE_ANALOG_MAX;

View File

@ -202,6 +202,7 @@ bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection) struct netplay_connection *connection)
{ {
uint32_t header[6]; uint32_t header[6];
unsigned conn_salt = 0;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
header[0] = htonl(netplay_magic); header[0] = htonl(netplay_magic);
@ -221,13 +222,11 @@ bool netplay_handshake_init_send(netplay_t *netplay,
connection->salt = simple_rand_uint32(); connection->salt = simple_rand_uint32();
if (connection->salt == 0) if (connection->salt == 0)
connection->salt = 1; connection->salt = 1;
header[3] = htonl(connection->salt); conn_salt = connection->salt;
}
else
{
header[3] = htonl(0);
} }
header[3] = htonl(conn_salt);
if (!netplay_send(&connection->send_packet_buffer, connection->fd, header, if (!netplay_send(&connection->send_packet_buffer, connection->fd, header,
sizeof(header)) || sizeof(header)) ||
!netplay_send_flush(&connection->send_packet_buffer, connection->fd, false)) !netplay_send_flush(&connection->send_packet_buffer, connection->fd, false))
@ -273,7 +272,7 @@ static void handshake_password(void *ignore, const char *line)
struct password_buf_s password_buf; struct password_buf_s password_buf;
char password[8+NETPLAY_PASS_LEN]; /* 8 for salt, 128 for password */ char password[8+NETPLAY_PASS_LEN]; /* 8 for salt, 128 for password */
char hash[NETPLAY_PASS_HASH_LEN+1]; /* + NULL terminator */ char hash[NETPLAY_PASS_HASH_LEN+1]; /* + NULL terminator */
netplay_t *netplay = handshake_password_netplay; netplay_t *netplay = handshake_password_netplay;
struct netplay_connection *connection = &netplay->connections[0]; struct netplay_connection *connection = &netplay->connections[0];
snprintf(password, sizeof(password), "%08X", connection->salt); snprintf(password, sizeof(password), "%08X", connection->salt);
@ -738,7 +737,6 @@ bool netplay_handshake_pre_nick(netplay_t *netplay,
return false; return false;
connection->mode = NETPLAY_CONNECTION_PRE_INFO; connection->mode = NETPLAY_CONNECTION_PRE_INFO;
} }
} }
/* Client needs to wait for INFO */ /* Client needs to wait for INFO */
else else
@ -800,7 +798,7 @@ bool netplay_handshake_pre_password(netplay_t *netplay,
if (!memcmp(password_buf.password, hash, NETPLAY_PASS_HASH_LEN)) if (!memcmp(password_buf.password, hash, NETPLAY_PASS_HASH_LEN))
{ {
correct = true; correct = true;
connection->can_play = true; connection->can_play = true;
} }
} }
@ -920,7 +918,6 @@ bool netplay_handshake_pre_info(netplay_t *netplay,
{ {
if (!netplay_handshake_sync(netplay, connection)) if (!netplay_handshake_sync(netplay, connection))
return false; return false;
} }
else else
{ {
@ -952,7 +949,6 @@ bool netplay_handshake_pre_sync(netplay_t *netplay,
retro_ctx_controller_info_t pad; retro_ctx_controller_info_t pad;
char new_nick[NETPLAY_NICK_LEN]; char new_nick[NETPLAY_NICK_LEN];
retro_ctx_memory_info_t mem_info; retro_ctx_memory_info_t mem_info;
settings_t *settings = config_get_ptr();
RECV(cmd, sizeof(cmd)) RECV(cmd, sizeof(cmd))
{ {
@ -1134,8 +1130,11 @@ 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 (!settings->bools.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; return true;
} }

View File

@ -487,9 +487,8 @@ bool netplay_cmd_mode(netplay_t *netplay,
enum rarch_netplay_connection_mode mode) enum rarch_netplay_connection_mode mode)
{ {
uint32_t cmd, device; uint32_t cmd, device;
uint32_t payloadBuf = 0, *payload = NULL; uint32_t payload_buf = 0, *payload = NULL;
uint8_t share_mode; uint8_t share_mode = 0;
settings_t *settings = config_get_ptr();
struct netplay_connection *connection = NULL; struct netplay_connection *connection = NULL;
if (!netplay->is_server) if (!netplay->is_server)
@ -502,25 +501,31 @@ bool netplay_cmd_mode(netplay_t *netplay,
break; break;
case NETPLAY_CONNECTION_SLAVE: case NETPLAY_CONNECTION_SLAVE:
payloadBuf = NETPLAY_CMD_PLAY_BIT_SLAVE; payload_buf = NETPLAY_CMD_PLAY_BIT_SLAVE;
/* no break */ /* no break */
case NETPLAY_CONNECTION_PLAYING: case NETPLAY_CONNECTION_PLAYING:
payload = &payloadBuf;
/* Add a share mode if requested */
share_mode = netplay_settings_share_mode();
payloadBuf |= ((uint32_t) share_mode) << 16;
/* Request devices */
for (device = 0; device < MAX_INPUT_DEVICES; device++)
{ {
if (settings->bools.netplay_request_devices[device]) settings_t *settings = config_get_ptr();
payloadBuf |= 1<<device; payload = &payload_buf;
}
payloadBuf = htonl(payloadBuf); /* Add a share mode if requested */
cmd = NETPLAY_CMD_PLAY; share_mode = netplay_settings_share_mode(
settings->uints.netplay_share_digital,
settings->uints.netplay_share_analog
);
payload_buf |= ((uint32_t) share_mode) << 16;
/* Request devices */
for (device = 0; device < MAX_INPUT_DEVICES; device++)
{
if (settings->bools.netplay_request_devices[device])
payload_buf |= 1<<device;
}
payload_buf = htonl(payload_buf);
cmd = NETPLAY_CMD_PLAY;
}
break; break;
default: default:

View File

@ -716,7 +716,7 @@ void netplay_load_savestate(netplay_t *netplay,
* *
* Get the preferred share mode * Get the preferred share mode
*/ */
uint8_t netplay_settings_share_mode(void); uint8_t netplay_settings_share_mode(unsigned share_digital, unsigned share_analog);
/** /**
* input_poll_net * input_poll_net

View File

@ -109,12 +109,10 @@ static JSON_Parser_HandlerResult JSON_CALL StringHandler(
{ {
if (pCtx->cur_field) if (pCtx->cur_field)
{ {
/* CRC comes in as a string but it is stored
* as an unsigned casted to int. */
if (string_is_equal(pCtx->cur_field, "game_crc")) if (string_is_equal(pCtx->cur_field, "game_crc"))
{
/* CRC comes in as a string but it is stored
* as an unsigned casted to int. */
*((int*)pCtx->cur_member) = (int)strtoul(pValue, NULL, 16); *((int*)pCtx->cur_member) = (int)strtoul(pValue, NULL, 16);
}
else else
strlcpy((char*)pCtx->cur_member, pValue, PATH_MAX_LENGTH); strlcpy((char*)pCtx->cur_member, pValue, PATH_MAX_LENGTH);
} }