mirror of
https://github.com/libretro/RetroArch
synced 2025-04-18 05:43:34 +00:00
(Netplay) Refactor fork arguments (#14208)
This commit is contained in:
parent
83a7c0d798
commit
cc7c310aa1
@ -36,6 +36,10 @@
|
|||||||
|
|
||||||
#include "../natt.h"
|
#include "../natt.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_DYNAMIC
|
||||||
|
#define NETPLAY_FORK_MAX_ARGS 64
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NETPLAY_NICK_LEN 32
|
#define NETPLAY_NICK_LEN 32
|
||||||
#define NETPLAY_HOST_STR_LEN 32
|
#define NETPLAY_HOST_STR_LEN 32
|
||||||
#define NETPLAY_HOST_LONGSTR_LEN 256
|
#define NETPLAY_HOST_LONGSTR_LEN 256
|
||||||
@ -59,8 +63,8 @@ enum rarch_netplay_ctl_state
|
|||||||
RARCH_NETPLAY_CTL_ENABLE_CLIENT,
|
RARCH_NETPLAY_CTL_ENABLE_CLIENT,
|
||||||
RARCH_NETPLAY_CTL_DISABLE,
|
RARCH_NETPLAY_CTL_DISABLE,
|
||||||
#ifndef HAVE_DYNAMIC
|
#ifndef HAVE_DYNAMIC
|
||||||
|
RARCH_NETPLAY_CTL_ADD_FORK_ARG,
|
||||||
RARCH_NETPLAY_CTL_GET_FORK_ARGS,
|
RARCH_NETPLAY_CTL_GET_FORK_ARGS,
|
||||||
RARCH_NETPLAY_CTL_SET_FORK_ARGS,
|
|
||||||
RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS,
|
RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS,
|
||||||
#endif
|
#endif
|
||||||
RARCH_NETPLAY_CTL_REFRESH_CLIENT_INFO,
|
RARCH_NETPLAY_CTL_REFRESH_CLIENT_INFO,
|
||||||
@ -162,6 +166,14 @@ typedef struct mitm_server
|
|||||||
enum msg_hash_enums description;
|
enum msg_hash_enums description;
|
||||||
} mitm_server_t;
|
} mitm_server_t;
|
||||||
|
|
||||||
|
#ifndef HAVE_DYNAMIC
|
||||||
|
struct netplay_fork_args
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
char args[PATH_MAX_LENGTH];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct netplay_room
|
struct netplay_room
|
||||||
{
|
{
|
||||||
struct netplay_room *next;
|
struct netplay_room *next;
|
||||||
@ -230,6 +242,9 @@ struct netplay_chat_buffer
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
#ifndef HAVE_DYNAMIC
|
||||||
|
struct netplay_fork_args fork_args;
|
||||||
|
#endif
|
||||||
/* NAT traversal info (if NAT traversal is used and serving) */
|
/* NAT traversal info (if NAT traversal is used and serving) */
|
||||||
struct nat_traversal_data nat_traversal_request;
|
struct nat_traversal_data nat_traversal_request;
|
||||||
#ifdef HAVE_NETPLAYDISCOVERY
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
@ -254,9 +269,6 @@ typedef struct
|
|||||||
unsigned server_port_deferred;
|
unsigned server_port_deferred;
|
||||||
char server_address_deferred[256];
|
char server_address_deferred[256];
|
||||||
char server_session_deferred[32];
|
char server_session_deferred[32];
|
||||||
#ifndef HAVE_DYNAMIC
|
|
||||||
char netplay_fork_args[PATH_MAX_LENGTH];
|
|
||||||
#endif
|
|
||||||
bool netplay_client_deferred;
|
bool netplay_client_deferred;
|
||||||
/* Only used before init_netplay */
|
/* Only used before init_netplay */
|
||||||
bool netplay_enabled;
|
bool netplay_enabled;
|
||||||
|
@ -8988,24 +8988,49 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
#ifndef HAVE_DYNAMIC
|
#ifndef HAVE_DYNAMIC
|
||||||
case RARCH_NETPLAY_CTL_GET_FORK_ARGS:
|
case RARCH_NETPLAY_CTL_ADD_FORK_ARG:
|
||||||
if (data && !string_is_empty(net_st->netplay_fork_args))
|
if (data && net_st->fork_args.size < sizeof(net_st->fork_args.args))
|
||||||
strlcpy((char*)data, net_st->netplay_fork_args,
|
{
|
||||||
sizeof(net_st->netplay_fork_args));
|
size_t new_size = strlcpy(
|
||||||
|
net_st->fork_args.args + net_st->fork_args.size,
|
||||||
|
(const char*)data,
|
||||||
|
sizeof(net_st->fork_args.args) - net_st->fork_args.size);
|
||||||
|
new_size += 1; /* NULL terminator */
|
||||||
|
new_size += net_st->fork_args.size;
|
||||||
|
if (new_size > sizeof(net_st->fork_args.args))
|
||||||
|
{
|
||||||
|
ret = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
net_st->fork_args.size = new_size;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_SET_FORK_ARGS:
|
case RARCH_NETPLAY_CTL_GET_FORK_ARGS:
|
||||||
if (data)
|
if (data && net_st->fork_args.size)
|
||||||
strlcpy(net_st->netplay_fork_args, (const char*)data,
|
{
|
||||||
sizeof(net_st->netplay_fork_args));
|
size_t offset = 0;
|
||||||
|
char *args = net_st->fork_args.args;
|
||||||
|
size_t args_sz = net_st->fork_args.size;
|
||||||
|
char **args_cur = (char**)data;
|
||||||
|
char **args_end = &args_cur[NETPLAY_FORK_MAX_ARGS - 1];
|
||||||
|
for (; offset < args_sz && args_cur != args_end; args_cur++)
|
||||||
|
{
|
||||||
|
*args_cur = args + offset;
|
||||||
|
offset += strlen(*args_cur) + 1;
|
||||||
|
}
|
||||||
|
/* Ensure that the final entry is NULL. */
|
||||||
|
*args_cur = NULL;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ret = false;
|
ret = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS:
|
case RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS:
|
||||||
*net_st->netplay_fork_args = '\0';
|
net_st->fork_args.size = 0;
|
||||||
|
*net_st->fork_args.args = '\0';
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -451,31 +451,29 @@ finished:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_DYNAMIC
|
#ifndef HAVE_DYNAMIC
|
||||||
static void static_load(const char *core, const char *subsystem,
|
static bool static_load(const char *core, const char *subsystem,
|
||||||
const void *content, const char *hostname)
|
const void *content, const char *hostname)
|
||||||
{
|
{
|
||||||
char buf[512];
|
#define ARG(arg) (void*)(arg)
|
||||||
char args[PATH_MAX_LENGTH];
|
|
||||||
|
|
||||||
path_set(RARCH_PATH_CORE, core);
|
|
||||||
|
|
||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS, NULL);
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS, NULL);
|
||||||
|
|
||||||
if (string_is_empty(hostname))
|
if (string_is_empty(hostname))
|
||||||
{
|
{
|
||||||
strlcpy(args, "-H", sizeof(args));
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG("-H")))
|
||||||
|
goto failure;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strlcpy(args, "-C ", sizeof(args));
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG("-C")) ||
|
||||||
strlcat(args, hostname, sizeof(args));
|
!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG(hostname)))
|
||||||
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string_is_empty(subsystem))
|
if (!string_is_empty(subsystem))
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "\"%s\"", subsystem);
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG("--subsystem")) ||
|
||||||
strlcat(args, " --subsystem ", sizeof(args));
|
!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG(subsystem)))
|
||||||
strlcat(args, buf, sizeof(args));
|
goto failure;
|
||||||
|
|
||||||
if (content)
|
if (content)
|
||||||
{
|
{
|
||||||
@ -485,21 +483,35 @@ static void static_load(const char *core, const char *subsystem,
|
|||||||
|
|
||||||
for (i = 0; i < subsystem_content->size; i++)
|
for (i = 0; i < subsystem_content->size; i++)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), " \"%s\"",
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG,
|
||||||
subsystem_content->elems[i].data);
|
ARG(subsystem_content->elems[i].data)))
|
||||||
strlcat(args, buf, sizeof(args));
|
goto failure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (content)
|
else if (content)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), " \"%s\"", (const char*)content);
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_ADD_FORK_ARG, ARG(content)))
|
||||||
strlcat(args, buf, sizeof(args));
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_SET_FORK_ARGS, args);
|
if (!frontend_driver_set_fork(FRONTEND_FORK_CORE_WITH_ARGS))
|
||||||
frontend_driver_set_fork(FRONTEND_FORK_CORE_WITH_ARGS);
|
goto failure;
|
||||||
|
|
||||||
|
path_set(RARCH_PATH_CORE, core);
|
||||||
|
|
||||||
retroarch_ctl(RARCH_CTL_SET_SHUTDOWN, NULL);
|
retroarch_ctl(RARCH_CTL_SET_SHUTDOWN, NULL);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
failure:
|
||||||
|
RARCH_ERR("[Lobby] Failed to fork RetroArch for netplay.\n");
|
||||||
|
|
||||||
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_CLEAR_FORK_ARGS, NULL);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
#undef ARG
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -677,10 +689,9 @@ static void task_netplay_crc_scan_callback(retro_task_t *task,
|
|||||||
content_set_subsystem_by_name(data->current.subsystem);
|
content_set_subsystem_by_name(data->current.subsystem);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static_load(data->core, data->current.subsystem, NULL,
|
if (static_load(data->core, data->current.subsystem, NULL,
|
||||||
data->hostname);
|
data->hostname))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
runloop_msg_queue_push(
|
runloop_msg_queue_push(
|
||||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_START_WHEN_LOADED),
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_START_WHEN_LOADED),
|
||||||
1, 480, true, NULL,
|
1, 480, true, NULL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user