(network) Cleanups

This commit is contained in:
twinaphex 2021-11-06 00:27:33 +01:00
parent 1ae36ee9a7
commit 0af9b72388
4 changed files with 199 additions and 163 deletions

View File

@ -154,6 +154,12 @@ struct netplay_room
bool fixed;
};
struct netplay_rooms
{
struct netplay_room *head;
struct netplay_room *cur;
};
struct netplay_host
{
struct sockaddr addr;
@ -182,6 +188,7 @@ typedef struct
struct netplay_room host_room; /* ptr alignment */
netplay_t *handshake_password;
struct netplay_room *room_list;
struct netplay_rooms *rooms_data;
/* List of discovered hosts */
struct netplay_host_list discovered_hosts;
#ifdef HAVE_NETPLAYDISCOVERY

View File

@ -143,8 +143,20 @@ static int lan_ad_server_fd = -1;
static int lan_ad_client_fd = -1;
#endif
/* The keys supported by netplay */
enum netplay_keys
{
NETPLAY_KEY_UNKNOWN = 0,
#define K(k) NETPLAY_KEY_ ## k,
#define KL(k,l) K(k)
#include "netplay_keys.h"
#undef KL
#undef K
NETPLAY_KEY_LAST
};
/* The mapping of keys from netplay (network) to libretro (host) */
const uint16_t netplay_key_ntoh_mapping[] = {
static const uint16_t netplay_key_ntoh_mapping[] = {
(uint16_t) RETROK_UNKNOWN,
#define K(k) (uint16_t) RETROK_ ## k,
#define KL(k,l) (uint16_t) l,
@ -154,6 +166,8 @@ const uint16_t netplay_key_ntoh_mapping[] = {
0
};
#define NETPLAY_KEY_NTOH(k) (netplay_key_ntoh_mapping[k])
static net_driver_state_t networking_driver_st = {0};
net_driver_state_t *networking_state_get_ptr(void)

View File

@ -206,10 +206,12 @@ enum netplay_cmd_mode_reasons
/* Real preferences for sharing devices */
enum rarch_netplay_share_preference
{
/* Prefer not to share, shouldn't be set as a sharing mode for an shared device */
/* Prefer not to share, shouldn't be set
as a sharing mode for an shared device */
NETPLAY_SHARE_NO_SHARING = 0x0,
/* No preference. Only for requests. Set if sharing is requested but either
/* No preference. Only for requests.
Set if sharing is requested but either
* digital or analog doesn't have a preference. */
NETPLAY_SHARE_NO_PREFERENCE = 0x1,
@ -230,7 +232,8 @@ enum rarch_netplay_connection_mode
{
NETPLAY_CONNECTION_NONE = 0,
NETPLAY_CONNECTION_DELAYED_DISCONNECT, /* The connection is dead, but data
NETPLAY_CONNECTION_DELAYED_DISCONNECT,
/* The connection is dead, but data
is still waiting to be forwarded */
/* Initialization: */
@ -251,14 +254,16 @@ enum rarch_netplay_stall_reason
{
NETPLAY_STALL_NONE = 0,
/* We're so far ahead that we can't read more data without overflowing the
* buffer */
/* We're so far ahead that we can't read
more data without overflowing the buffer */
NETPLAY_STALL_RUNNING_FAST,
/* We're in spectator or slave mode and are running ahead at all */
/* We're in spectator or slave mode
and are running ahead at all */
NETPLAY_STALL_SPECTATOR_WAIT,
/* Our actual execution is catching up with latency-adjusted input frames */
/* Our actual execution is catching up
with latency-adjusted input frames */
NETPLAY_STALL_INPUT_LATENCY,
/* The server asked us to stall */
@ -283,16 +288,18 @@ typedef struct netplay_input_state
/* Is this a buffer with real data? */
bool used;
/* The input data itself (note: should expand beyond 1 by overallocating). */
/* The input data itself (note: should expand
beyond 1 by overallocating). */
uint32_t data[1];
/* Warning: No members allowed past this point, due to dynamic resizing. */
/* Warning: No members allowed past this point,
due to dynamic resizing. */
} *netplay_input_state_t;
struct delta_frame
{
/* The resolved input, i.e., what's actually going to the core. One input
* per device. */
/* The resolved input, i.e., what's actually
going to the core. One input per device. */
netplay_input_state_t resolved_input[MAX_INPUT_DEVICES]; /* ptr alignment */
/* The real input */
@ -316,7 +323,9 @@ struct delta_frame
/* Have we read the real (remote) input? */
bool have_real[MAX_CLIENTS];
bool used; /* a bit derpy, but this is how we know if the delta's been used at all */
/* A bit derpy, but this is how we know if the delta
* has been used at all. */
bool used;
};
struct socket_buffer
@ -343,15 +352,18 @@ struct netplay_connection
/* fd associated with this connection */
int fd;
/* If the mode is a DELAYED_DISCONNECT or SPECTATOR, the transmission of the
* mode change may have to wait for data to be forwarded. This is the frame
* to wait for, or 0 if no delay is active. */
/* If the mode is a DELAYED_DISCONNECT or SPECTATOR,
* the transmission of the mode change may have to
* wait for data to be forwarded.
* This is the frame to wait for, or 0 if no delay
* is active. */
uint32_t delay_frame;
/* What compression does this peer support? */
uint32_t compression_supported;
/* For the server: When was the last time we requested this client to stall?
/* For the server: When was the last time we requested
* this client to stall?
* For the client: How many frames of stall do we have left? */
uint32_t stall_frame;
@ -393,10 +405,11 @@ struct netplay
/* How long have we been stalled? */
retro_time_t stall_time;
/* We stall if we're far enough ahead that we couldn't transparently rewind.
* To know if we could transparently rewind, we need to know how long
* running a frame takes. We record that every frame and get a running
* (window) average */
/* We stall if we're far enough ahead that we
* couldn't transparently rewind.
* To know if we could transparently rewind,
* we need to know how long running a frame takes.
* We record that every frame and get a running (window) average. */
retro_time_t frame_run_time[NETPLAY_FRAME_RUN_TIME_WINDOW];
retro_time_t frame_run_time_sum, frame_run_time_avg;
@ -428,12 +441,13 @@ struct netplay
/* Our own device bitmap */
uint32_t self_devices;
/* Number of desync operations we're currently performing. If set, we don't
* attempt to stay in sync. */
/* Number of desync operations we're currently performing.
* If set, we don't attempt to stay in sync. */
uint32_t desync;
/* The device types for every connected device. We store them and ignore any
* menu changes, as netplay needs fixed devices. */
/* The device types for every connected device.
* We store them and ignore any menu changes,
* as netplay needs fixed devices. */
uint32_t config_devices[MAX_INPUT_DEVICES];
struct retro_callbacks cbs;
@ -462,8 +476,9 @@ struct netplay
size_t self_ptr;
uint32_t self_frame_count;
/* The frame we're currently running, which may be behind the frame we're
* currently inputting if we're using input latency */
/* The frame we're currently running, which may be
* behind the frame we're currently inputting if
* we're using input latency */
size_t run_ptr;
uint32_t run_frame_count;
@ -471,10 +486,11 @@ struct netplay
size_t other_ptr;
uint32_t other_frame_count;
/* Pointer to the first frame for which we're missing the data of at least
* one connected player excluding ourself.
* Generally, other_ptr <= unread_ptr <= self_ptr, but unread_ptr can get ahead
* of self_ptr if the peer is running fast. */
/* Pointer to the first frame for which we're missing
* the data of at least one connected player excluding ourself.
* Generally, other_ptr <= unread_ptr <= self_ptr,
* but unread_ptr can get ahead of self_ptr if the peer
* is running fast. */
size_t unread_ptr;
uint32_t unread_frame_count;
@ -482,8 +498,9 @@ struct netplay
size_t read_ptr[MAX_CLIENTS];
uint32_t read_frame_count[MAX_CLIENTS];
/* Pointer to the next frame to read from the server (as it might not be a
* player but still synchronizes) */
/* Pointer to the next frame to read from the server
* (as it might not be a player but still synchronizes)
*/
size_t server_ptr;
uint32_t server_frame_count;
@ -499,7 +516,8 @@ struct netplay
int frame_run_time_ptr;
/* Latency frames; positive to hide network latency, negative to hide input latency */
/* Latency frames; positive to hide network latency,
* negative to hide input latency */
int input_latency_frames;
/* Frequency with which to check CRCs */
@ -525,11 +543,12 @@ struct netplay
bool nat_traversal, nat_traversal_task_oustanding;
/* Set to true if we have a device that most cores translate to "up/down"
* actions, typically a keyboard. We need to keep track of this because with
* such a device, we need to "fix" the input state to the frame BEFORE a
* state load, then perform the state load, and the up/down states will
* proceed as expected */
/* Set to true if we have a device that most cores
* translate to "up/down" actions, typically a keyboard.
* We need to keep track of this because with such a device,
* we need to "fix" the input state to the frame BEFORE a
* state load, then perform the state load, and the
* up/down states will proceed as expected. */
bool have_updown_device;
/* Are we replaying old frames? */
@ -538,8 +557,9 @@ struct netplay
/* We don't want to poll several times on a frame. */
bool can_poll;
/* Force a rewind to other_frame_count/other_ptr. This is for synchronized
* events, such as restarting or savestate loading. */
/* Force a rewind to other_frame_count/other_ptr.
* This is for synchronized events, such as restarting
* or savestate loading. */
bool force_rewind;
/* Force a reset */
@ -554,15 +574,14 @@ struct netplay
/* Have we requested a savestate as a sync point? */
bool savestate_request_outstanding;
/* Netplay pausing */
bool local_paused;
bool remote_paused;
/* If true, never progress without peer input (stateless/rewindless mode) */
/* If true, never progress without peer input
* (stateless/rewindless mode) */
bool stateless_mode;
/* Opposite of stalling, should we be catching up? */
bool catch_up;
@ -589,42 +608,46 @@ struct netplay
*
* Queue the given data for sending.
*/
bool netplay_send(struct socket_buffer *sbuf, int sockfd, const void *buf,
bool netplay_send(struct socket_buffer *sbuf,
int sockfd, const void *buf,
size_t len);
/**
* netplay_send_flush
*
* Flush unsent data in the given socket buffer, blocking to do so if
* requested.
* Flush unsent data in the given socket buffer,
* blocking to do so if requested.
*
* Returns false only on socket failures, true otherwise.
*/
bool netplay_send_flush(struct socket_buffer *sbuf, int sockfd, bool block);
bool netplay_send_flush(struct socket_buffer *sbuf,
int sockfd, bool block);
/**
* netplay_recv
*
* Receive buffered or fresh data.
*
* Returns number of bytes returned, which may be short or 0, or -1 on error.
* Returns number of bytes returned, which may be
* short or 0, or -1 on error.
*/
ssize_t netplay_recv(struct socket_buffer *sbuf, int sockfd, void *buf,
ssize_t netplay_recv(struct socket_buffer *sbuf,
int sockfd, void *buf,
size_t len, bool block);
/**
* netplay_recv_reset
*
* Reset our recv buffer so that future netplay_recvs will read the same data
* again.
* Reset our recv buffer so that future netplay_recvs
* will read the same data again.
*/
void netplay_recv_reset(struct socket_buffer *sbuf);
/**
* netplay_recv_flush
*
* Flush our recv buffer, so a future netplay_recv_reset will reset to this
* point.
* Flush our recv buffer, so a future netplay_recv_reset
* will reset to this point.
*/
void netplay_recv_flush(struct socket_buffer *sbuf);
@ -635,13 +658,14 @@ void netplay_recv_flush(struct socket_buffer *sbuf);
/**
* netplay_delta_frame_ready
*
* Prepares, if possible, a delta frame for input, and reports whether it is
* ready.
* Prepares, if possible, a delta frame for input, and reports
* whether it is ready.
*
* Returns: True if the delta frame is ready for input at the given frame,
* false otherwise.
* Returns: True if the delta frame is ready for input at
* the given frame, false otherwise.
*/
bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta,
bool netplay_delta_frame_ready(netplay_t *netplay,
struct delta_frame *delta,
uint32_t frame);
/**
@ -649,15 +673,18 @@ bool netplay_delta_frame_ready(netplay_t *netplay, struct delta_frame *delta,
*
* Get an input state for a particular client
*/
netplay_input_state_t netplay_input_state_for(netplay_input_state_t *list,
uint32_t client_num, size_t size, bool must_create, bool must_not_create);
netplay_input_state_t netplay_input_state_for(
netplay_input_state_t *list,
uint32_t client_num, size_t size,
bool must_create, bool must_not_create);
/**
* netplay_expected_input_size
*
* Size in words for a given set of devices.
*/
uint32_t netplay_expected_input_size(netplay_t *netplay, uint32_t devices);
uint32_t netplay_expected_input_size(netplay_t *netplay,
uint32_t devices);
/***************************************************************
* NETPLAY-DISCOVERY.C
@ -688,7 +715,8 @@ void input_poll_net(void);
/**
* netplay_handshake_init_send
*
* Initialize our handshake and send the first part of the handshake protocol.
* Initialize our handshake and send the first
* part of the handshake protocol.
*/
bool netplay_handshake_init_send(netplay_t *netplay,
struct netplay_connection *connection);
@ -717,8 +745,8 @@ bool netplay_try_init_serialization(netplay_t *netplay);
/**
* netplay_wait_and_init_serialization
*
* Try very hard to initialize serialization, simulating multiple frames if
* necessary. For quirky cores.
* Try very hard to initialize serialization, simulating
* multiple frames if necessary. For quirky cores.
*
* Returns true if serialization is now ready, false otherwise.
*/
@ -741,9 +769,11 @@ bool netplay_wait_and_init_serialization(netplay_t *netplay);
*
* Returns: new netplay data.
*/
netplay_t *netplay_new(void *direct_host, const char *server, uint16_t port,
netplay_t *netplay_new(void *direct_host,
const char *server, uint16_t port,
bool stateless_mode, int check_frames,
const struct retro_callbacks *cb, bool nat_traversal, const char *nick,
const struct retro_callbacks *cb,
bool nat_traversal, const char *nick,
uint64_t quirks);
/**
@ -763,13 +793,14 @@ void netplay_free(netplay_t *netplay);
*
* Disconnects an active Netplay connection due to an error
*/
void netplay_hangup(netplay_t *netplay, struct netplay_connection *connection);
void netplay_hangup(netplay_t *netplay,
struct netplay_connection *connection);
/**
* netplay_delayed_state_change:
*
* Handle any pending state changes which are ready as of the beginning of the
* current frame.
* Handle any pending state changes which are ready as
* of the beginning of the current frame.
*/
void netplay_delayed_state_change(netplay_t *netplay);
@ -797,7 +828,8 @@ bool netplay_send_raw_cmd(netplay_t *netplay,
/**
* netplay_send_raw_cmd_all
*
* Send a raw Netplay command to all connections, optionally excluding one
* Send a raw Netplay command to all connections,
* optionally excluding one
* (typically the client that the relevant command came from)
*/
void netplay_send_raw_cmd_all(netplay_t *netplay,
@ -807,8 +839,8 @@ void netplay_send_raw_cmd_all(netplay_t *netplay,
/**
* netplay_cmd_mode
*
* Send a mode change request. As a server, the request is to ourself, and so
* honored instantly.
* Send a mode change request. As a server,
* the request is to ourself, and so honored instantly.
*/
bool netplay_cmd_mode(netplay_t *netplay,
enum rarch_netplay_connection_mode mode);
@ -845,26 +877,11 @@ void netplay_init_nat_traversal(netplay_t *netplay);
* NETPLAY-KEYBOARD.C
**************************************************************/
/* The keys supported by netplay */
enum netplay_keys {
NETPLAY_KEY_UNKNOWN = 0,
#define K(k) NETPLAY_KEY_ ## k,
#define KL(k,l) K(k)
#include "netplay_keys.h"
#undef KL
#undef K
NETPLAY_KEY_LAST
};
/* The mapping of keys from netplay (network) to libretro (host) */
extern const uint16_t netplay_key_ntoh_mapping[];
#define NETPLAY_KEY_NTOH(k) (netplay_key_ntoh_mapping[k])
/* The mapping of keys from libretro (host) to netplay (network) */
uint32_t netplay_key_hton(unsigned key);
/* Because the hton keymapping has to be generated, call this before using
* netplay_key_hton */
/* Because the hton keymapping has to be generated,
* call this before using netplay_key_hton */
void netplay_key_hton_init(void);
/***************************************************************
@ -874,8 +891,9 @@ void netplay_key_hton_init(void);
/**
* netplay_update_unread_ptr
*
* Update the global unread_ptr and unread_frame_count to correspond to the
* earliest unread frame count of any connected player
* Update the global unread_ptr and unread_frame_count to
* correspond to the earliest unread frame count of any
* connected player.
*/
void netplay_update_unread_ptr(netplay_t *netplay);
@ -883,14 +901,16 @@ void netplay_update_unread_ptr(netplay_t *netplay);
* netplay_resolve_input
* @netplay : pointer to netplay object
* @sim_ptr : frame pointer for which to resolve input
* @resim : are we resimulating, or simulating this frame for the
* first time?
* @resim : are we resimulating, or simulating this
* frame for the first time?
*
* "Simulate" input by assuming it hasn't changed since the last read input.
* Returns true if the resolved input changed from the last time it was
* resolved.
* "Simulate" input by assuming it hasn't changed since the
* last read input.
* Returns true if the resolved input changed from the
* last time it was resolved.
*/
bool netplay_resolve_input(netplay_t *netplay, size_t sim_ptr, bool resim);
bool netplay_resolve_input(netplay_t *netplay,
size_t sim_ptr, bool resim);
/**
* netplay_sync_pre_frame

View File

@ -35,12 +35,6 @@ enum netplay_parse_state
STATE_END
};
struct netplay_rooms
{
struct netplay_room *head;
struct netplay_room *cur;
};
struct netplay_json_context
{
bool *cur_member_bool;
@ -51,9 +45,6 @@ struct netplay_json_context
enum netplay_parse_state state;
};
/* TODO/FIXME - static global variable */
static struct netplay_rooms *netplay_rooms_data;
static bool netplay_json_boolean(void* ctx, bool value)
{
struct netplay_json_context* p_ctx = (struct netplay_json_context*)ctx;
@ -102,20 +93,21 @@ static bool netplay_json_number(void* ctx, const char *p_value, size_t len)
static bool netplay_json_start_object(void* ctx)
{
struct netplay_json_context *p_ctx = (struct netplay_json_context*)ctx;
net_driver_state_t *net_st = networking_state_get_ptr();
if (p_ctx->state == STATE_FIELDS_START)
{
p_ctx->state = STATE_FIELDS_OBJECT_START;
if (!netplay_rooms_data->head)
if (!net_st->rooms_data->head)
{
netplay_rooms_data->head = (struct netplay_room*)calloc(1, sizeof(*netplay_rooms_data->head));
netplay_rooms_data->cur = netplay_rooms_data->head;
net_st->rooms_data->head = (struct netplay_room*)calloc(1, sizeof(*net_st->rooms_data->head));
net_st->rooms_data->cur = net_st->rooms_data->head;
}
else if (!netplay_rooms_data->cur->next)
else if (!net_st->rooms_data->cur->next)
{
netplay_rooms_data->cur->next = (struct netplay_room*)calloc(1, sizeof(*netplay_rooms_data->cur->next));
netplay_rooms_data->cur = netplay_rooms_data->cur->next;
net_st->rooms_data->cur->next = (struct netplay_room*)calloc(1, sizeof(*net_st->rooms_data->cur->next));
net_st->rooms_data->cur = net_st->rooms_data->cur->next;
}
}
else if (p_ctx->state == STATE_ARRAY_START)
@ -138,6 +130,7 @@ static bool netplay_json_object_member(void *ctx, const char *p_value,
size_t len)
{
struct netplay_json_context* p_ctx = (struct netplay_json_context*)ctx;
net_driver_state_t *net_st = networking_state_get_ptr();
if (!p_value || !len)
return true;
@ -157,81 +150,81 @@ static bool netplay_json_object_member(void *ctx, const char *p_value,
{
if (string_is_equal(p_value, "username"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->nickname;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->nickname);
p_ctx->cur_member_string = net_st->rooms_data->cur->nickname;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->nickname);
}
else if (string_is_equal(p_value, "game_name"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->gamename;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->gamename);
p_ctx->cur_member_string = net_st->rooms_data->cur->gamename;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->gamename);
}
else if (string_is_equal(p_value, "core_name"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->corename;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->corename);
p_ctx->cur_member_string = net_st->rooms_data->cur->corename;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->corename);
}
else if (string_is_equal(p_value, "ip"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->address;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->address);
p_ctx->cur_member_string = net_st->rooms_data->cur->address;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->address);
}
else if (string_is_equal(p_value, "port"))
{
p_ctx->cur_member_int = &netplay_rooms_data->cur->port;
p_ctx->cur_member_int = &net_st->rooms_data->cur->port;
}
else if (string_is_equal(p_value, "game_crc"))
{
p_ctx->cur_member_inthex = &netplay_rooms_data->cur->gamecrc;
p_ctx->cur_member_inthex = &net_st->rooms_data->cur->gamecrc;
}
else if (string_is_equal(p_value, "core_version"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->coreversion;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->coreversion);
p_ctx->cur_member_string = net_st->rooms_data->cur->coreversion;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->coreversion);
}
else if (string_is_equal(p_value, "has_password"))
{
p_ctx->cur_member_bool = &netplay_rooms_data->cur->has_password;
p_ctx->cur_member_bool = &net_st->rooms_data->cur->has_password;
}
else if (string_is_equal(p_value, "has_spectate_password"))
{
p_ctx->cur_member_bool = &netplay_rooms_data->cur->has_spectate_password;
p_ctx->cur_member_bool = &net_st->rooms_data->cur->has_spectate_password;
}
else if (string_is_equal(p_value, "fixed"))
{
p_ctx->cur_member_bool = &netplay_rooms_data->cur->fixed;
p_ctx->cur_member_bool = &net_st->rooms_data->cur->fixed;
}
else if (string_is_equal(p_value, "mitm_ip"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->mitm_address;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->mitm_address);
p_ctx->cur_member_string = net_st->rooms_data->cur->mitm_address;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->mitm_address);
}
else if (string_is_equal(p_value, "mitm_port"))
{
p_ctx->cur_member_int = &netplay_rooms_data->cur->mitm_port;
p_ctx->cur_member_int = &net_st->rooms_data->cur->mitm_port;
}
else if (string_is_equal(p_value, "host_method"))
{
p_ctx->cur_member_int = &netplay_rooms_data->cur->host_method;
p_ctx->cur_member_int = &net_st->rooms_data->cur->host_method;
}
else if (string_is_equal(p_value, "retroarch_version"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->retroarch_version;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->retroarch_version);
p_ctx->cur_member_string = net_st->rooms_data->cur->retroarch_version;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->retroarch_version);
}
else if (string_is_equal(p_value, "country"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->country;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->country);
p_ctx->cur_member_string = net_st->rooms_data->cur->country;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->country);
}
else if (string_is_equal(p_value, "frontend"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->frontend;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->frontend);
p_ctx->cur_member_string = net_st->rooms_data->cur->frontend;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->frontend);
}
else if (string_is_equal(p_value, "subsystem_name"))
{
p_ctx->cur_member_string = netplay_rooms_data->cur->subsystem_name;
p_ctx->cur_member_size = sizeof(netplay_rooms_data->cur->subsystem_name);
p_ctx->cur_member_string = net_st->rooms_data->cur->subsystem_name;
p_ctx->cur_member_size = sizeof(net_st->rooms_data->cur->subsystem_name);
}
}
}
@ -258,9 +251,10 @@ static void netplay_rooms_error(void *context,
void netplay_rooms_free(void)
{
if (netplay_rooms_data)
net_driver_state_t *net_st = networking_state_get_ptr();
if (net_st->rooms_data)
{
struct netplay_room *room = netplay_rooms_data->head;
struct netplay_room *room = net_st->rooms_data->head;
if (room)
{
@ -273,14 +267,15 @@ void netplay_rooms_free(void)
}
}
free(netplay_rooms_data);
free(net_st->rooms_data);
}
netplay_rooms_data = NULL;
net_st->rooms_data = NULL;
}
int netplay_rooms_parse(const char *buf)
{
struct netplay_json_context ctx;
net_driver_state_t *net_st = networking_state_get_ptr();
memset(&ctx, 0, sizeof(ctx));
@ -289,8 +284,8 @@ int netplay_rooms_parse(const char *buf)
/* delete any previous rooms */
netplay_rooms_free();
netplay_rooms_data = (struct netplay_rooms*)
calloc(1, sizeof(*netplay_rooms_data));
net_st->rooms_data = (struct netplay_rooms*)
calloc(1, sizeof(*net_st->rooms_data));
rjson_parse_quick(buf, &ctx, 0,
netplay_json_object_member,
@ -310,7 +305,8 @@ int netplay_rooms_parse(const char *buf)
struct netplay_room* netplay_room_get(int index)
{
int cur = 0;
struct netplay_room *room = netplay_rooms_data->head;
net_driver_state_t *net_st = networking_state_get_ptr();
struct netplay_room *room = net_st->rooms_data->head;
if (index < 0)
return NULL;
@ -330,14 +326,13 @@ struct netplay_room* netplay_room_get(int index)
int netplay_rooms_get_count(void)
{
int count = 0;
struct netplay_room *room;
struct netplay_room *room = NULL;
net_driver_state_t *net_st = networking_state_get_ptr();
if (!netplay_rooms_data)
if (!net_st || !net_st->rooms_data)
return count;
room = netplay_rooms_data->head;
if (!room)
if (!(room = net_st->rooms_data->head))
return count;
while (room)