mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
[discord] start getting ready for ask-to-join functionality, cleanup some of the mess
This commit is contained in:
parent
2a7a2e7dee
commit
4d0729187f
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -14,6 +14,8 @@
|
|||||||
"*.in": "c",
|
"*.in": "c",
|
||||||
"*.rh": "c",
|
"*.rh": "c",
|
||||||
"array": "c",
|
"array": "c",
|
||||||
|
"file_stream.h": "c",
|
||||||
|
"driver.h": "c"
|
||||||
},
|
},
|
||||||
"C_Cpp.dimInactiveRegions": false,
|
"C_Cpp.dimInactiveRegions": false,
|
||||||
}
|
}
|
11
command.c
11
command.c
@ -98,6 +98,8 @@
|
|||||||
#define DEFAULT_NETWORK_CMD_PORT 55355
|
#define DEFAULT_NETWORK_CMD_PORT 55355
|
||||||
#define STDIN_BUF_SIZE 4096
|
#define STDIN_BUF_SIZE 4096
|
||||||
|
|
||||||
|
extern bool discord_is_inited;
|
||||||
|
|
||||||
enum cmd_source_t
|
enum cmd_source_t
|
||||||
{
|
{
|
||||||
CMD_NONE = 0,
|
CMD_NONE = 0,
|
||||||
@ -1980,6 +1982,15 @@ bool command_event(enum event_command cmd, void *data)
|
|||||||
core_unload_game();
|
core_unload_game();
|
||||||
if (!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
|
if (!rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL))
|
||||||
core_unload();
|
core_unload();
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
if (discord_is_inited)
|
||||||
|
{
|
||||||
|
discord_userdata_t userdata;
|
||||||
|
userdata.status = DISCORD_PRESENCE_MENU;
|
||||||
|
|
||||||
|
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CMD_EVENT_QUIT:
|
case CMD_EVENT_QUIT:
|
||||||
|
@ -25,21 +25,30 @@
|
|||||||
|
|
||||||
#include "../msg_hash.h"
|
#include "../msg_hash.h"
|
||||||
|
|
||||||
static const char* APPLICATION_ID = "475456035851599874";
|
#ifdef HAVE_NETWORKING
|
||||||
|
#include "../../network/netplay/netplay.h"
|
||||||
|
#include "../../network/netplay/netplay_discovery.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_CHEEVOS
|
||||||
|
#include "../cheevos/cheevos.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const char* APPLICATION_ID = "399289711077752833";
|
||||||
static int FrustrationLevel = 0;
|
static int FrustrationLevel = 0;
|
||||||
|
|
||||||
static int64_t start_time = 0;
|
static int64_t start_time = 0;
|
||||||
static int64_t pause_time = 0;
|
static int64_t pause_time = 0;
|
||||||
|
static int64_t ellapsed_time = 0;
|
||||||
|
|
||||||
static bool discord_ready = false;
|
static bool discord_ready = false;
|
||||||
static bool in_menu = false;
|
|
||||||
static unsigned discord_status = 0;
|
static unsigned discord_status = 0;
|
||||||
|
|
||||||
DiscordRichPresence discord_presence;
|
DiscordRichPresence discord_presence;
|
||||||
|
|
||||||
static void handle_discord_ready(const DiscordUser* connectedUser)
|
static void handle_discord_ready(const DiscordUser* connectedUser)
|
||||||
{
|
{
|
||||||
RARCH_LOG("[Discord] connected to user %s#%s - %s\n",
|
RARCH_LOG("[Discord] connected to user: %s#%s - avatar id: %s\n",
|
||||||
connectedUser->username,
|
connectedUser->username,
|
||||||
connectedUser->discriminator,
|
connectedUser->discriminator,
|
||||||
connectedUser->userId);
|
connectedUser->userId);
|
||||||
@ -78,19 +87,17 @@ static void handle_discord_join_request(const DiscordUser* request)
|
|||||||
void discord_update(enum discord_presence presence)
|
void discord_update(enum discord_presence presence)
|
||||||
{
|
{
|
||||||
core_info_t *core_info = NULL;
|
core_info_t *core_info = NULL;
|
||||||
bool skip = false;
|
|
||||||
|
|
||||||
core_info_get_current_core(&core_info);
|
core_info_get_current_core(&core_info);
|
||||||
|
|
||||||
if (!discord_ready)
|
if (!discord_ready)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (
|
if (presence == discord_status)
|
||||||
(discord_status != DISCORD_PRESENCE_MENU) &&
|
|
||||||
(discord_status == presence))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memset(&discord_presence, 0, sizeof(discord_presence));
|
if (presence == DISCORD_PRESENCE_NONE || presence == DISCORD_PRESENCE_MENU)
|
||||||
|
memset(&discord_presence, 0, sizeof(discord_presence));
|
||||||
|
|
||||||
switch (presence)
|
switch (presence)
|
||||||
{
|
{
|
||||||
@ -99,19 +106,15 @@ void discord_update(enum discord_presence presence)
|
|||||||
discord_presence.largeImageKey = "base";
|
discord_presence.largeImageKey = "base";
|
||||||
discord_presence.largeImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
|
discord_presence.largeImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
|
||||||
discord_presence.instance = 0;
|
discord_presence.instance = 0;
|
||||||
|
|
||||||
in_menu = true;
|
|
||||||
break;
|
break;
|
||||||
case DISCORD_PRESENCE_GAME_PAUSED:
|
case DISCORD_PRESENCE_GAME_PAUSED:
|
||||||
discord_presence.smallImageKey = "paused";
|
discord_presence.smallImageKey = "paused";
|
||||||
discord_presence.smallImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_STATUS_PAUSED);
|
discord_presence.smallImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_STATUS_PAUSED);
|
||||||
discord_presence.details = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_IN_GAME_PAUSED);
|
discord_presence.details = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_IN_GAME_PAUSED);
|
||||||
|
|
||||||
pause_time = time(0);
|
pause_time = time(0);
|
||||||
skip = true;
|
ellapsed_time = difftime(time(0), start_time);
|
||||||
|
discord_presence.startTimestamp = pause_time;
|
||||||
if (in_menu)
|
break;
|
||||||
break;
|
|
||||||
case DISCORD_PRESENCE_GAME:
|
case DISCORD_PRESENCE_GAME:
|
||||||
if (core_info)
|
if (core_info)
|
||||||
{
|
{
|
||||||
@ -126,7 +129,7 @@ void discord_update(enum discord_presence presence)
|
|||||||
|
|
||||||
if (!label)
|
if (!label)
|
||||||
label = (char *)path_basename(path_get(RARCH_PATH_BASENAME));
|
label = (char *)path_basename(path_get(RARCH_PATH_BASENAME));
|
||||||
#if 1
|
#if 0
|
||||||
RARCH_LOG("[Discord] current core: %s\n", system_id);
|
RARCH_LOG("[Discord] current core: %s\n", system_id);
|
||||||
RARCH_LOG("[Discord] current content: %s\n", label);
|
RARCH_LOG("[Discord] current content: %s\n", label);
|
||||||
#endif
|
#endif
|
||||||
@ -135,39 +138,40 @@ void discord_update(enum discord_presence presence)
|
|||||||
if (core_info->display_name)
|
if (core_info->display_name)
|
||||||
discord_presence.largeImageText = core_info->display_name;
|
discord_presence.largeImageText = core_info->display_name;
|
||||||
|
|
||||||
if (in_menu)
|
start_time = time(0);
|
||||||
start_time = time(0);
|
if (pause_time != 0)
|
||||||
else
|
start_time = time(0) - ellapsed_time;
|
||||||
start_time = start_time + difftime(time(0), pause_time);
|
|
||||||
|
|
||||||
if (!skip)
|
pause_time = 0;
|
||||||
{
|
ellapsed_time = 0;
|
||||||
discord_presence.smallImageKey = "playing";
|
|
||||||
discord_presence.smallImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_STATUS_PLAYING);
|
discord_presence.smallImageKey = "playing";
|
||||||
discord_presence.startTimestamp = start_time;
|
discord_presence.smallImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_STATUS_PLAYING);
|
||||||
discord_presence.details = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_IN_GAME);
|
discord_presence.startTimestamp = start_time;
|
||||||
}
|
discord_presence.details = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_IN_GAME);
|
||||||
|
|
||||||
discord_presence.state = label;
|
discord_presence.state = label;
|
||||||
discord_presence.instance = 0;
|
discord_presence.instance = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
in_menu = false;
|
|
||||||
break;
|
break;
|
||||||
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
||||||
|
discord_presence.joinSecret = "JOINJOINJOIN";
|
||||||
|
discord_presence.spectateSecret = "SPECSPECSPEC";
|
||||||
|
discord_presence.partyId = "RADIUS";
|
||||||
|
discord_presence.partyMax = 0;
|
||||||
|
discord_presence.partySize = 0;
|
||||||
|
break;
|
||||||
|
case DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED:
|
||||||
case DISCORD_PRESENCE_NETPLAY_CLIENT:
|
case DISCORD_PRESENCE_NETPLAY_CLIENT:
|
||||||
case DISCORD_PRESENCE_CHEEVO_UNLOCKED:
|
default:
|
||||||
/* TODO/FIXME */
|
discord_presence.joinSecret = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_menu && skip)
|
|
||||||
return;
|
|
||||||
|
|
||||||
RARCH_LOG("[Discord] updating (%d)\n", presence);
|
RARCH_LOG("[Discord] updating (%d)\n", presence);
|
||||||
|
|
||||||
Discord_UpdatePresence(&discord_presence);
|
Discord_UpdatePresence(&discord_presence);
|
||||||
discord_status = presence;
|
discord_status = presence;
|
||||||
}
|
}
|
||||||
|
|
||||||
void discord_init(void)
|
void discord_init(void)
|
||||||
@ -197,3 +201,8 @@ void discord_shutdown(void)
|
|||||||
Discord_Shutdown();
|
Discord_Shutdown();
|
||||||
discord_ready = false;
|
discord_ready = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void discord_run_callbacks()
|
||||||
|
{
|
||||||
|
Discord_RunCallbacks();
|
||||||
|
}
|
@ -32,11 +32,13 @@
|
|||||||
|
|
||||||
enum discord_presence
|
enum discord_presence
|
||||||
{
|
{
|
||||||
DISCORD_PRESENCE_MENU = 0,
|
DISCORD_PRESENCE_NONE = 0,
|
||||||
|
DISCORD_PRESENCE_MENU,
|
||||||
DISCORD_PRESENCE_GAME,
|
DISCORD_PRESENCE_GAME,
|
||||||
DISCORD_PRESENCE_GAME_PAUSED,
|
DISCORD_PRESENCE_GAME_PAUSED,
|
||||||
DISCORD_PRESENCE_CHEEVO_UNLOCKED,
|
DISCORD_PRESENCE_CHEEVO_UNLOCKED,
|
||||||
DISCORD_PRESENCE_NETPLAY_HOSTING,
|
DISCORD_PRESENCE_NETPLAY_HOSTING,
|
||||||
|
DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED,
|
||||||
DISCORD_PRESENCE_NETPLAY_CLIENT
|
DISCORD_PRESENCE_NETPLAY_CLIENT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,4 +53,6 @@ void discord_shutdown(void);
|
|||||||
|
|
||||||
void discord_update(enum discord_presence presence);
|
void discord_update(enum discord_presence presence);
|
||||||
|
|
||||||
|
void discord_run_callbacks();
|
||||||
|
|
||||||
#endif /* __RARCH_DISCORD_H */
|
#endif /* __RARCH_DISCORD_H */
|
||||||
|
@ -467,16 +467,17 @@ bool menu_display_libretro(bool is_idle,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
|
||||||
discord_userdata_t userdata;
|
|
||||||
userdata.status = DISCORD_PRESENCE_GAME_PAUSED;
|
|
||||||
|
|
||||||
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (is_idle)
|
if (is_idle)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
discord_userdata_t userdata;
|
||||||
|
userdata.status = DISCORD_PRESENCE_GAME_PAUSED;
|
||||||
|
|
||||||
|
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
|
||||||
|
#endif
|
||||||
return true; /* Maybe return false here
|
return true; /* Maybe return false here
|
||||||
for indication of idleness? */
|
for indication of idleness? */
|
||||||
|
}
|
||||||
return video_driver_cached_frame();
|
return video_driver_cached_frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
#include <net/net_http.h>
|
#include <net/net_http.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
#include <discord/discord.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
|
|
||||||
#include "netplay_discovery.h"
|
#include "netplay_discovery.h"
|
||||||
@ -60,6 +64,10 @@ static bool is_mitm = false;
|
|||||||
|
|
||||||
static bool netplay_disconnect(netplay_t *netplay);
|
static bool netplay_disconnect(netplay_t *netplay);
|
||||||
|
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
extern bool discord_is_inited;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* netplay_is_alive:
|
* netplay_is_alive:
|
||||||
* @netplay : pointer to netplay object
|
* @netplay : pointer to netplay object
|
||||||
@ -1490,6 +1498,14 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
|
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
|
||||||
netplay_enabled = true;
|
netplay_enabled = true;
|
||||||
netplay_is_client = false;
|
netplay_is_client = false;
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
if (discord_is_inited)
|
||||||
|
{
|
||||||
|
discord_userdata_t userdata;
|
||||||
|
userdata.status = DISCORD_PRESENCE_NETPLAY_HOSTING;
|
||||||
|
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
|
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
|
||||||
@ -1499,6 +1515,14 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
|||||||
|
|
||||||
case RARCH_NETPLAY_CTL_DISABLE:
|
case RARCH_NETPLAY_CTL_DISABLE:
|
||||||
netplay_enabled = false;
|
netplay_enabled = false;
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
if (discord_is_inited)
|
||||||
|
{
|
||||||
|
discord_userdata_t userdata;
|
||||||
|
userdata.status = DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED;
|
||||||
|
command_event(CMD_EVENT_DISCORD_UPDATE, &userdata);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
case RARCH_NETPLAY_CTL_IS_ENABLED:
|
case RARCH_NETPLAY_CTL_IS_ENABLED:
|
||||||
|
10
retroarch.c
10
retroarch.c
@ -204,7 +204,7 @@ static retro_bits_t has_set_libretro_device;
|
|||||||
static bool has_set_core = false;
|
static bool has_set_core = false;
|
||||||
static bool has_set_username = false;
|
static bool has_set_username = false;
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
static bool discord_is_inited = false;
|
bool discord_is_inited = false;
|
||||||
#endif
|
#endif
|
||||||
static bool rarch_is_inited = false;
|
static bool rarch_is_inited = false;
|
||||||
static bool rarch_error_on_init = false;
|
static bool rarch_error_on_init = false;
|
||||||
@ -3357,6 +3357,13 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
settings_t *settings = config_get_ptr();
|
settings_t *settings = config_get_ptr();
|
||||||
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
|
unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS));
|
||||||
|
|
||||||
|
if (discord_is_inited)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_DISCORD
|
||||||
|
discord_run_callbacks();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (runloop_frame_time.callback)
|
if (runloop_frame_time.callback)
|
||||||
{
|
{
|
||||||
/* Updates frame timing if frame timing callback is in use by the core.
|
/* Updates frame timing if frame timing callback is in use by the core.
|
||||||
@ -3452,7 +3459,6 @@ int runloop_iterate(unsigned *sleep_ms)
|
|||||||
if (runloop_check_cheevos())
|
if (runloop_check_cheevos())
|
||||||
cheevos_test();
|
cheevos_test();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cheat_manager_apply_retro_cheats() ;
|
cheat_manager_apply_retro_cheats() ;
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
|
Loading…
x
Reference in New Issue
Block a user