diff --git a/netplay.c b/netplay.c index 8f436afb5a..29e2b58a20 100644 --- a/netplay.c +++ b/netplay.c @@ -25,6 +25,7 @@ #include "general.h" #include "autosave.h" #include "dynamic.h" +#include "intl/intl.h" struct delta_frame { @@ -1625,6 +1626,62 @@ void netplay_post_frame(netplay_t *netplay) netplay_post_frame_net(netplay); } +#define RARCH_DEFAULT_PORT 55435 + +/** + * init_netplay: + * + * Initializes netplay. + * + * If netplay is already initialized, will return false (0). + * + * Returns: true (1) if successful, otherwise false (0). + **/ + +bool init_netplay(void) +{ + struct retro_callbacks cbs = {0}; + driver_t *driver = driver_get_ptr(); + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + + if (!global->netplay_enable) + return false; + + if (global->bsv.movie_start_playback) + { + RARCH_WARN(RETRO_LOG_MOVIE_STARTED_INIT_NETPLAY_FAILED); + return false; + } + + retro_set_default_callbacks(&cbs); + + if (*global->netplay_server) + { + RARCH_LOG("Connecting to netplay host...\n"); + global->netplay_is_client = true; + } + else + RARCH_LOG("Waiting for client...\n"); + + driver->netplay_data = (netplay_t*)netplay_new( + global->netplay_is_client ? global->netplay_server : NULL, + global->netplay_port ? global->netplay_port : RARCH_DEFAULT_PORT, + global->netplay_sync_frames, &cbs, global->netplay_is_spectate, + settings->username); + + if (driver->netplay_data) + return true; + + global->netplay_is_client = false; + RARCH_WARN(RETRO_LOG_INIT_NETPLAY_FAILED); + + rarch_main_msg_queue_push( + RETRO_MSG_INIT_NETPLAY_FAILED, + 0, 180, false); + return false; +} + #ifdef HAVE_SOCKET_LEGACY #undef sockaddr_storage diff --git a/netplay.h b/netplay.h index 38df9f5f45..7da811059e 100644 --- a/netplay.h +++ b/netplay.h @@ -98,5 +98,16 @@ void netplay_pre_frame(netplay_t *handle); **/ void netplay_post_frame(netplay_t *handle); +/** + * init_netplay: + * + * Initializes netplay. + * + * If netplay is already initialized, will return false (0). + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool init_netplay(void); + #endif diff --git a/retroarch.c b/retroarch.c index 71ddcd819c..e2590c167e 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1006,64 +1006,6 @@ static void init_movie(void) } } -#define RARCH_DEFAULT_PORT 55435 - -#ifdef HAVE_NETPLAY -/** - * init_netplay: - * - * Initializes netplay. - * - * If netplay is already initialized, will return false (0). - * - * Returns: true (1) if successful, otherwise false (0). - **/ - -static bool init_netplay(void) -{ - struct retro_callbacks cbs = {0}; - driver_t *driver = driver_get_ptr(); - settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); - - if (!global->netplay_enable) - return false; - - if (global->bsv.movie_start_playback) - { - RARCH_WARN(RETRO_LOG_MOVIE_STARTED_INIT_NETPLAY_FAILED); - return false; - } - - retro_set_default_callbacks(&cbs); - - if (*global->netplay_server) - { - RARCH_LOG("Connecting to netplay host...\n"); - global->netplay_is_client = true; - } - else - RARCH_LOG("Waiting for client...\n"); - - driver->netplay_data = (netplay_t*)netplay_new( - global->netplay_is_client ? global->netplay_server : NULL, - global->netplay_port ? global->netplay_port : RARCH_DEFAULT_PORT, - global->netplay_sync_frames, &cbs, global->netplay_is_spectate, - settings->username); - - if (driver->netplay_data) - return true; - - global->netplay_is_client = false; - RARCH_WARN(RETRO_LOG_INIT_NETPLAY_FAILED); - - rarch_main_msg_queue_push( - RETRO_MSG_INIT_NETPLAY_FAILED, - 0, 180, false); - return false; -} -#endif - #ifdef HAVE_COMMAND static void init_command(void) {