mirror of
https://github.com/libretro/RetroArch
synced 2025-04-25 00:02:31 +00:00
Preparations for being able to move discord and networking code
out of retroarch.c
This commit is contained in:
parent
4b95c5dc84
commit
574b850dd7
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
|
||||||
|
#include <discord_rpc.h>
|
||||||
|
#include "../deps/discord-rpc/include/discord_rpc.h"
|
||||||
|
|
||||||
enum discord_presence
|
enum discord_presence
|
||||||
{
|
{
|
||||||
DISCORD_PRESENCE_NONE = 0,
|
DISCORD_PRESENCE_NONE = 0,
|
||||||
@ -41,6 +44,37 @@ typedef struct discord_userdata
|
|||||||
enum discord_presence status;
|
enum discord_presence status;
|
||||||
} discord_userdata_t;
|
} discord_userdata_t;
|
||||||
|
|
||||||
|
/* The Discord API specifies these variables:
|
||||||
|
- userId --------- char[24] - the userId of the player asking to join
|
||||||
|
- username ------- char[344] - the username of the player asking to join
|
||||||
|
- discriminator -- char[8] - the discriminator of the player asking to join
|
||||||
|
- spectateSecret - char[128] - secret used for spectatin matches
|
||||||
|
- joinSecret - char[128] - secret used to join matches
|
||||||
|
- partyId - char[128] - the party you would be joining
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct discord_state
|
||||||
|
{
|
||||||
|
int64_t start_time;
|
||||||
|
int64_t pause_time;
|
||||||
|
int64_t elapsed_time;
|
||||||
|
|
||||||
|
DiscordRichPresence presence; /* int64_t alignment */
|
||||||
|
|
||||||
|
unsigned status;
|
||||||
|
|
||||||
|
char self_party_id[128];
|
||||||
|
char peer_party_id[128];
|
||||||
|
char user_name[344];
|
||||||
|
char user_avatar[344];
|
||||||
|
|
||||||
|
bool ready;
|
||||||
|
bool avatar_ready;
|
||||||
|
bool connecting;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct discord_state discord_state_t;
|
||||||
|
|
||||||
void discord_update(enum discord_presence presence);
|
void discord_update(enum discord_presence presence);
|
||||||
|
|
||||||
bool discord_is_ready(void);
|
bool discord_is_ready(void);
|
||||||
@ -51,4 +85,8 @@ bool discord_avatar_is_ready(void);
|
|||||||
|
|
||||||
char* discord_get_own_avatar(void);
|
char* discord_get_own_avatar(void);
|
||||||
|
|
||||||
|
discord_state_t *discord_state_get_ptr(void);
|
||||||
|
|
||||||
|
void discord_init(const char *discord_app_id, char *args);
|
||||||
|
|
||||||
#endif /* __RARCH_DISCORD_H */
|
#endif /* __RARCH_DISCORD_H */
|
||||||
|
130
retroarch.c
130
retroarch.c
@ -116,8 +116,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
#include <discord_rpc.h>
|
|
||||||
#include "deps/discord-rpc/include/discord_rpc.h"
|
|
||||||
#include "network/discord.h"
|
#include "network/discord.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -177,10 +175,6 @@
|
|||||||
#include "translation_defines.h"
|
#include "translation_defines.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
|
||||||
#include "network/discord.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_NETWORKING
|
#ifdef HAVE_NETWORKING
|
||||||
#include "network/netplay/netplay.h"
|
#include "network/netplay/netplay.h"
|
||||||
#include "network/netplay/netplay_private.h"
|
#include "network/netplay/netplay_private.h"
|
||||||
@ -1284,17 +1278,25 @@ static const void *find_driver_nonempty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
|
#define CDN_URL "https://cdn.discordapp.com/avatars"
|
||||||
|
|
||||||
|
static discord_state_t discord_state_st; /* int64_t alignment */
|
||||||
|
|
||||||
|
discord_state_t *discord_state_get_ptr(void)
|
||||||
|
{
|
||||||
|
return &discord_state_st;
|
||||||
|
}
|
||||||
|
|
||||||
bool discord_is_ready(void)
|
bool discord_is_ready(void)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
return discord_st->ready;
|
return discord_st->ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *discord_get_own_username(struct rarch_state *p_rarch)
|
static char *discord_get_own_username(void)
|
||||||
{
|
{
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
|
|
||||||
if (discord_st->ready)
|
if (discord_st->ready)
|
||||||
return discord_st->user_name;
|
return discord_st->user_name;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1302,8 +1304,7 @@ static char *discord_get_own_username(struct rarch_state *p_rarch)
|
|||||||
|
|
||||||
char *discord_get_own_avatar(void)
|
char *discord_get_own_avatar(void)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
if (discord_st->ready)
|
if (discord_st->ready)
|
||||||
return discord_st->user_avatar;
|
return discord_st->user_avatar;
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1316,8 +1317,7 @@ bool discord_avatar_is_ready(void)
|
|||||||
|
|
||||||
void discord_avatar_set_ready(bool ready)
|
void discord_avatar_set_ready(bool ready)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
discord_st->avatar_ready = ready;
|
discord_st->avatar_ready = ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1332,8 +1332,6 @@ static bool discord_download_avatar(
|
|||||||
static char buf[PATH_MAX_LENGTH];
|
static char buf[PATH_MAX_LENGTH];
|
||||||
file_transfer_t *transf = NULL;
|
file_transfer_t *transf = NULL;
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: User avatar ID: %s\n", user_id);
|
|
||||||
|
|
||||||
fill_pathname_application_special(buf,
|
fill_pathname_application_special(buf,
|
||||||
sizeof(buf),
|
sizeof(buf),
|
||||||
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
||||||
@ -1357,7 +1355,6 @@ static bool discord_download_avatar(
|
|||||||
strlcpy(transf->path, buf, sizeof(transf->path));
|
strlcpy(transf->path, buf, sizeof(transf->path));
|
||||||
transf->user_data = NULL;
|
transf->user_data = NULL;
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: Downloading avatar from: %s\n", url_encoded);
|
|
||||||
task_push_http_transfer_file(url_encoded, true, NULL, cb_generic_download, transf);
|
task_push_http_transfer_file(url_encoded, true, NULL, cb_generic_download, transf);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -1366,16 +1363,10 @@ static bool discord_download_avatar(
|
|||||||
|
|
||||||
static void handle_discord_ready(const DiscordUser* connectedUser)
|
static void handle_discord_ready(const DiscordUser* connectedUser)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
|
|
||||||
strlcpy(discord_st->user_name,
|
strlcpy(discord_st->user_name,
|
||||||
connectedUser->username, sizeof(discord_st->user_name));
|
connectedUser->username, sizeof(discord_st->user_name));
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: Connected to user: %s#%s\n",
|
|
||||||
connectedUser->username,
|
|
||||||
connectedUser->discriminator);
|
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
discord_download_avatar(discord_st,
|
discord_download_avatar(discord_st,
|
||||||
connectedUser->userId, connectedUser->avatar);
|
connectedUser->userId, connectedUser->avatar);
|
||||||
@ -1384,12 +1375,10 @@ static void handle_discord_ready(const DiscordUser* connectedUser)
|
|||||||
|
|
||||||
static void handle_discord_disconnected(int errcode, const char* message)
|
static void handle_discord_disconnected(int errcode, const char* message)
|
||||||
{
|
{
|
||||||
RARCH_LOG("[DISCORD]: Disconnected (%d: %s)\n", errcode, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_discord_error(int errcode, const char* message)
|
static void handle_discord_error(int errcode, const char* message)
|
||||||
{
|
{
|
||||||
RARCH_LOG("[DISCORD]: Error (%d: %s)\n", errcode, message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_discord_join_cb(retro_task_t *task,
|
static void handle_discord_join_cb(retro_task_t *task,
|
||||||
@ -1398,8 +1387,7 @@ static void handle_discord_join_cb(retro_task_t *task,
|
|||||||
char join_hostname[PATH_MAX_LENGTH];
|
char join_hostname[PATH_MAX_LENGTH];
|
||||||
struct netplay_room *room = NULL;
|
struct netplay_room *room = NULL;
|
||||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
|
|
||||||
if (!data || err || !data->data)
|
if (!data || err || !data->data)
|
||||||
goto finish;
|
goto finish;
|
||||||
@ -1417,13 +1405,12 @@ static void handle_discord_join_cb(retro_task_t *task,
|
|||||||
unsigned srv_port = host_method_is_mitm ? room->mitm_port : room->port;
|
unsigned srv_port = host_method_is_mitm ? room->mitm_port : room->port;
|
||||||
|
|
||||||
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
||||||
deinit_netplay(p_rarch);
|
deinit_netplay();
|
||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
||||||
|
|
||||||
snprintf(join_hostname, sizeof(join_hostname), "%s|%d",
|
snprintf(join_hostname, sizeof(join_hostname), "%s|%d",
|
||||||
srv_address, srv_port);
|
srv_address, srv_port);
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: Joining lobby at: %s\n", join_hostname);
|
|
||||||
task_push_netplay_crc_scan(room->gamecrc,
|
task_push_netplay_crc_scan(room->gamecrc,
|
||||||
room->gamename, join_hostname, room->corename, room->subsystem_name);
|
room->gamename, join_hostname, room->corename, room->subsystem_name);
|
||||||
discord_st->connecting = true;
|
discord_st->connecting = true;
|
||||||
@ -1444,22 +1431,18 @@ static void handle_discord_join(const char* secret)
|
|||||||
{
|
{
|
||||||
char url[2048];
|
char url[2048];
|
||||||
struct string_list *list = string_split(secret, "|");
|
struct string_list *list = string_split(secret, "|");
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
|
|
||||||
strlcpy(discord_st->peer_party_id,
|
strlcpy(discord_st->peer_party_id,
|
||||||
list->elems[0].data, sizeof(discord_st->peer_party_id));
|
list->elems[0].data, sizeof(discord_st->peer_party_id));
|
||||||
snprintf(url, sizeof(url), FILE_PATH_LOBBY_LIBRETRO_URL "%s/",
|
snprintf(url, sizeof(url), FILE_PATH_LOBBY_LIBRETRO_URL "%s/",
|
||||||
discord_st->peer_party_id);
|
discord_st->peer_party_id);
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: Querying lobby id: %s at %s\n",
|
|
||||||
discord_st->peer_party_id, url);
|
|
||||||
task_push_http_transfer(url, true, NULL, handle_discord_join_cb, NULL);
|
task_push_http_transfer(url, true, NULL, handle_discord_join_cb, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_discord_spectate(const char* secret)
|
static void handle_discord_spectate(const char* secret)
|
||||||
{
|
{
|
||||||
RARCH_LOG("[DISCORD]: Spectate (%s)\n", secret);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
@ -1485,7 +1468,7 @@ static void handle_discord_join_request(const DiscordUser* request)
|
|||||||
char buf[PATH_MAX_LENGTH];
|
char buf[PATH_MAX_LENGTH];
|
||||||
menu_input_ctx_line_t line;
|
menu_input_ctx_line_t line;
|
||||||
#endif
|
#endif
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
|
|
||||||
RARCH_LOG("[DISCORD]: Join request from %s#%s - %s %s\n",
|
RARCH_LOG("[DISCORD]: Join request from %s#%s - %s %s\n",
|
||||||
request->username,
|
request->username,
|
||||||
@ -1493,8 +1476,7 @@ static void handle_discord_join_request(const DiscordUser* request)
|
|||||||
request->userId,
|
request->userId,
|
||||||
request->avatar);
|
request->avatar);
|
||||||
|
|
||||||
discord_download_avatar(&p_rarch->discord_st,
|
discord_download_avatar(discord_st, request->userId, request->avatar);
|
||||||
request->userId, request->avatar);
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* TODO/FIXME: Needs in-game widgets */
|
/* TODO/FIXME: Needs in-game widgets */
|
||||||
@ -1520,8 +1502,7 @@ static void handle_discord_join_request(const DiscordUser* request)
|
|||||||
|
|
||||||
void discord_update(enum discord_presence presence)
|
void discord_update(enum discord_presence presence)
|
||||||
{
|
{
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
#ifdef HAVE_CHEEVOS
|
#ifdef HAVE_CHEEVOS
|
||||||
char cheevos_richpresence[256];
|
char cheevos_richpresence[256];
|
||||||
#endif
|
#endif
|
||||||
@ -1633,6 +1614,7 @@ void discord_update(enum discord_presence presence)
|
|||||||
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
||||||
{
|
{
|
||||||
char join_secret[128];
|
char join_secret[128];
|
||||||
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
struct netplay_room *room = &p_rarch->netplay_host_room;
|
struct netplay_room *room = &p_rarch->netplay_host_room;
|
||||||
bool host_method_is_mitm = room->host_method == NETPLAY_HOST_METHOD_MITM;
|
bool host_method_is_mitm = room->host_method == NETPLAY_HOST_METHOD_MITM;
|
||||||
const char *srv_address = host_method_is_mitm ? room->mitm_address : room->address;
|
const char *srv_address = host_method_is_mitm ? room->mitm_address : room->address;
|
||||||
@ -1701,10 +1683,6 @@ void discord_update(enum discord_presence presence)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
RARCH_LOG("[DISCORD]: Updating (%d)\n", presence);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Discord_UpdatePresence(&discord_st->presence);
|
Discord_UpdatePresence(&discord_st->presence);
|
||||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
#ifdef DISCORD_DISABLE_IO_THREAD
|
||||||
Discord_UpdateConnection();
|
Discord_UpdateConnection();
|
||||||
@ -1712,15 +1690,14 @@ void discord_update(enum discord_presence presence)
|
|||||||
discord_st->status = presence;
|
discord_st->status = presence;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void discord_init(
|
void discord_init(const char *discord_app_id, char *args)
|
||||||
discord_state_t *discord_st,
|
|
||||||
const char *discord_app_id, char *args)
|
|
||||||
{
|
{
|
||||||
DiscordEventHandlers handlers;
|
DiscordEventHandlers handlers;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char full_path[PATH_MAX_LENGTH];
|
char full_path[PATH_MAX_LENGTH];
|
||||||
#endif
|
#endif
|
||||||
char command[PATH_MAX_LENGTH];
|
char command[PATH_MAX_LENGTH];
|
||||||
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
|
|
||||||
discord_st->start_time = time(0);
|
discord_st->start_time = time(0);
|
||||||
|
|
||||||
@ -1987,7 +1964,7 @@ static void netplay_announce_cb(retro_task_t *task,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void netplay_announce(struct rarch_state *p_rarch)
|
static void netplay_announce(void)
|
||||||
{
|
{
|
||||||
char buf[4600];
|
char buf[4600];
|
||||||
char frontend_architecture[PATH_MAX_LENGTH];
|
char frontend_architecture[PATH_MAX_LENGTH];
|
||||||
@ -2045,7 +2022,7 @@ static void netplay_announce(struct rarch_state *p_rarch)
|
|||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
if (discord_is_ready())
|
if (discord_is_ready())
|
||||||
net_http_urlencode(&username, discord_get_own_username(p_rarch));
|
net_http_urlencode(&username, discord_get_own_username());
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
net_http_urlencode(&username, settings->paths.username);
|
net_http_urlencode(&username, settings->paths.username);
|
||||||
@ -2105,16 +2082,14 @@ static int16_t input_state_net(unsigned port, unsigned device,
|
|||||||
*
|
*
|
||||||
* Returns: true (1) if successful. At present, cannot fail.
|
* Returns: true (1) if successful. At present, cannot fail.
|
||||||
**/
|
**/
|
||||||
static void netplay_disconnect(
|
static void netplay_disconnect(netplay_t *netplay)
|
||||||
struct rarch_state *p_rarch,
|
|
||||||
netplay_t *netplay)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < netplay->connections_size; i++)
|
for (i = 0; i < netplay->connections_size; i++)
|
||||||
netplay_hangup(netplay, &netplay->connections[i]);
|
netplay_hangup(netplay, &netplay->connections[i]);
|
||||||
|
|
||||||
deinit_netplay(p_rarch);
|
deinit_netplay();
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
if (discord_is_inited)
|
if (discord_is_inited)
|
||||||
@ -2137,12 +2112,12 @@ static void netplay_disconnect(
|
|||||||
* if we're stalled or paused
|
* if we're stalled or paused
|
||||||
**/
|
**/
|
||||||
static bool netplay_pre_frame(
|
static bool netplay_pre_frame(
|
||||||
struct rarch_state *p_rarch,
|
|
||||||
bool netplay_public_announce,
|
bool netplay_public_announce,
|
||||||
bool netplay_use_mitm_server,
|
bool netplay_use_mitm_server,
|
||||||
netplay_t *netplay)
|
netplay_t *netplay)
|
||||||
{
|
{
|
||||||
bool sync_stalled = false;
|
bool sync_stalled = false;
|
||||||
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
|
|
||||||
retro_assert(netplay);
|
retro_assert(netplay);
|
||||||
|
|
||||||
@ -2152,7 +2127,7 @@ static bool netplay_pre_frame(
|
|||||||
if (
|
if (
|
||||||
(netplay->is_server || p_rarch->is_mitm) &&
|
(netplay->is_server || p_rarch->is_mitm) &&
|
||||||
(p_rarch->reannounce % 300 == 0))
|
(p_rarch->reannounce % 300 == 0))
|
||||||
netplay_announce(p_rarch);
|
netplay_announce();
|
||||||
}
|
}
|
||||||
/* Make sure that if announcement is turned on mid-game, it gets announced */
|
/* Make sure that if announcement is turned on mid-game, it gets announced */
|
||||||
else
|
else
|
||||||
@ -2198,7 +2173,7 @@ static bool netplay_pre_frame(
|
|||||||
/* If we're disconnected, deinitialize */
|
/* If we're disconnected, deinitialize */
|
||||||
if (!netplay->is_server && !netplay->connections[0].active)
|
if (!netplay->is_server && !netplay->connections[0].active)
|
||||||
{
|
{
|
||||||
netplay_disconnect(p_rarch, netplay);
|
netplay_disconnect(netplay);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2214,8 +2189,10 @@ static bool netplay_pre_frame(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deinit_netplay(struct rarch_state *p_rarch)
|
static void deinit_netplay(void)
|
||||||
{
|
{
|
||||||
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
|
|
||||||
if (p_rarch->netplay_data)
|
if (p_rarch->netplay_data)
|
||||||
{
|
{
|
||||||
netplay_free(p_rarch->netplay_data);
|
netplay_free(p_rarch->netplay_data);
|
||||||
@ -2240,7 +2217,6 @@ static void deinit_netplay(struct rarch_state *p_rarch)
|
|||||||
* Returns: true (1) if successful, otherwise false (0).
|
* Returns: true (1) if successful, otherwise false (0).
|
||||||
**/
|
**/
|
||||||
static bool init_netplay(
|
static bool init_netplay(
|
||||||
struct rarch_state *p_rarch,
|
|
||||||
settings_t *settings,
|
settings_t *settings,
|
||||||
void *direct_host,
|
void *direct_host,
|
||||||
const char *server, unsigned port)
|
const char *server, unsigned port)
|
||||||
@ -2248,6 +2224,7 @@ static bool init_netplay(
|
|||||||
struct retro_callbacks cbs = {0};
|
struct retro_callbacks cbs = {0};
|
||||||
uint64_t serialization_quirks = 0;
|
uint64_t serialization_quirks = 0;
|
||||||
uint64_t quirks = 0;
|
uint64_t quirks = 0;
|
||||||
|
struct rarch_state *p_rarch = &rarch_st;
|
||||||
bool _netplay_is_client = p_rarch->netplay_is_client;
|
bool _netplay_is_client = p_rarch->netplay_is_client;
|
||||||
bool _netplay_enabled = p_rarch->netplay_enabled;
|
bool _netplay_enabled = p_rarch->netplay_enabled;
|
||||||
|
|
||||||
@ -2289,7 +2266,7 @@ static bool init_netplay(
|
|||||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||||
|
|
||||||
if (settings->bools.netplay_public_announce)
|
if (settings->bools.netplay_public_announce)
|
||||||
netplay_announce(p_rarch);
|
netplay_announce();
|
||||||
}
|
}
|
||||||
|
|
||||||
p_rarch->netplay_data = (netplay_t*)netplay_new(
|
p_rarch->netplay_data = (netplay_t*)netplay_new(
|
||||||
@ -2310,8 +2287,8 @@ static bool init_netplay(
|
|||||||
&cbs,
|
&cbs,
|
||||||
settings->bools.netplay_nat_traversal && !settings->bools.netplay_use_mitm_server,
|
settings->bools.netplay_nat_traversal && !settings->bools.netplay_use_mitm_server,
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
discord_get_own_username(p_rarch)
|
discord_get_own_username()
|
||||||
? discord_get_own_username(p_rarch)
|
? discord_get_own_username()
|
||||||
:
|
:
|
||||||
#endif
|
#endif
|
||||||
settings->paths.username,
|
settings->paths.username,
|
||||||
@ -2424,10 +2401,10 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
netplay_post_frame(netplay);
|
netplay_post_frame(netplay);
|
||||||
/* If we're disconnected, deinitialize */
|
/* If we're disconnected, deinitialize */
|
||||||
if (!netplay->is_server && !netplay->connections[0].active)
|
if (!netplay->is_server && !netplay->connections[0].active)
|
||||||
netplay_disconnect(p_rarch, netplay);
|
netplay_disconnect(netplay);
|
||||||
break;
|
break;
|
||||||
case RARCH_NETPLAY_CTL_PRE_FRAME:
|
case RARCH_NETPLAY_CTL_PRE_FRAME:
|
||||||
ret = netplay_pre_frame(p_rarch,
|
ret = netplay_pre_frame(
|
||||||
settings->bools.netplay_public_announce,
|
settings->bools.netplay_public_announce,
|
||||||
settings->bools.netplay_use_mitm_server,
|
settings->bools.netplay_use_mitm_server,
|
||||||
netplay);
|
netplay);
|
||||||
@ -2452,7 +2429,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
case RARCH_NETPLAY_CTL_DISCONNECT:
|
case RARCH_NETPLAY_CTL_DISCONNECT:
|
||||||
ret = true;
|
ret = true;
|
||||||
if (netplay)
|
if (netplay)
|
||||||
netplay_disconnect(p_rarch, netplay);
|
netplay_disconnect(netplay);
|
||||||
goto done;
|
goto done;
|
||||||
case RARCH_NETPLAY_CTL_FINISHED_NAT_TRAVERSAL:
|
case RARCH_NETPLAY_CTL_FINISHED_NAT_TRAVERSAL:
|
||||||
netplay->nat_traversal_task_oustanding = false;
|
netplay->nat_traversal_task_oustanding = false;
|
||||||
@ -7001,7 +6978,7 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_GAME_WATCH, NULL);
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_GAME_WATCH, NULL);
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_NETPLAY_DEINIT:
|
case CMD_EVENT_NETPLAY_DEINIT:
|
||||||
deinit_netplay(p_rarch);
|
deinit_netplay();
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_NETWORK_INIT:
|
case CMD_EVENT_NETWORK_INIT:
|
||||||
network_init();
|
network_init();
|
||||||
@ -7015,7 +6992,7 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
|
|
||||||
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
|
command_event(CMD_EVENT_NETPLAY_DEINIT, NULL);
|
||||||
|
|
||||||
if (!init_netplay(p_rarch,
|
if (!init_netplay(
|
||||||
settings,
|
settings,
|
||||||
NULL,
|
NULL,
|
||||||
hostname
|
hostname
|
||||||
@ -7054,7 +7031,6 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
: netplay_port);
|
: netplay_port);
|
||||||
|
|
||||||
if (!init_netplay(
|
if (!init_netplay(
|
||||||
p_rarch,
|
|
||||||
settings,
|
settings,
|
||||||
NULL,
|
NULL,
|
||||||
hostname->elems[0].data,
|
hostname->elems[0].data,
|
||||||
@ -7583,29 +7559,26 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
{
|
{
|
||||||
bool discord_enable = settings ? settings->bools.discord_enable : false;
|
bool discord_enable = settings ? settings->bools.discord_enable : false;
|
||||||
const char *discord_app_id = settings ? settings->arrays.discord_app_id : NULL;
|
const char *discord_app_id = settings ? settings->arrays.discord_app_id : NULL;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
|
|
||||||
if (!settings)
|
if (!settings)
|
||||||
return false;
|
return false;
|
||||||
if (!discord_enable)
|
if (!discord_enable)
|
||||||
return false;
|
return false;
|
||||||
if (discord_st->ready)
|
if (discord_st->ready)
|
||||||
return true;
|
return true;
|
||||||
discord_init(discord_st,
|
discord_init(discord_app_id, p_rarch->launch_arguments);
|
||||||
discord_app_id,
|
|
||||||
p_rarch->launch_arguments);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_DISCORD_UPDATE:
|
case CMD_EVENT_DISCORD_UPDATE:
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
discord_userdata_t *userdata = NULL;
|
||||||
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
if (!data || !discord_st->ready)
|
if (!data || !discord_st->ready)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
discord_userdata_t *userdata = (discord_userdata_t*)data;
|
userdata = (discord_userdata_t*)data;
|
||||||
|
|
||||||
if (discord_st->ready)
|
if (discord_st->ready)
|
||||||
discord_update(userdata->status);
|
discord_update(userdata->status);
|
||||||
#endif
|
#endif
|
||||||
@ -17924,8 +17897,7 @@ bool retroarch_main_quit(void)
|
|||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
struct rarch_state *p_rarch = &rarch_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
|
||||||
if (discord_is_inited)
|
if (discord_is_inited)
|
||||||
{
|
{
|
||||||
discord_userdata_t userdata;
|
discord_userdata_t userdata;
|
||||||
@ -19284,10 +19256,8 @@ int runloop_iterate(void)
|
|||||||
bool cheevos_enable = settings->bools.cheevos_enable;
|
bool cheevos_enable = settings->bools.cheevos_enable;
|
||||||
#endif
|
#endif
|
||||||
bool audio_sync = settings->bools.audio_sync;
|
bool audio_sync = settings->bools.audio_sync;
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
discord_state_t *discord_st = &p_rarch->discord_st;
|
discord_state_t *discord_st = &discord_state_st;
|
||||||
|
|
||||||
if (discord_is_inited)
|
if (discord_is_inited)
|
||||||
{
|
{
|
||||||
|
@ -122,8 +122,6 @@ input_st->bsv_movie_state.eof_exit)
|
|||||||
old_pressed3 = pressed3; \
|
old_pressed3 = pressed3; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CDN_URL "https://cdn.discordapp.com/avatars"
|
|
||||||
|
|
||||||
#ifdef HAVE_DYNAMIC
|
#ifdef HAVE_DYNAMIC
|
||||||
#define SYMBOL(x) do { \
|
#define SYMBOL(x) do { \
|
||||||
function_t func = dylib_proc(lib_handle_local, #x); \
|
function_t func = dylib_proc(lib_handle_local, #x); \
|
||||||
@ -488,45 +486,9 @@ enum
|
|||||||
RA_OPT_LOAD_MENU_ON_ERROR
|
RA_OPT_LOAD_MENU_ON_ERROR
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
|
||||||
/* The Discord API specifies these variables:
|
|
||||||
- userId --------- char[24] - the userId of the player asking to join
|
|
||||||
- username ------- char[344] - the username of the player asking to join
|
|
||||||
- discriminator -- char[8] - the discriminator of the player asking to join
|
|
||||||
- spectateSecret - char[128] - secret used for spectatin matches
|
|
||||||
- joinSecret - char[128] - secret used to join matches
|
|
||||||
- partyId - char[128] - the party you would be joining
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct discord_state
|
|
||||||
{
|
|
||||||
int64_t start_time;
|
|
||||||
int64_t pause_time;
|
|
||||||
int64_t elapsed_time;
|
|
||||||
|
|
||||||
DiscordRichPresence presence; /* int64_t alignment */
|
|
||||||
|
|
||||||
unsigned status;
|
|
||||||
|
|
||||||
char self_party_id[128];
|
|
||||||
char peer_party_id[128];
|
|
||||||
char user_name[344];
|
|
||||||
char user_avatar[344];
|
|
||||||
|
|
||||||
bool ready;
|
|
||||||
bool avatar_ready;
|
|
||||||
bool connecting;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct discord_state discord_state_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct rarch_state
|
struct rarch_state
|
||||||
{
|
{
|
||||||
struct global g_extern; /* retro_time_t alignment */
|
struct global g_extern; /* retro_time_t alignment */
|
||||||
#ifdef HAVE_DISCORD
|
|
||||||
discord_state_t discord_st; /* int64_t alignment */
|
|
||||||
#endif
|
|
||||||
struct retro_camera_callback camera_cb; /* uint64_t alignment */
|
struct retro_camera_callback camera_cb; /* uint64_t alignment */
|
||||||
|
|
||||||
const camera_driver_t *camera_driver;
|
const camera_driver_t *camera_driver;
|
||||||
|
@ -30,7 +30,7 @@ static bool is_narrator_running(struct rarch_state *p_rarch, bool accessibility_
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_NETWORKING
|
#ifdef HAVE_NETWORKING
|
||||||
static void deinit_netplay(struct rarch_state *p_rarch);
|
static void deinit_netplay(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void retroarch_deinit_drivers(struct rarch_state *p_rarch,
|
static void retroarch_deinit_drivers(struct rarch_state *p_rarch,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user