mirror of
https://github.com/libretro/RetroArch
synced 2025-03-25 16:44:01 +00:00
Revert "Revert "Move some stray globals to netplay state""
This reverts commit 722f9bbfac0ceae95f2b8c2b77b5a9f0ed18816f.
This commit is contained in:
parent
7e7b2d826e
commit
ac1f6ab599
@ -24,6 +24,14 @@
|
|||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "../../config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
|
#include "netplay_discovery.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "../../core.h"
|
#include "../../core.h"
|
||||||
|
|
||||||
enum rarch_netplay_ctl_state
|
enum rarch_netplay_ctl_state
|
||||||
@ -115,8 +123,16 @@ 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;
|
||||||
|
/* List of discovered hosts */
|
||||||
|
struct netplay_host_list discovered_hosts;
|
||||||
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
|
size_t discovered_hosts_allocated;
|
||||||
|
#endif
|
||||||
int reannounce;
|
int reannounce;
|
||||||
unsigned server_port_deferred;
|
unsigned server_port_deferred;
|
||||||
|
uint16_t mapping[RETROK_LAST];
|
||||||
|
char server_address_deferred[512];
|
||||||
/* Only used before init_netplay */
|
/* Only used before init_netplay */
|
||||||
bool netplay_enabled;
|
bool netplay_enabled;
|
||||||
bool netplay_is_client;
|
bool netplay_is_client;
|
||||||
@ -124,7 +140,6 @@ typedef struct
|
|||||||
bool in_netplay;
|
bool in_netplay;
|
||||||
bool netplay_client_deferred;
|
bool netplay_client_deferred;
|
||||||
bool is_mitm;
|
bool is_mitm;
|
||||||
char server_address_deferred[512];
|
|
||||||
bool has_set_netplay_mode;
|
bool has_set_netplay_mode;
|
||||||
bool has_set_netplay_ip_address;
|
bool has_set_netplay_ip_address;
|
||||||
bool has_set_netplay_ip_port;
|
bool has_set_netplay_ip_port;
|
||||||
|
@ -156,7 +156,6 @@ struct ad_packet
|
|||||||
/* TODO/FIXME - globals */
|
/* TODO/FIXME - globals */
|
||||||
struct netplay_room *netplay_room_list = NULL;
|
struct netplay_room *netplay_room_list = NULL;
|
||||||
int netplay_room_count = 0;
|
int netplay_room_count = 0;
|
||||||
static netplay_t *handshake_password_netplay = NULL;
|
|
||||||
static unsigned long simple_rand_next = 1;
|
static unsigned long simple_rand_next = 1;
|
||||||
|
|
||||||
#ifdef HAVE_NETPLAYDISCOVERY
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
@ -166,11 +165,6 @@ static int lan_ad_client_fd = -1;
|
|||||||
|
|
||||||
/* Packet buffer for advertisement and responses */
|
/* Packet buffer for advertisement and responses */
|
||||||
static struct ad_packet ad_packet_buffer;
|
static struct ad_packet ad_packet_buffer;
|
||||||
|
|
||||||
/* List of discovered hosts */
|
|
||||||
static struct netplay_host_list discovered_hosts;
|
|
||||||
|
|
||||||
static size_t discovered_hosts_allocated;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The mapping of keys from netplay (network) to libretro (host) */
|
/* The mapping of keys from netplay (network) to libretro (host) */
|
||||||
@ -184,9 +178,6 @@ const uint16_t netplay_key_ntoh_mapping[] = {
|
|||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO/FIXME - static global variables */
|
|
||||||
static uint16_t netplay_mapping[RETROK_LAST];
|
|
||||||
|
|
||||||
static net_driver_state_t networking_driver_st = {0};
|
static net_driver_state_t networking_driver_st = {0};
|
||||||
|
|
||||||
net_driver_state_t *networking_state_get_ptr(void)
|
net_driver_state_t *networking_state_get_ptr(void)
|
||||||
@ -220,6 +211,7 @@ static bool netplay_lan_ad_client(void)
|
|||||||
socklen_t addr_size;
|
socklen_t addr_size;
|
||||||
struct sockaddr their_addr;
|
struct sockaddr their_addr;
|
||||||
struct timeval tmp_tv = {0};
|
struct timeval tmp_tv = {0};
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
|
|
||||||
if (lan_ad_client_fd < 0)
|
if (lan_ad_client_fd < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -282,9 +274,9 @@ static bool netplay_lan_ad_client(void)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Allocate space for it */
|
/* Allocate space for it */
|
||||||
if (discovered_hosts.size >= discovered_hosts_allocated)
|
if (net_st->discovered_hosts.size >= net_st->discovered_hosts_allocated)
|
||||||
{
|
{
|
||||||
size_t allocated = discovered_hosts_allocated;
|
size_t allocated = net_st->discovered_hosts_allocated;
|
||||||
struct netplay_host *new_hosts = NULL;
|
struct netplay_host *new_hosts = NULL;
|
||||||
|
|
||||||
if (allocated == 0)
|
if (allocated == 0)
|
||||||
@ -292,9 +284,9 @@ static bool netplay_lan_ad_client(void)
|
|||||||
else
|
else
|
||||||
allocated *= 2;
|
allocated *= 2;
|
||||||
|
|
||||||
if (discovered_hosts.hosts)
|
if (net_st->discovered_hosts.hosts)
|
||||||
new_hosts = (struct netplay_host *)
|
new_hosts = (struct netplay_host *)
|
||||||
realloc(discovered_hosts.hosts, allocated * sizeof(struct
|
realloc(net_st->discovered_hosts.hosts, allocated * sizeof(struct
|
||||||
netplay_host));
|
netplay_host));
|
||||||
else
|
else
|
||||||
/* Should be equivalent to realloc,
|
/* Should be equivalent to realloc,
|
||||||
@ -305,12 +297,12 @@ static bool netplay_lan_ad_client(void)
|
|||||||
if (!new_hosts)
|
if (!new_hosts)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
discovered_hosts.hosts = new_hosts;
|
net_st->discovered_hosts.hosts = new_hosts;
|
||||||
discovered_hosts_allocated = allocated;
|
net_st->discovered_hosts_allocated = allocated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get our host structure */
|
/* Get our host structure */
|
||||||
host = &discovered_hosts.hosts[discovered_hosts.size++];
|
host = &net_st->discovered_hosts.hosts[net_st->discovered_hosts.size++];
|
||||||
|
|
||||||
/* Copy in the response */
|
/* Copy in the response */
|
||||||
memset(host, 0, sizeof(struct netplay_host));
|
memset(host, 0, sizeof(struct netplay_host));
|
||||||
@ -390,6 +382,7 @@ bool netplay_discovery_driver_ctl(
|
|||||||
int ret;
|
int ret;
|
||||||
char port_str[6];
|
char port_str[6];
|
||||||
unsigned k = 0;
|
unsigned k = 0;
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
|
|
||||||
if (lan_ad_client_fd < 0)
|
if (lan_ad_client_fd < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -444,11 +437,11 @@ bool netplay_discovery_driver_ctl(
|
|||||||
case RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES:
|
case RARCH_NETPLAY_DISCOVERY_CTL_LAN_GET_RESPONSES:
|
||||||
if (!netplay_lan_ad_client())
|
if (!netplay_lan_ad_client())
|
||||||
return false;
|
return false;
|
||||||
*((struct netplay_host_list **) data) = &discovered_hosts;
|
*((struct netplay_host_list **) data) = &net_st->discovered_hosts;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RARCH_NETPLAY_DISCOVERY_CTL_LAN_CLEAR_RESPONSES:
|
case RARCH_NETPLAY_DISCOVERY_CTL_LAN_CLEAR_RESPONSES:
|
||||||
discovered_hosts.size = 0;
|
net_st->discovered_hosts.size = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -792,20 +785,12 @@ static int simple_rand(void)
|
|||||||
return((unsigned)(simple_rand_next / 65536) % 32768);
|
return((unsigned)(simple_rand_next / 65536) % 32768);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simple_srand(unsigned int seed)
|
|
||||||
{
|
|
||||||
simple_rand_next = seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint32_t simple_rand_uint32(void)
|
static uint32_t simple_rand_uint32(void)
|
||||||
{
|
{
|
||||||
uint32_t parts[3];
|
uint32_t part0 = simple_rand();
|
||||||
parts[0] = simple_rand();
|
uint32_t part1 = simple_rand();
|
||||||
parts[1] = simple_rand();
|
uint32_t part2 = simple_rand();
|
||||||
parts[2] = simple_rand();
|
return ((part0 << 30) + (part1 << 15) + part2);
|
||||||
return ((parts[0] << 30) +
|
|
||||||
(parts[1] << 15) +
|
|
||||||
parts[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -861,7 +846,7 @@ bool netplay_handshake_init_send(netplay_t *netplay,
|
|||||||
{
|
{
|
||||||
/* Demand a password */
|
/* Demand a password */
|
||||||
if (simple_rand_next == 1)
|
if (simple_rand_next == 1)
|
||||||
simple_srand((unsigned int) time(NULL));
|
simple_rand_next = (unsigned int)time(NULL);
|
||||||
connection->salt = simple_rand_uint32();
|
connection->salt = simple_rand_uint32();
|
||||||
if (connection->salt == 0)
|
if (connection->salt == 0)
|
||||||
connection->salt = 1;
|
connection->salt = 1;
|
||||||
@ -884,7 +869,8 @@ static void handshake_password(void *ignore, const char *line)
|
|||||||
struct password_buf_s password_buf;
|
struct password_buf_s password_buf;
|
||||||
char password[8+NETPLAY_PASS_LEN]; /* 8 for salt, 128 for password */
|
char password[8+NETPLAY_PASS_LEN]; /* 8 for salt, 128 for password */
|
||||||
char hash[NETPLAY_PASS_HASH_LEN+1]; /* + NULL terminator */
|
char hash[NETPLAY_PASS_HASH_LEN+1]; /* + NULL terminator */
|
||||||
netplay_t *netplay = handshake_password_netplay;
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
|
netplay_t *netplay = net_st->handshake_password;
|
||||||
struct netplay_connection *connection = &netplay->connections[0];
|
struct netplay_connection *connection = &netplay->connections[0];
|
||||||
|
|
||||||
snprintf(password, sizeof(password), "%08lX", (unsigned long)connection->salt);
|
snprintf(password, sizeof(password), "%08lX", (unsigned long)connection->salt);
|
||||||
@ -926,6 +912,7 @@ bool netplay_handshake_init(netplay_t *netplay,
|
|||||||
uint32_t compression = 0;
|
uint32_t compression = 0;
|
||||||
struct compression_transcoder *ctrans = NULL;
|
struct compression_transcoder *ctrans = NULL;
|
||||||
const char *dmsg = NULL;
|
const char *dmsg = NULL;
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
bool extra_notifications = settings->bools.notification_show_netplay_extra;
|
bool extra_notifications = settings->bools.notification_show_netplay_extra;
|
||||||
|
|
||||||
@ -1062,7 +1049,7 @@ bool netplay_handshake_init(netplay_t *netplay,
|
|||||||
retroarch_menu_running();
|
retroarch_menu_running();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
handshake_password_netplay = netplay;
|
net_st->handshake_password = netplay;
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
memset(&line, 0, sizeof(line));
|
memset(&line, 0, sizeof(line));
|
||||||
@ -1855,9 +1842,10 @@ bool netplay_handshake(netplay_t *netplay,
|
|||||||
/* The mapping of keys from libretro (host) to netplay (network) */
|
/* The mapping of keys from libretro (host) to netplay (network) */
|
||||||
uint32_t netplay_key_hton(unsigned key)
|
uint32_t netplay_key_hton(unsigned key)
|
||||||
{
|
{
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
if (key >= RETROK_LAST)
|
if (key >= RETROK_LAST)
|
||||||
return NETPLAY_KEY_UNKNOWN;
|
return NETPLAY_KEY_UNKNOWN;
|
||||||
return netplay_mapping[key];
|
return net_st->mapping[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Because the hton keymapping has to be generated, call this before using
|
/* Because the hton keymapping has to be generated, call this before using
|
||||||
@ -1865,12 +1853,13 @@ uint32_t netplay_key_hton(unsigned key)
|
|||||||
void netplay_key_hton_init(void)
|
void netplay_key_hton_init(void)
|
||||||
{
|
{
|
||||||
static bool mapping_defined = false;
|
static bool mapping_defined = false;
|
||||||
|
net_driver_state_t *net_st = &networking_driver_st;
|
||||||
|
|
||||||
if (!mapping_defined)
|
if (!mapping_defined)
|
||||||
{
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
for (i = 0; i < NETPLAY_KEY_LAST; i++)
|
for (i = 0; i < NETPLAY_KEY_LAST; i++)
|
||||||
netplay_mapping[NETPLAY_KEY_NTOH(i)] = i;
|
net_st->mapping[NETPLAY_KEY_NTOH(i)] = i;
|
||||||
mapping_defined = true;
|
mapping_defined = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user