Move stray globals to networking state
This commit is contained in:
parent
f264d20d1e
commit
96053e14a7
|
@ -82,9 +82,6 @@
|
||||||
|
|
||||||
#ifdef HAVE_NETWORKING
|
#ifdef HAVE_NETWORKING
|
||||||
#include "../../network/netplay/netplay.h"
|
#include "../../network/netplay/netplay.h"
|
||||||
/* TODO/FIXME - we can't ifdef netplay_discovery.h because of these pesky globals 'netplay_room_count' and 'netplay_room_list' - let's please get rid of them */
|
|
||||||
#include "../../network/netplay/netplay_discovery.h"
|
|
||||||
|
|
||||||
#include "../../wifi/wifi_driver.h"
|
#include "../../wifi/wifi_driver.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -5703,43 +5700,44 @@ static int action_ok_netplay_connect_room(const char *path,
|
||||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||||
{
|
{
|
||||||
char tmp_hostname[4115];
|
char tmp_hostname[4115];
|
||||||
unsigned room_index = type - MENU_SETTINGS_NETPLAY_ROOMS_START;
|
net_driver_state_t *net_st = networking_state_get_ptr();
|
||||||
|
unsigned room_index = type - MENU_SETTINGS_NETPLAY_ROOMS_START;
|
||||||
|
|
||||||
tmp_hostname[0] = '\0';
|
if (room_index >= (unsigned)net_st->room_count)
|
||||||
|
|
||||||
if (room_index >= (unsigned)netplay_room_count)
|
|
||||||
return menu_cbs_exit();
|
return menu_cbs_exit();
|
||||||
|
|
||||||
|
tmp_hostname[0] = '\0';
|
||||||
|
|
||||||
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
||||||
generic_action_ok_command(CMD_EVENT_NETPLAY_DEINIT);
|
generic_action_ok_command(CMD_EVENT_NETPLAY_DEINIT);
|
||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
||||||
|
|
||||||
if (netplay_room_list[room_index].host_method == NETPLAY_HOST_METHOD_MITM)
|
if (net_st->room_list[room_index].host_method == NETPLAY_HOST_METHOD_MITM)
|
||||||
snprintf(tmp_hostname,
|
snprintf(tmp_hostname,
|
||||||
sizeof(tmp_hostname),
|
sizeof(tmp_hostname),
|
||||||
"%s|%d",
|
"%s|%d",
|
||||||
netplay_room_list[room_index].mitm_address,
|
net_st->room_list[room_index].mitm_address,
|
||||||
netplay_room_list[room_index].mitm_port);
|
net_st->room_list[room_index].mitm_port);
|
||||||
else
|
else
|
||||||
snprintf(tmp_hostname,
|
snprintf(tmp_hostname,
|
||||||
sizeof(tmp_hostname),
|
sizeof(tmp_hostname),
|
||||||
"%s|%d",
|
"%s|%d",
|
||||||
netplay_room_list[room_index].address,
|
net_st->room_list[room_index].address,
|
||||||
netplay_room_list[room_index].port);
|
net_st->room_list[room_index].port);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
RARCH_LOG("[lobby] connecting to: %s with game: %s/%08x\n",
|
RARCH_LOG("[lobby] connecting to: %s with game: %s/%08x\n",
|
||||||
tmp_hostname,
|
tmp_hostname,
|
||||||
netplay_room_list[room_index].gamename,
|
net_st->room_list[room_index].gamename,
|
||||||
netplay_room_list[room_index].gamecrc);
|
net_st->room_list[room_index].gamecrc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
task_push_netplay_crc_scan(
|
task_push_netplay_crc_scan(
|
||||||
netplay_room_list[room_index].gamecrc,
|
net_st->room_list[room_index].gamecrc,
|
||||||
netplay_room_list[room_index].gamename,
|
net_st->room_list[room_index].gamename,
|
||||||
tmp_hostname,
|
tmp_hostname,
|
||||||
netplay_room_list[room_index].corename,
|
net_st->room_list[room_index].corename,
|
||||||
netplay_room_list[room_index].subsystem_name);
|
net_st->room_list[room_index].subsystem_name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -5834,7 +5832,7 @@ static void netplay_refresh_rooms_cb(retro_task_t *task,
|
||||||
const char *label = NULL;
|
const char *label = NULL;
|
||||||
unsigned menu_type = 0;
|
unsigned menu_type = 0;
|
||||||
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
|
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
|
||||||
|
net_driver_state_t *net_st = networking_state_get_ptr();
|
||||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||||
|
|
||||||
menu_entries_get_last_stack(&path, &label, &menu_type, &enum_idx, NULL);
|
menu_entries_get_last_stack(&path, &label, &menu_type, &enum_idx, NULL);
|
||||||
|
@ -5860,7 +5858,7 @@ static void netplay_refresh_rooms_cb(retro_task_t *task,
|
||||||
STRLEN_CONST("registry.lpl")))
|
STRLEN_CONST("registry.lpl")))
|
||||||
{
|
{
|
||||||
if (string_is_empty(data->data))
|
if (string_is_empty(data->data))
|
||||||
netplay_room_count = 0;
|
net_st->room_count = 0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char s[PATH_MAX_LENGTH];
|
char s[PATH_MAX_LENGTH];
|
||||||
|
@ -5878,63 +5876,63 @@ static void netplay_refresh_rooms_cb(retro_task_t *task,
|
||||||
|
|
||||||
netplay_rooms_parse(data->data);
|
netplay_rooms_parse(data->data);
|
||||||
|
|
||||||
if (netplay_room_list)
|
if (net_st->room_list)
|
||||||
free(netplay_room_list);
|
free(net_st->room_list);
|
||||||
|
|
||||||
/* TODO/FIXME - right now, a LAN and non-LAN netplay session might appear
|
/* TODO/FIXME - right now, a LAN and non-LAN netplay session might appear
|
||||||
* in the same list. If both entries are available, we want to show only
|
* in the same list. If both entries are available, we want to show only
|
||||||
* the LAN one. */
|
* the LAN one. */
|
||||||
|
|
||||||
netplay_room_count = netplay_rooms_get_count();
|
net_st->room_count = netplay_rooms_get_count();
|
||||||
netplay_room_list = (struct netplay_room*)
|
net_st->room_list = (struct netplay_room*)
|
||||||
calloc(netplay_room_count + lan_room_count,
|
calloc(net_st->room_count + lan_room_count,
|
||||||
sizeof(struct netplay_room));
|
sizeof(struct netplay_room));
|
||||||
|
|
||||||
for (i = 0; i < (unsigned)netplay_room_count; i++)
|
for (i = 0; i < (unsigned)net_st->room_count; i++)
|
||||||
memcpy(&netplay_room_list[i], netplay_room_get(i), sizeof(netplay_room_list[i]));
|
memcpy(&net_st->room_list[i], netplay_room_get(i), sizeof(net_st->room_list[i]));
|
||||||
|
|
||||||
if (lan_room_count != 0)
|
if (lan_room_count != 0)
|
||||||
{
|
{
|
||||||
for (i = netplay_room_count; i < (unsigned)(netplay_room_count + lan_room_count); i++)
|
for (i = net_st->room_count; i < (unsigned)(net_st->room_count + lan_room_count); i++)
|
||||||
{
|
{
|
||||||
struct netplay_host *host = &lan_hosts->hosts[j++];
|
struct netplay_host *host = &lan_hosts->hosts[j++];
|
||||||
|
|
||||||
strlcpy(netplay_room_list[i].nickname,
|
strlcpy(net_st->room_list[i].nickname,
|
||||||
host->nick,
|
host->nick,
|
||||||
sizeof(netplay_room_list[i].nickname));
|
sizeof(net_st->room_list[i].nickname));
|
||||||
|
|
||||||
strlcpy(netplay_room_list[i].address,
|
strlcpy(net_st->room_list[i].address,
|
||||||
host->address,
|
host->address,
|
||||||
INET6_ADDRSTRLEN);
|
INET6_ADDRSTRLEN);
|
||||||
strlcpy(netplay_room_list[i].corename,
|
strlcpy(net_st->room_list[i].corename,
|
||||||
host->core,
|
host->core,
|
||||||
sizeof(netplay_room_list[i].corename));
|
sizeof(net_st->room_list[i].corename));
|
||||||
strlcpy(netplay_room_list[i].retroarch_version,
|
strlcpy(net_st->room_list[i].retroarch_version,
|
||||||
host->retroarch_version,
|
host->retroarch_version,
|
||||||
sizeof(netplay_room_list[i].retroarch_version));
|
sizeof(net_st->room_list[i].retroarch_version));
|
||||||
strlcpy(netplay_room_list[i].coreversion,
|
strlcpy(net_st->room_list[i].coreversion,
|
||||||
host->core_version,
|
host->core_version,
|
||||||
sizeof(netplay_room_list[i].coreversion));
|
sizeof(net_st->room_list[i].coreversion));
|
||||||
strlcpy(netplay_room_list[i].gamename,
|
strlcpy(net_st->room_list[i].gamename,
|
||||||
host->content,
|
host->content,
|
||||||
sizeof(netplay_room_list[i].gamename));
|
sizeof(net_st->room_list[i].gamename));
|
||||||
strlcpy(netplay_room_list[i].frontend,
|
strlcpy(net_st->room_list[i].frontend,
|
||||||
host->frontend,
|
host->frontend,
|
||||||
sizeof(netplay_room_list[i].frontend));
|
sizeof(net_st->room_list[i].frontend));
|
||||||
strlcpy(netplay_room_list[i].subsystem_name,
|
strlcpy(net_st->room_list[i].subsystem_name,
|
||||||
host->subsystem_name,
|
host->subsystem_name,
|
||||||
sizeof(netplay_room_list[i].subsystem_name));
|
sizeof(net_st->room_list[i].subsystem_name));
|
||||||
|
|
||||||
netplay_room_list[i].port = host->port;
|
net_st->room_list[i].port = host->port;
|
||||||
netplay_room_list[i].gamecrc = host->content_crc;
|
net_st->room_list[i].gamecrc = host->content_crc;
|
||||||
netplay_room_list[i].timestamp = 0;
|
net_st->room_list[i].timestamp = 0;
|
||||||
netplay_room_list[i].lan = true;
|
net_st->room_list[i].lan = true;
|
||||||
|
|
||||||
snprintf(s, sizeof(s),
|
snprintf(s, sizeof(s),
|
||||||
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME),
|
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NETPLAY_ROOM_NICKNAME),
|
||||||
netplay_room_list[i].nickname);
|
net_st->room_list[i].nickname);
|
||||||
}
|
}
|
||||||
netplay_room_count += lan_room_count;
|
net_st->room_count += lan_room_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
|
||||||
|
|
|
@ -1322,26 +1322,27 @@ static int action_bind_sublabel_netplay_room(
|
||||||
const char *label, const char *path,
|
const char *label, const char *path,
|
||||||
char *s, size_t len)
|
char *s, size_t len)
|
||||||
{
|
{
|
||||||
uint32_t gamecrc = 0;
|
uint32_t gamecrc = 0;
|
||||||
const char *ra_version = NULL;
|
const char *ra_version = NULL;
|
||||||
const char *corename = NULL;
|
const char *corename = NULL;
|
||||||
const char *gamename = NULL;
|
const char *gamename = NULL;
|
||||||
const char *core_ver = NULL;
|
const char *core_ver = NULL;
|
||||||
const char *frontend = NULL;
|
const char *frontend = NULL;
|
||||||
const char *na = NULL;
|
const char *na = NULL;
|
||||||
const char *subsystem = NULL;
|
const char *subsystem = NULL;
|
||||||
unsigned room_index = type - MENU_SETTINGS_NETPLAY_ROOMS_START;
|
net_driver_state_t *net_st = networking_state_get_ptr();
|
||||||
|
unsigned room_index = type - MENU_SETTINGS_NETPLAY_ROOMS_START;
|
||||||
|
|
||||||
if (room_index >= (unsigned)netplay_room_count)
|
if (room_index >= (unsigned)net_st->room_count)
|
||||||
return menu_cbs_exit();
|
return menu_cbs_exit();
|
||||||
|
|
||||||
ra_version = netplay_room_list[room_index].retroarch_version;
|
ra_version = net_st->room_list[room_index].retroarch_version;
|
||||||
corename = netplay_room_list[room_index].corename;
|
corename = net_st->room_list[room_index].corename;
|
||||||
gamename = netplay_room_list[room_index].gamename;
|
gamename = net_st->room_list[room_index].gamename;
|
||||||
core_ver = netplay_room_list[room_index].coreversion;
|
core_ver = net_st->room_list[room_index].coreversion;
|
||||||
gamecrc = netplay_room_list[room_index].gamecrc;
|
gamecrc = net_st->room_list[room_index].gamecrc;
|
||||||
frontend = netplay_room_list[room_index].frontend;
|
frontend = net_st->room_list[room_index].frontend;
|
||||||
subsystem = netplay_room_list[room_index].subsystem_name;
|
subsystem = net_st->room_list[room_index].subsystem_name;
|
||||||
na = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
|
na = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
|
||||||
|
|
||||||
if (string_is_empty(subsystem) || string_is_equal(subsystem,
|
if (string_is_empty(subsystem) || string_is_equal(subsystem,
|
||||||
|
|
|
@ -9636,6 +9636,7 @@ unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list)
|
||||||
char s[8300];
|
char s[8300];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
|
net_driver_state_t *net_st = networking_state_get_ptr();
|
||||||
|
|
||||||
s[0] = '\0';
|
s[0] = '\0';
|
||||||
|
|
||||||
|
@ -9681,15 +9682,15 @@ unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list)
|
||||||
MENU_SETTING_ACTION, 0, 0))
|
MENU_SETTING_ACTION, 0, 0))
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (netplay_room_count != 0)
|
if (net_st->room_count != 0)
|
||||||
{
|
{
|
||||||
for (i = 0; i < netplay_room_count; i++)
|
for (i = 0; i < net_st->room_count; i++)
|
||||||
{
|
{
|
||||||
char country[PATH_MAX_LENGTH];
|
char country[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
if (*netplay_room_list[i].country)
|
if (*net_st->room_list[i].country)
|
||||||
snprintf(country, sizeof(country),
|
snprintf(country, sizeof(country),
|
||||||
"(%s)", netplay_room_list[i].country);
|
"(%s)", net_st->room_list[i].country);
|
||||||
|
|
||||||
/* Uncomment this to debug mismatched room parameters*/
|
/* Uncomment this to debug mismatched room parameters*/
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -9702,23 +9703,25 @@ unsigned menu_displaylist_netplay_refresh_rooms(file_list_t *list)
|
||||||
"Game: %s\n"
|
"Game: %s\n"
|
||||||
"Game CRC: %08x\n"
|
"Game CRC: %08x\n"
|
||||||
"Timestamp: %d\n", room_data->elems[j + 6].data,
|
"Timestamp: %d\n", room_data->elems[j + 6].data,
|
||||||
netplay_room_list[i].nickname,
|
net_st->room_list[i].nickname,
|
||||||
netplay_room_list[i].address,
|
net_st->room_list[i].address,
|
||||||
netplay_room_list[i].port,
|
net_st->room_list[i].port,
|
||||||
netplay_room_list[i].corename,
|
net_st->room_list[i].corename,
|
||||||
netplay_room_list[i].coreversion,
|
net_st->room_list[i].coreversion,
|
||||||
netplay_room_list[i].gamename,
|
net_st->room_list[i].gamename,
|
||||||
netplay_room_list[i].gamecrc,
|
net_st->room_list[i].gamecrc,
|
||||||
netplay_room_list[i].timestamp);
|
net_st->room_list[i].timestamp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
snprintf(s, sizeof(s), "%s: %s%s",
|
snprintf(s, sizeof(s), "%s: %s%s",
|
||||||
netplay_room_list[i].lan
|
net_st->room_list[i].lan
|
||||||
? msg_hash_to_str(MSG_LOCAL)
|
? msg_hash_to_str(MSG_LOCAL)
|
||||||
: (netplay_room_list[i].host_method == NETPLAY_HOST_METHOD_MITM
|
: (net_st->room_list[i].host_method
|
||||||
|
== NETPLAY_HOST_METHOD_MITM
|
||||||
? msg_hash_to_str(MSG_INTERNET_RELAY)
|
? msg_hash_to_str(MSG_INTERNET_RELAY)
|
||||||
: msg_hash_to_str(MSG_INTERNET)),
|
: msg_hash_to_str(MSG_INTERNET)),
|
||||||
netplay_room_list[i].nickname, country);
|
net_st->room_list[i].nickname,
|
||||||
|
country);
|
||||||
|
|
||||||
if (menu_entries_append_enum(list,
|
if (menu_entries_append_enum(list,
|
||||||
s,
|
s,
|
||||||
|
|
|
@ -81,6 +81,24 @@ enum rarch_netplay_share_analog_preference
|
||||||
|
|
||||||
typedef struct netplay netplay_t;
|
typedef struct netplay netplay_t;
|
||||||
|
|
||||||
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
|
struct ad_packet
|
||||||
|
{
|
||||||
|
uint32_t header;
|
||||||
|
uint32_t protocol_version;
|
||||||
|
uint32_t port;
|
||||||
|
char address[NETPLAY_HOST_STR_LEN];
|
||||||
|
char retroarch_version[NETPLAY_HOST_STR_LEN];
|
||||||
|
char nick[NETPLAY_HOST_STR_LEN];
|
||||||
|
char frontend[NETPLAY_HOST_STR_LEN];
|
||||||
|
char core[NETPLAY_HOST_STR_LEN];
|
||||||
|
char core_version[NETPLAY_HOST_STR_LEN];
|
||||||
|
char content[NETPLAY_HOST_LONGSTR_LEN];
|
||||||
|
char content_crc[NETPLAY_HOST_STR_LEN];
|
||||||
|
char subsystem_name[NETPLAY_HOST_STR_LEN];
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct mitm_server
|
typedef struct mitm_server
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -124,13 +142,17 @@ typedef struct
|
||||||
netplay_t *data; /* Used while Netplay is running */
|
netplay_t *data; /* Used while Netplay is running */
|
||||||
struct netplay_room host_room; /* ptr alignment */
|
struct netplay_room host_room; /* ptr alignment */
|
||||||
netplay_t *handshake_password;
|
netplay_t *handshake_password;
|
||||||
|
struct netplay_room *room_list;
|
||||||
/* List of discovered hosts */
|
/* List of discovered hosts */
|
||||||
struct netplay_host_list discovered_hosts;
|
struct netplay_host_list discovered_hosts;
|
||||||
#ifdef HAVE_NETPLAYDISCOVERY
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
size_t discovered_hosts_allocated;
|
size_t discovered_hosts_allocated;
|
||||||
#endif
|
#endif
|
||||||
|
int room_count;
|
||||||
int reannounce;
|
int reannounce;
|
||||||
unsigned server_port_deferred;
|
unsigned server_port_deferred;
|
||||||
|
/* Packet buffer for advertisement and responses */
|
||||||
|
struct ad_packet ad_packet_buffer; /* uint32_t alignment */
|
||||||
uint16_t mapping[RETROK_LAST];
|
uint16_t mapping[RETROK_LAST];
|
||||||
char server_address_deferred[512];
|
char server_address_deferred[512];
|
||||||
/* Only used before init_netplay */
|
/* Only used before init_netplay */
|
||||||
|
|
|
@ -73,8 +73,4 @@ void deinit_netplay_discovery(void);
|
||||||
bool netplay_discovery_driver_ctl(enum rarch_netplay_discovery_ctl_state state, void *data);
|
bool netplay_discovery_driver_ctl(enum rarch_netplay_discovery_ctl_state state, void *data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* TODO/FIXME - globals */
|
|
||||||
extern struct netplay_room *netplay_room_list;
|
|
||||||
extern int netplay_room_count;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -135,36 +135,13 @@ struct info_buf_s
|
||||||
char core_version[NETPLAY_NICK_LEN];
|
char core_version[NETPLAY_NICK_LEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_NETPLAYDISCOVERY
|
|
||||||
struct ad_packet
|
|
||||||
{
|
|
||||||
uint32_t header;
|
|
||||||
uint32_t protocol_version;
|
|
||||||
uint32_t port;
|
|
||||||
char address[NETPLAY_HOST_STR_LEN];
|
|
||||||
char retroarch_version[NETPLAY_HOST_STR_LEN];
|
|
||||||
char nick[NETPLAY_HOST_STR_LEN];
|
|
||||||
char frontend[NETPLAY_HOST_STR_LEN];
|
|
||||||
char core[NETPLAY_HOST_STR_LEN];
|
|
||||||
char core_version[NETPLAY_HOST_STR_LEN];
|
|
||||||
char content[NETPLAY_HOST_LONGSTR_LEN];
|
|
||||||
char content_crc[NETPLAY_HOST_STR_LEN];
|
|
||||||
char subsystem_name[NETPLAY_HOST_STR_LEN];
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* TODO/FIXME - globals */
|
/* TODO/FIXME - globals */
|
||||||
struct netplay_room *netplay_room_list = NULL;
|
static unsigned long simple_rand_next = 1;
|
||||||
int netplay_room_count = 0;
|
|
||||||
static unsigned long simple_rand_next = 1;
|
|
||||||
|
|
||||||
#ifdef HAVE_NETPLAYDISCOVERY
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
/* LAN discovery sockets */
|
/* LAN discovery sockets */
|
||||||
static int lan_ad_server_fd = -1;
|
static int lan_ad_server_fd = -1;
|
||||||
static int lan_ad_client_fd = -1;
|
static int lan_ad_client_fd = -1;
|
||||||
|
|
||||||
/* Packet buffer for advertisement and responses */
|
|
||||||
static struct ad_packet ad_packet_buffer;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The mapping of keys from netplay (network) to libretro (host) */
|
/* The mapping of keys from netplay (network) to libretro (host) */
|
||||||
|
@ -235,18 +212,18 @@ static bool netplay_lan_ad_client(void)
|
||||||
/* Somebody queried, so check that it's valid */
|
/* Somebody queried, so check that it's valid */
|
||||||
addr_size = sizeof(their_addr);
|
addr_size = sizeof(their_addr);
|
||||||
|
|
||||||
if (recvfrom(lan_ad_client_fd, (char*)&ad_packet_buffer,
|
if (recvfrom(lan_ad_client_fd, (char*)&net_st->ad_packet_buffer,
|
||||||
sizeof(struct ad_packet), 0, &their_addr, &addr_size) >=
|
sizeof(struct ad_packet), 0, &their_addr, &addr_size) >=
|
||||||
(ssize_t) sizeof(struct ad_packet))
|
(ssize_t) sizeof(struct ad_packet))
|
||||||
{
|
{
|
||||||
struct netplay_host *host = NULL;
|
struct netplay_host *host = NULL;
|
||||||
|
|
||||||
/* Make sure it's a valid response */
|
/* Make sure it's a valid response */
|
||||||
if (memcmp((void *) &ad_packet_buffer, "RANS", 4))
|
if (memcmp((void *) &net_st->ad_packet_buffer, "RANS", 4))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* For this version */
|
/* For this version */
|
||||||
if (ntohl(ad_packet_buffer.protocol_version)
|
if (ntohl(net_st->ad_packet_buffer.protocol_version)
|
||||||
!= NETPLAY_PROTOCOL_VERSION)
|
!= NETPLAY_PROTOCOL_VERSION)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -257,7 +234,7 @@ static bool netplay_lan_ad_client(void)
|
||||||
|
|
||||||
RARCH_WARN ("[Discovery] Using IPv4 for discovery\n");
|
RARCH_WARN ("[Discovery] Using IPv4 for discovery\n");
|
||||||
sin = (struct sockaddr_in *) &their_addr;
|
sin = (struct sockaddr_in *) &their_addr;
|
||||||
sin->sin_port = htons(ntohl(ad_packet_buffer.port));
|
sin->sin_port = htons(ntohl(net_st->ad_packet_buffer.port));
|
||||||
|
|
||||||
}
|
}
|
||||||
#ifdef HAVE_INET6
|
#ifdef HAVE_INET6
|
||||||
|
@ -266,7 +243,7 @@ static bool netplay_lan_ad_client(void)
|
||||||
struct sockaddr_in6 *sin6 = NULL;
|
struct sockaddr_in6 *sin6 = NULL;
|
||||||
RARCH_WARN ("[Discovery] Using IPv6 for discovery\n");
|
RARCH_WARN ("[Discovery] Using IPv6 for discovery\n");
|
||||||
sin6 = (struct sockaddr_in6 *) &their_addr;
|
sin6 = (struct sockaddr_in6 *) &their_addr;
|
||||||
sin6->sin6_port = htons(ad_packet_buffer.port);
|
sin6->sin6_port = htons(net_st->ad_packet_buffer.port);
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -309,24 +286,35 @@ static bool netplay_lan_ad_client(void)
|
||||||
host->addr = their_addr;
|
host->addr = their_addr;
|
||||||
host->addrlen = addr_size;
|
host->addrlen = addr_size;
|
||||||
|
|
||||||
host->port = ntohl(ad_packet_buffer.port);
|
host->port = ntohl(net_st->ad_packet_buffer.port);
|
||||||
|
|
||||||
strlcpy(host->address, ad_packet_buffer.address, NETPLAY_HOST_STR_LEN);
|
strlcpy(host->address,
|
||||||
strlcpy(host->nick, ad_packet_buffer.nick, NETPLAY_HOST_STR_LEN);
|
net_st->ad_packet_buffer.address,
|
||||||
strlcpy(host->core, ad_packet_buffer.core, NETPLAY_HOST_STR_LEN);
|
NETPLAY_HOST_STR_LEN);
|
||||||
strlcpy(host->retroarch_version, ad_packet_buffer.retroarch_version,
|
strlcpy(host->nick,
|
||||||
NETPLAY_HOST_STR_LEN);
|
net_st->ad_packet_buffer.nick,
|
||||||
strlcpy(host->core_version, ad_packet_buffer.core_version,
|
NETPLAY_HOST_STR_LEN);
|
||||||
NETPLAY_HOST_STR_LEN);
|
strlcpy(host->core,
|
||||||
strlcpy(host->content, ad_packet_buffer.content,
|
net_st->ad_packet_buffer.core,
|
||||||
NETPLAY_HOST_LONGSTR_LEN);
|
NETPLAY_HOST_STR_LEN);
|
||||||
strlcpy(host->subsystem_name, ad_packet_buffer.subsystem_name,
|
strlcpy(host->retroarch_version,
|
||||||
NETPLAY_HOST_LONGSTR_LEN);
|
net_st->ad_packet_buffer.retroarch_version,
|
||||||
strlcpy(host->frontend, ad_packet_buffer.frontend,
|
NETPLAY_HOST_STR_LEN);
|
||||||
NETPLAY_HOST_STR_LEN);
|
strlcpy(host->core_version,
|
||||||
|
net_st->ad_packet_buffer.core_version,
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
strlcpy(host->content,
|
||||||
|
net_st->ad_packet_buffer.content,
|
||||||
|
NETPLAY_HOST_LONGSTR_LEN);
|
||||||
|
strlcpy(host->subsystem_name,
|
||||||
|
net_st->ad_packet_buffer.subsystem_name,
|
||||||
|
NETPLAY_HOST_LONGSTR_LEN);
|
||||||
|
strlcpy(host->frontend,
|
||||||
|
net_st->ad_packet_buffer.frontend,
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
|
||||||
host->content_crc =
|
host->content_crc =
|
||||||
atoi(ad_packet_buffer.content_crc);
|
atoi(net_st->ad_packet_buffer.content_crc);
|
||||||
host->nick[NETPLAY_HOST_STR_LEN-1] =
|
host->nick[NETPLAY_HOST_STR_LEN-1] =
|
||||||
host->core[NETPLAY_HOST_STR_LEN-1] =
|
host->core[NETPLAY_HOST_STR_LEN-1] =
|
||||||
host->core_version[NETPLAY_HOST_STR_LEN-1] =
|
host->core_version[NETPLAY_HOST_STR_LEN-1] =
|
||||||
|
@ -413,16 +401,18 @@ bool netplay_discovery_driver_ctl(
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Put together the request */
|
/* Put together the request */
|
||||||
memcpy((void *) &ad_packet_buffer, "RANQ", 4);
|
memcpy((void *)&net_st->ad_packet_buffer, "RANQ", 4);
|
||||||
ad_packet_buffer.protocol_version = htonl(NETPLAY_PROTOCOL_VERSION);
|
net_st->ad_packet_buffer.protocol_version = htonl(NETPLAY_PROTOCOL_VERSION);
|
||||||
|
|
||||||
for (k = 0; k < (unsigned)interfaces.size; k++)
|
for (k = 0; k < (unsigned)interfaces.size; k++)
|
||||||
{
|
{
|
||||||
strlcpy(ad_packet_buffer.address, interfaces.entries[k].host,
|
strlcpy(net_st->ad_packet_buffer.address,
|
||||||
NETPLAY_HOST_STR_LEN);
|
interfaces.entries[k].host,
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
|
||||||
/* And send it off */
|
/* And send it off */
|
||||||
ret = (int)sendto(lan_ad_client_fd, (const char *) &ad_packet_buffer,
|
ret = (int)sendto(lan_ad_client_fd, (const char *)
|
||||||
|
&net_st->ad_packet_buffer,
|
||||||
sizeof(struct ad_packet), 0, addr->ai_addr, addr->ai_addrlen);
|
sizeof(struct ad_packet), 0, addr->ai_addr, addr->ai_addrlen);
|
||||||
if (ret < (ssize_t) (2*sizeof(uint32_t)))
|
if (ret < (ssize_t) (2*sizeof(uint32_t)))
|
||||||
RARCH_WARN("[Discovery] Failed to send netplay discovery query (error: %d)\n", errno);
|
RARCH_WARN("[Discovery] Failed to send netplay discovery query (error: %d)\n", errno);
|
||||||
|
@ -495,6 +485,7 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
unsigned k = 0;
|
unsigned k = 0;
|
||||||
struct addrinfo *our_addr, hints = {0};
|
struct addrinfo *our_addr, hints = {0};
|
||||||
struct string_list *subsystem = path_get_subsystem_list();
|
struct string_list *subsystem = path_get_subsystem_list();
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
|
|
||||||
interfaces.entries = NULL;
|
interfaces.entries = NULL;
|
||||||
interfaces.size = 0;
|
interfaces.size = 0;
|
||||||
|
@ -525,7 +516,8 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
|
|
||||||
/* Somebody queried, so check that it's valid */
|
/* Somebody queried, so check that it's valid */
|
||||||
addr_size = sizeof(their_addr);
|
addr_size = sizeof(their_addr);
|
||||||
ret = (int)recvfrom(lan_ad_server_fd, (char*)&ad_packet_buffer,
|
ret = (int)recvfrom(lan_ad_server_fd, (char*)
|
||||||
|
&net_st->ad_packet_buffer,
|
||||||
sizeof(struct ad_packet), 0, &their_addr, &addr_size);
|
sizeof(struct ad_packet), 0, &their_addr, &addr_size);
|
||||||
if (ret >= (ssize_t) (2 * sizeof(uint32_t)))
|
if (ret >= (ssize_t) (2 * sizeof(uint32_t)))
|
||||||
{
|
{
|
||||||
|
@ -533,22 +525,24 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
uint32_t content_crc = 0;
|
uint32_t content_crc = 0;
|
||||||
|
|
||||||
/* Make sure it's a valid query */
|
/* Make sure it's a valid query */
|
||||||
if (memcmp((void *) &ad_packet_buffer, "RANQ", 4))
|
if (memcmp((void *) &net_st->ad_packet_buffer, "RANQ", 4))
|
||||||
{
|
{
|
||||||
RARCH_LOG("[Discovery] Invalid query\n");
|
RARCH_LOG("[Discovery] Invalid query\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For this version */
|
/* For this version */
|
||||||
if (ntohl(ad_packet_buffer.protocol_version) !=
|
if (ntohl(net_st->ad_packet_buffer.protocol_version) !=
|
||||||
NETPLAY_PROTOCOL_VERSION)
|
NETPLAY_PROTOCOL_VERSION)
|
||||||
{
|
{
|
||||||
RARCH_LOG("[Discovery] Invalid protocol version\n");
|
RARCH_LOG("[Discovery] Invalid protocol version\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string_is_empty(ad_packet_buffer.address))
|
if (!string_is_empty(net_st->ad_packet_buffer.address))
|
||||||
strlcpy(reply_addr, ad_packet_buffer.address, NETPLAY_HOST_STR_LEN);
|
strlcpy(reply_addr,
|
||||||
|
net_st->ad_packet_buffer.address,
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
|
||||||
for (k = 0; k < interfaces.size; k++)
|
for (k = 0; k < interfaces.size; k++)
|
||||||
{
|
{
|
||||||
|
@ -579,8 +573,9 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
content_crc = content_get_crc();
|
content_crc = content_get_crc();
|
||||||
|
|
||||||
memset(&ad_packet_buffer, 0, sizeof(struct ad_packet));
|
memset(&net_st->ad_packet_buffer,
|
||||||
memcpy(&ad_packet_buffer, "RANS", 4);
|
0, sizeof(struct ad_packet));
|
||||||
|
memcpy(&net_st->ad_packet_buffer, "RANS", 4);
|
||||||
|
|
||||||
if (subsystem)
|
if (subsystem)
|
||||||
{
|
{
|
||||||
|
@ -592,41 +587,52 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
if (i < subsystem->size - 1)
|
if (i < subsystem->size - 1)
|
||||||
strlcat(buf, "|", NETPLAY_HOST_LONGSTR_LEN);
|
strlcat(buf, "|", NETPLAY_HOST_LONGSTR_LEN);
|
||||||
}
|
}
|
||||||
strlcpy(ad_packet_buffer.content, buf,
|
strlcpy(net_st->ad_packet_buffer.content, buf,
|
||||||
NETPLAY_HOST_LONGSTR_LEN);
|
NETPLAY_HOST_LONGSTR_LEN);
|
||||||
strlcpy(ad_packet_buffer.subsystem_name, path_get(RARCH_PATH_SUBSYSTEM),
|
strlcpy(net_st->ad_packet_buffer.subsystem_name,
|
||||||
NETPLAY_HOST_STR_LEN);
|
path_get(RARCH_PATH_SUBSYSTEM),
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strlcpy(ad_packet_buffer.content, !string_is_empty(
|
strlcpy(net_st->ad_packet_buffer.content,
|
||||||
|
!string_is_empty(
|
||||||
path_basename(path_get(RARCH_PATH_BASENAME)))
|
path_basename(path_get(RARCH_PATH_BASENAME)))
|
||||||
? path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A",
|
? path_basename(path_get(RARCH_PATH_BASENAME))
|
||||||
|
: "N/A",
|
||||||
NETPLAY_HOST_LONGSTR_LEN);
|
NETPLAY_HOST_LONGSTR_LEN);
|
||||||
strlcpy(ad_packet_buffer.subsystem_name, "N/A", NETPLAY_HOST_STR_LEN);
|
strlcpy(net_st->ad_packet_buffer.subsystem_name,
|
||||||
|
"N/A",
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(ad_packet_buffer.address, interfaces.entries[k].host,
|
strlcpy(net_st->ad_packet_buffer.address,
|
||||||
NETPLAY_HOST_STR_LEN);
|
interfaces.entries[k].host,
|
||||||
ad_packet_buffer.protocol_version =
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
net_st->ad_packet_buffer.protocol_version =
|
||||||
htonl(NETPLAY_PROTOCOL_VERSION);
|
htonl(NETPLAY_PROTOCOL_VERSION);
|
||||||
ad_packet_buffer.port = htonl(netplay->tcp_port);
|
net_st->ad_packet_buffer.port = htonl(netplay->tcp_port);
|
||||||
strlcpy(ad_packet_buffer.retroarch_version, PACKAGE_VERSION,
|
strlcpy(net_st->ad_packet_buffer.retroarch_version,
|
||||||
NETPLAY_HOST_STR_LEN);
|
PACKAGE_VERSION,
|
||||||
strlcpy(ad_packet_buffer.nick, netplay->nick, NETPLAY_HOST_STR_LEN);
|
NETPLAY_HOST_STR_LEN);
|
||||||
strlcpy(ad_packet_buffer.frontend, frontend, NETPLAY_HOST_STR_LEN);
|
strlcpy(net_st->ad_packet_buffer.nick,
|
||||||
|
netplay->nick, NETPLAY_HOST_STR_LEN);
|
||||||
|
strlcpy(net_st->ad_packet_buffer.frontend,
|
||||||
|
frontend, NETPLAY_HOST_STR_LEN);
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
{
|
{
|
||||||
strlcpy(ad_packet_buffer.core, info->library_name,
|
strlcpy(net_st->ad_packet_buffer.core,
|
||||||
NETPLAY_HOST_STR_LEN);
|
info->library_name,
|
||||||
strlcpy(ad_packet_buffer.core_version, info->library_version,
|
NETPLAY_HOST_STR_LEN);
|
||||||
NETPLAY_HOST_STR_LEN);
|
strlcpy(net_st->ad_packet_buffer.core_version,
|
||||||
|
info->library_version,
|
||||||
|
NETPLAY_HOST_STR_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(s, sizeof(s), "%ld", (long)content_crc);
|
snprintf(s, sizeof(s), "%ld", (long)content_crc);
|
||||||
strlcpy(ad_packet_buffer.content_crc, s,
|
strlcpy(net_st->ad_packet_buffer.content_crc, s,
|
||||||
NETPLAY_HOST_STR_LEN);
|
NETPLAY_HOST_STR_LEN);
|
||||||
|
|
||||||
/* Build up the destination address*/
|
/* Build up the destination address*/
|
||||||
snprintf(port_str, 6, "%hu", ntohs(((struct sockaddr_in*)(&their_addr))->sin_port));
|
snprintf(port_str, 6, "%hu", ntohs(((struct sockaddr_in*)(&their_addr))->sin_port));
|
||||||
|
@ -636,8 +642,10 @@ bool netplay_lan_ad_server(netplay_t *netplay)
|
||||||
RARCH_LOG ("[Discovery] Sending reply to %s \n", reply_addr);
|
RARCH_LOG ("[Discovery] Sending reply to %s \n", reply_addr);
|
||||||
|
|
||||||
/* And send it */
|
/* And send it */
|
||||||
sendto(lan_ad_server_fd, (const char*)&ad_packet_buffer,
|
sendto(lan_ad_server_fd,
|
||||||
sizeof(struct ad_packet), 0, our_addr->ai_addr, our_addr->ai_addrlen);
|
(const char*)&net_st->ad_packet_buffer,
|
||||||
|
sizeof(struct ad_packet),
|
||||||
|
0, our_addr->ai_addr, our_addr->ai_addrlen);
|
||||||
freeaddrinfo_retro(our_addr);
|
freeaddrinfo_retro(our_addr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue