From 4a83e6dee9ae94cd28d22ada9da2241587e53a39 Mon Sep 17 00:00:00 2001 From: Gregor Richards Date: Thu, 22 Sep 2016 07:06:26 -0400 Subject: [PATCH] Both sides should send the same header so either can check the other --- network/netplay/netplay_common.c | 44 +++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/network/netplay/netplay_common.c b/network/netplay/netplay_common.c index 73d8ea52c3..7384771b79 100644 --- a/network/netplay/netplay_common.c +++ b/network/netplay/netplay_common.c @@ -144,6 +144,32 @@ bool netplay_send_info(netplay_t *netplay) if (!socket_send_all_blocking(netplay->fd, header, sizeof(header), false)) return false; + if (!socket_receive_all_blocking(netplay->fd, header, sizeof(header))) + { + RARCH_ERR("%s\n", + msg_hash_to_str(MSG_FAILED_TO_RECEIVE_HEADER_FROM_CLIENT)); + return false; + } + + if (*content_crc_ptr != ntohl(header[0])) + { + RARCH_ERR("%s\n", msg_hash_to_str(MSG_CONTENT_CRC32S_DIFFER)); + return false; + } + + if (netplay_impl_magic() != ntohl(header[1])) + { + RARCH_ERR("Implementations differ, make sure you're using exact same " + "libretro implementations and RetroArch version.\n"); + return false; + } + + if (mem_info.size != ntohl(header[2])) + { + RARCH_ERR("Content SRAM sizes do not correspond.\n"); + return false; + } + if (!netplay_send_nickname(netplay, netplay->fd)) { RARCH_ERR("%s\n", @@ -187,6 +213,18 @@ bool netplay_get_info(netplay_t *netplay) const void *sram = NULL; size_t i; + mem_info.id = RETRO_MEMORY_SAVE_RAM; + + core_get_memory(&mem_info); + content_get_crc(&content_crc_ptr); + + header[0] = htonl(*content_crc_ptr); + header[1] = htonl(netplay_impl_magic()); + header[2] = htonl(mem_info.size); + + if (!socket_send_all_blocking(netplay->fd, header, sizeof(header), false)) + return false; + if (!socket_receive_all_blocking(netplay->fd, header, sizeof(header))) { RARCH_ERR("%s\n", @@ -194,8 +232,6 @@ bool netplay_get_info(netplay_t *netplay) return false; } - content_get_crc(&content_crc_ptr); - if (*content_crc_ptr != ntohl(header[0])) { RARCH_ERR("%s\n", msg_hash_to_str(MSG_CONTENT_CRC32S_DIFFER)); @@ -209,10 +245,6 @@ bool netplay_get_info(netplay_t *netplay) return false; } - mem_info.id = RETRO_MEMORY_SAVE_RAM; - - core_get_memory(&mem_info); - if (mem_info.size != ntohl(header[2])) { RARCH_ERR("Content SRAM sizes do not correspond.\n");