Better error messages when the Netplay handshake fails

This commit is contained in:
Gregor Richards 2016-12-03 09:46:20 -05:00
parent 0c74d19112
commit 98f0d4d45b

View File

@ -170,7 +170,7 @@ bool netplay_handshake(netplay_t *netplay)
bool is_server = netplay->is_server; bool is_server = netplay->is_server;
int compression = 0; int compression = 0;
msg[0] = '\0'; msg[0] = msg[sizeof(msg)-1] = '\0';
mem_info.id = RETRO_MEMORY_SAVE_RAM; mem_info.id = RETRO_MEMORY_SAVE_RAM;
@ -190,22 +190,21 @@ bool netplay_handshake(netplay_t *netplay)
if (!socket_receive_all_blocking(netplay->fd, header, sizeof(header))) if (!socket_receive_all_blocking(netplay->fd, header, sizeof(header)))
{ {
RARCH_ERR("%s\n", strncpy(msg, msg_hash_to_str(MSG_FAILED_TO_RECEIVE_HEADER_FROM_CLIENT), sizeof(msg)-1);
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_HEADER_FROM_CLIENT)); goto error;
return false;
} }
if (*content_crc_ptr != ntohl(header[0])) if (*content_crc_ptr != ntohl(header[0]))
{ {
RARCH_ERR("%s\n", msg_hash_to_str(MSG_CONTENT_CRC32S_DIFFER)); strncpy(msg, msg_hash_to_str(MSG_CONTENT_CRC32S_DIFFER), sizeof(msg)-1);
return false; goto error;
} }
if (netplay_impl_magic() != ntohl(header[1])) if (netplay_impl_magic() != ntohl(header[1]))
{ {
RARCH_ERR("Implementations differ, make sure you're using exact same " strncpy(msg, "Implementations differ. Make sure you're using exact same "
"libretro implementations and RetroArch version.\n"); "libretro implementations and RetroArch version.", sizeof(msg)-1);
return false; goto error;
} }
/* Some cores only report the correct sram size late, so we can't actually /* Some cores only report the correct sram size late, so we can't actually
@ -223,13 +222,17 @@ bool netplay_handshake(netplay_t *netplay)
netplay_endian_mismatch(local_pmagic, remote_pmagic)) netplay_endian_mismatch(local_pmagic, remote_pmagic))
{ {
RARCH_ERR("Endianness mismatch with an endian-sensitive core.\n"); RARCH_ERR("Endianness mismatch with an endian-sensitive core.\n");
return false; strncpy(msg, "This core does not support inter-architecture netplay "
"between these systems.", sizeof(msg)-1);
goto error;
} }
if ((netplay->quirks & NETPLAY_QUIRK_PLATFORM_DEPENDENT) && if ((netplay->quirks & NETPLAY_QUIRK_PLATFORM_DEPENDENT) &&
(local_pmagic != remote_pmagic)) (local_pmagic != remote_pmagic))
{ {
RARCH_ERR("Platform mismatch with a platform-sensitive core.\n"); RARCH_ERR("Platform mismatch with a platform-sensitive core.\n");
return false; strncpy(msg, "This core does not support inter-architecture netplay.",
sizeof(msg)-1);
goto error;
} }
/* Clear any existing compression */ /* Clear any existing compression */
@ -267,21 +270,22 @@ bool netplay_handshake(netplay_t *netplay)
{ {
if (!netplay_send_nickname(netplay, netplay->fd)) if (!netplay_send_nickname(netplay, netplay->fd))
{ {
RARCH_ERR("%s\n", strncpy(msg, msg_hash_to_str(MSG_FAILED_TO_SEND_NICKNAME_TO_HOST),
msg_hash_to_str(MSG_FAILED_TO_SEND_NICKNAME_TO_HOST)); sizeof(msg)-1);
return false; goto error;
} }
} }
if (!netplay_get_nickname(netplay, netplay->fd)) if (!netplay_get_nickname(netplay, netplay->fd))
{ {
if (is_server) if (is_server)
RARCH_ERR("%s\n", strncpy(msg, msg_hash_to_str(MSG_FAILED_TO_GET_NICKNAME_FROM_CLIENT),
msg_hash_to_str(MSG_FAILED_TO_GET_NICKNAME_FROM_CLIENT)); sizeof(msg)-1);
else else
RARCH_ERR("%s\n", strncpy(msg,
msg_hash_to_str(MSG_FAILED_TO_RECEIVE_NICKNAME_FROM_HOST)); msg_hash_to_str(MSG_FAILED_TO_RECEIVE_NICKNAME_FROM_HOST),
return false; sizeof(msg)-1);
goto error;
} }
if (is_server) if (is_server)
@ -378,6 +382,14 @@ bool netplay_handshake(netplay_t *netplay)
} }
return true; return true;
error:
if (msg[0])
{
RARCH_ERR("%s\n", msg);
runloop_msg_queue_push(msg, 1, 180, false);
}
return false;
} }
bool netplay_is_server(netplay_t* netplay) bool netplay_is_server(netplay_t* netplay)