diff --git a/Makefile.common b/Makefile.common index 966532b100..2851353841 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1122,11 +1122,12 @@ ifeq ($(HAVE_NETWORKING), 1) # Netplay DEFINES += -DHAVE_NETWORK_CMD - OBJ += network/netplay/netplay_frontend.o \ + 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 \ network/netplay/netplay_sync.o \ - network/netplay/netplay_common.o \ network/netplay/netplay_discovery.o \ network/netplay/netplay_buf.o diff --git a/griffin/griffin.c b/griffin/griffin.c index e9f4a45bd5..bd80e87312 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -881,12 +881,14 @@ THREAD NETPLAY ============================================================ */ #ifdef HAVE_NETWORKING +#include "../network/netplay/netplay_delta.c" #include "../network/netplay/netplay_frontend.c" +#include "../network/netplay/netplay_handshake.c" #include "../network/netplay/netplay_init.c" #include "../network/netplay/netplay_io.c" #include "../network/netplay/netplay_sync.c" -#include "../network/netplay/netplay_common.c" #include "../network/netplay/netplay_discovery.c" +#include "../network/netplay/netplay_buf.c" #include "../libretro-common/net/net_compat.c" #include "../libretro-common/net/net_socket.c" #include "../libretro-common/net/net_http.c" diff --git a/network/netplay/netplay_delta.c b/network/netplay/netplay_delta.c new file mode 100644 index 0000000000..b5c49760e8 --- /dev/null +++ b/network/netplay/netplay_delta.c @@ -0,0 +1,51 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2016 - Gregor Richards + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#include +#include + +#include "netplay_private.h" + +bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta, uint32_t frame) +{ + void *remember_state; + if (delta->used) + { + if (delta->frame == frame) return true; + if (netplay->other_frame_count <= delta->frame) + { + /* We haven't even replayed this frame yet, so we can't overwrite it! */ + return false; + } + } + remember_state = delta->state; + memset(delta, 0, sizeof(struct delta_frame)); + delta->used = true; + delta->frame = frame; + delta->state = remember_state; + return true; +} + +uint32_t netplay_delta_frame_crc(netplay_t *netplay, struct delta_frame *delta) +{ + if (!netplay->state_size) + return 0; + return encoding_crc32(0L, (const unsigned char*)delta->state, netplay->state_size); +} diff --git a/network/netplay/netplay_common.c b/network/netplay/netplay_handshake.c similarity index 88% rename from network/netplay/netplay_common.c rename to network/netplay/netplay_handshake.c index 715f04f6bc..0f4ac0e374 100644 --- a/network/netplay/netplay_common.c +++ b/network/netplay/netplay_handshake.c @@ -15,17 +15,16 @@ * If not, see . */ +#include +#include +#include + +#include #include +#include #include "netplay_private.h" -#include -#include -#include -#include - -#include "../../movie.h" -#include "../../msg_hash.h" #include "../../configuration.h" #include "../../content.h" #include "../../retroarch.h" @@ -33,6 +32,96 @@ #include "../../version.h" #include "../../menu/widgets/menu_input_dialog.h" +#ifndef HAVE_SOCKET_LEGACY +/* Custom inet_ntop. Win32 doesn't seem to support this ... */ +void netplay_log_connection(const struct sockaddr_storage *their_addr, + unsigned slot, const char *nick) +{ + union + { + const struct sockaddr_storage *storage; + const struct sockaddr_in *v4; + const struct sockaddr_in6 *v6; + } u; + const char *str = NULL; + char buf_v4[INET_ADDRSTRLEN] = {0}; + char buf_v6[INET6_ADDRSTRLEN] = {0}; + char msg[512]; + + msg[0] = '\0'; + + u.storage = their_addr; + + switch (their_addr->ss_family) + { + case AF_INET: + { + struct sockaddr_in in; + + memset(&in, 0, sizeof(in)); + + str = buf_v4; + in.sin_family = AF_INET; + memcpy(&in.sin_addr, &u.v4->sin_addr, sizeof(struct in_addr)); + + getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in), + buf_v4, sizeof(buf_v4), + NULL, 0, NI_NUMERICHOST); + } + break; + case AF_INET6: + { + struct sockaddr_in6 in; + memset(&in, 0, sizeof(in)); + + str = buf_v6; + in.sin6_family = AF_INET6; + memcpy(&in.sin6_addr, &u.v6->sin6_addr, sizeof(struct in6_addr)); + + getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in6), + buf_v6, sizeof(buf_v6), NULL, 0, NI_NUMERICHOST); + } + break; + default: + break; + } + + if (str) + { + snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM_NAME), + nick, str); + runloop_msg_queue_push(msg, 1, 180, false); + RARCH_LOG("%s\n", msg); + } + else + { + snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM), + nick); + runloop_msg_queue_push(msg, 1, 180, false); + RARCH_LOG("%s\n", msg); + } + RARCH_LOG("%s %u\n", msg_hash_to_str(MSG_CONNECTION_SLOT), + slot); +} + +#else +void netplay_log_connection(const struct sockaddr_storage *their_addr, + unsigned slot, const char *nick) +{ + char msg[512]; + + msg[0] = '\0'; + + snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM), + nick); + runloop_msg_queue_push(msg, 1, 180, false); + RARCH_LOG("%s\n", msg); + RARCH_LOG("%s %u\n", + msg_hash_to_str(MSG_CONNECTION_SLOT), slot); +} + +#endif + /** * netplay_impl_magic: * @@ -649,37 +738,3 @@ bool netplay_handshake_pre_sync(netplay_t *netplay, struct netplay_connection *c /* Ask to go to player mode */ return netplay_cmd_mode(netplay, connection, NETPLAY_CONNECTION_PLAYING); } - -bool netplay_is_server(netplay_t* netplay) -{ - if (!netplay) - return false; - return netplay->is_server; -} - -bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta, uint32_t frame) -{ - void *remember_state; - if (delta->used) - { - if (delta->frame == frame) return true; - if (netplay->other_frame_count <= delta->frame) - { - /* We haven't even replayed this frame yet, so we can't overwrite it! */ - return false; - } - } - remember_state = delta->state; - memset(delta, 0, sizeof(struct delta_frame)); - delta->used = true; - delta->frame = frame; - delta->state = remember_state; - return true; -} - -uint32_t netplay_delta_frame_crc(netplay_t *netplay, struct delta_frame *delta) -{ - if (!netplay->state_size) - return 0; - return encoding_crc32(0L, (const unsigned char*)delta->state, netplay->state_size); -} diff --git a/network/netplay/netplay_init.c b/network/netplay/netplay_init.c index 33ca0d65da..665dae8f61 100644 --- a/network/netplay/netplay_init.c +++ b/network/netplay/netplay_init.c @@ -228,96 +228,6 @@ static bool init_socket(netplay_t *netplay, void *direct_host, const char *serve return true; } -#ifndef HAVE_SOCKET_LEGACY -/* Custom inet_ntop. Win32 doesn't seem to support this ... */ -void netplay_log_connection(const struct sockaddr_storage *their_addr, - unsigned slot, const char *nick) -{ - union - { - const struct sockaddr_storage *storage; - const struct sockaddr_in *v4; - const struct sockaddr_in6 *v6; - } u; - const char *str = NULL; - char buf_v4[INET_ADDRSTRLEN] = {0}; - char buf_v6[INET6_ADDRSTRLEN] = {0}; - char msg[512]; - - msg[0] = '\0'; - - u.storage = their_addr; - - switch (their_addr->ss_family) - { - case AF_INET: - { - struct sockaddr_in in; - - memset(&in, 0, sizeof(in)); - - str = buf_v4; - in.sin_family = AF_INET; - memcpy(&in.sin_addr, &u.v4->sin_addr, sizeof(struct in_addr)); - - getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in), - buf_v4, sizeof(buf_v4), - NULL, 0, NI_NUMERICHOST); - } - break; - case AF_INET6: - { - struct sockaddr_in6 in; - memset(&in, 0, sizeof(in)); - - str = buf_v6; - in.sin6_family = AF_INET6; - memcpy(&in.sin6_addr, &u.v6->sin6_addr, sizeof(struct in6_addr)); - - getnameinfo((struct sockaddr*)&in, sizeof(struct sockaddr_in6), - buf_v6, sizeof(buf_v6), NULL, 0, NI_NUMERICHOST); - } - break; - default: - break; - } - - if (str) - { - snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM_NAME), - nick, str); - runloop_msg_queue_push(msg, 1, 180, false); - RARCH_LOG("%s\n", msg); - } - else - { - snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM), - nick); - runloop_msg_queue_push(msg, 1, 180, false); - RARCH_LOG("%s\n", msg); - } - RARCH_LOG("%s %u\n", msg_hash_to_str(MSG_CONNECTION_SLOT), - slot); -} - -#else -void netplay_log_connection(const struct sockaddr_storage *their_addr, - unsigned slot, const char *nick) -{ - char msg[512]; - - msg[0] = '\0'; - - snprintf(msg, sizeof(msg), msg_hash_to_str(MSG_GOT_CONNECTION_FROM), - nick); - runloop_msg_queue_push(msg, 1, 180, false); - RARCH_LOG("%s\n", msg); - RARCH_LOG("%s %u\n", - msg_hash_to_str(MSG_CONNECTION_SLOT), slot); -} - -#endif - static bool netplay_init_socket_buffers(netplay_t *netplay) { /* Make our packet buffer big enough for a save state and frames-many frames diff --git a/network/netplay/netplay_sync.c b/network/netplay/netplay_sync.c index e2992473c3..7635074ca7 100644 --- a/network/netplay/netplay_sync.c +++ b/network/netplay/netplay_sync.c @@ -131,7 +131,7 @@ void netplay_simulate_input(netplay_t *netplay, size_t sim_ptr, bool resim) static void netplay_handle_frame_hash(netplay_t *netplay, struct delta_frame *delta) { static bool crcs_valid = true; - if (netplay_is_server(netplay)) + if (netplay->is_server) { if (netplay->check_frames && (delta->frame % netplay->check_frames == 0 || delta->frame == 1))