diff --git a/.vscode/settings.json b/.vscode/settings.json index 95dbc02f0b..9740a3edac 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,7 +56,14 @@ "menu_animation.h": "c", "audio_driver.h": "c", "netplay.h": "c", - "scaler.h": "c" + "scaler.h": "c", + "deque": "c", + "vector": "c", + "xhash": "c", + "xiosbase": "c", + "xstring": "c", + "xtree": "c", + "xutility": "c" }, "C_Cpp.dimInactiveRegions": false, } \ No newline at end of file diff --git a/command.c b/command.c index a41e87b9a1..5aaf5c674e 100644 --- a/command.c +++ b/command.c @@ -1849,7 +1849,7 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_LOAD_CORE: { - bool success = false; + bool success = false; subsystem_current_count = 0; content_clear_subsystem(); success = command_event(CMD_EVENT_LOAD_CORE_PERSIST, NULL); @@ -1976,18 +1976,19 @@ bool command_event(enum event_command cmd, void *data) if (!task_push_start_dummy_core(&content_info)) return false; } -#ifdef HAVE_DYNAMIC - path_clear(RARCH_PATH_CORE); - rarch_ctl(RARCH_CTL_SYSTEM_INFO_FREE, NULL); -#endif #ifdef HAVE_DISCORD if (discord_is_inited) { discord_userdata_t userdata; + userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); userdata.status = DISCORD_PRESENCE_MENU; - command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); } +#endif +#ifdef HAVE_DYNAMIC + path_clear(RARCH_PATH_CORE); + rarch_ctl(RARCH_CTL_SYSTEM_INFO_FREE, NULL); #endif if (is_inited) { @@ -2623,13 +2624,14 @@ TODO: Add a setting for these tweaks */ { /* buf is expected to be address|port */ char *buf = (char *)data; + RARCH_LOG("[netplay] buf %s\n", buf); static struct string_list *hostname = NULL; settings_t *settings = config_get_ptr(); hostname = string_split(buf, "|"); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); - RARCH_LOG("[netplay] connecting to %s:%d\n", + RARCH_LOG("[netplay] connecting to %s:%d (direct)\n", hostname->elems[0].data, !string_is_empty(hostname->elems[1].data) ? atoi(hostname->elems[1].data) : settings->uints.netplay_port); @@ -2657,13 +2659,14 @@ TODO: Add a setting for these tweaks */ { /* buf is expected to be address|port */ char *buf = (char *)data; + RARCH_LOG("[netplay] buf %s\n", buf); static struct string_list *hostname = NULL; settings_t *settings = config_get_ptr(); hostname = string_split(buf, "|"); command_event(CMD_EVENT_NETPLAY_DEINIT, NULL); - RARCH_LOG("[netplay] connecting to %s:%d\n", + RARCH_LOG("[netplay] connecting to %s:%d (deferred)\n", hostname->elems[0].data, !string_is_empty(hostname->elems[1].data) ? atoi(hostname->elems[1].data) : settings->uints.netplay_port); diff --git a/deps/discord-rpc/src/discord_register_linux.cpp b/deps/discord-rpc/src/discord_register_linux.cpp index 09911dcc6c..4e31ad2290 100644 --- a/deps/discord-rpc/src/discord_register_linux.cpp +++ b/deps/discord-rpc/src/discord_register_linux.cpp @@ -43,7 +43,7 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const const char* destopFileFormat = "[Desktop Entry]\n" "Name=Game %s\n" - "Exec=%s %%u\n" // note: it really wants that %u in there + "Exec=%s\n" // note: it really wants that %u in there "Type=Application\n" "NoDisplay=true\n" "Categories=Discord;Games;\n" diff --git a/discord/discord.c b/discord/discord.c index c27296408d..7a34156c1e 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -68,8 +68,11 @@ struct netplay_room *room; static char user_id[128]; static char user_name[128]; static char party_name[128]; +static char client_party_name[128]; static char user_avatar[PATH_MAX_LENGTH]; +static bool connecting = false; + static char cdn_url[] = "https://cdn.discordapp.com/avatars"; DiscordRichPresence discord_presence; @@ -198,6 +201,8 @@ static void handle_discord_join_cb(retro_task_t *task, void *task_data, void *us RARCH_LOG("[Discord] joining lobby at: %s\n", tmp_hostname); task_push_netplay_crc_scan(room->gamecrc, room->gamename, tmp_hostname, room->corename, room->subsystem_name); + connecting = true; + discord_update(DISCORD_PRESENCE_NETPLAY_CLIENT); } finish: @@ -225,11 +230,9 @@ static void handle_discord_join(const char* secret) RARCH_LOG("[Discord] join secret: (%s)\n", secret); list = string_split(secret, "|"); - strlcpy(party_name, list->elems[1].data, sizeof(party_name)); - strlcat(party_name, "|", sizeof(party_name)); - strlcat(party_name, list->elems[2].data, sizeof(party_name)); - discord_update(DISCORD_PRESENCE_NETPLAY_CLIENT); - + strlcpy(client_party_name, list->elems[1].data, sizeof(client_party_name)); + strlcat(client_party_name, "|", sizeof(client_party_name)); + strlcat(client_party_name, list->elems[2].data, sizeof(client_party_name)); strlcat(url, list->elems[0].data, sizeof(url)); strlcat(url, "/", sizeof(url)); @@ -309,8 +312,11 @@ void discord_update(enum discord_presence presence) if (presence == discord_status) return; - if (presence == DISCORD_PRESENCE_NONE || presence == DISCORD_PRESENCE_MENU) + if (!connecting && (presence == DISCORD_PRESENCE_NONE || presence == DISCORD_PRESENCE_MENU)) + { memset(&discord_presence, 0, sizeof(discord_presence)); + client_party_name[0] = '\0'; + } switch (presence) { @@ -370,9 +376,14 @@ void discord_update(enum discord_presence presence) discord_presence.state = label; discord_presence.instance = 0; - if (!string_is_empty(party_name)) - discord_presence.partyId = strdup(party_name); - + if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL)) + { + client_party_name[0] = '\0'; + discord_presence.partyId = NULL; + discord_presence.partyMax = 0; + discord_presence.partySize = 0; + connecting = false; + } } break; case DISCORD_PRESENCE_NETPLAY_HOSTING: @@ -399,12 +410,28 @@ void discord_update(enum discord_presence presence) } break; case DISCORD_PRESENCE_NETPLAY_CLIENT: - RARCH_LOG("[Discord] party id: %s\n", party_name); - discord_presence.partyId = strdup(party_name); + RARCH_LOG("[Discord] party id: %s\n", client_party_name); + discord_presence.partyId = strdup(client_party_name); break; - case DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED: + case DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED: + { + if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) && + !netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_CONNECTED, NULL)) + { + client_party_name[0] = '\0'; + discord_presence.partyId = NULL; + discord_presence.partyMax = 0; + discord_presence.partySize = 0; + connecting = false; + } + } + break; + case DISCORD_PRESENCE_SHUTDOWN: + discord_presence.partyId = NULL; + discord_presence.partyMax = 0; + discord_presence.partySize = 0; + connecting = false; default: - discord_presence.joinSecret = NULL; break; } @@ -434,7 +461,11 @@ void discord_init(void) Discord_Initialize(settings->arrays.discord_app_id, &handlers, 0, NULL); +#ifdef _WIN32) strlcpy(command, get_retroarch_launch_arguments(), sizeof(command)); +#else + snprintf(command, sizeof(command), "sh -c %s", get_retroarch_launch_arguments()); +#endif RARCH_LOG("[Discord] registering startup command: %s\n", command); Discord_Register(settings->arrays.discord_app_id, command); diff --git a/discord/discord.h b/discord/discord.h index 3b0f8d693d..f0eefb2db0 100644 --- a/discord/discord.h +++ b/discord/discord.h @@ -31,8 +31,9 @@ enum discord_presence DISCORD_PRESENCE_GAME_PAUSED, DISCORD_PRESENCE_CHEEVO_UNLOCKED, DISCORD_PRESENCE_NETPLAY_HOSTING, - DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED, - DISCORD_PRESENCE_NETPLAY_CLIENT + DISCORD_PRESENCE_NETPLAY_CLIENT, + DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED, + DISCORD_PRESENCE_SHUTDOWN }; typedef struct discord_userdata diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index 4dc333e80d..63b15b614f 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -1413,6 +1413,15 @@ static bool netplay_disconnect(netplay_t *netplay) netplay_hangup(netplay, &netplay->connections[i]); deinit_netplay(); + +#ifdef HAVE_DISCORD + if (discord_is_inited) + { + discord_userdata_t userdata; + userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); + } +#endif return true; } @@ -1554,7 +1563,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data) if (discord_is_inited) { discord_userdata_t userdata; - userdata.status = DISCORD_PRESENCE_NETPLAY_HOSTING_STOPPED; + userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED; command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); } #endif diff --git a/network/netplay/netplay_io.c b/network/netplay/netplay_io.c index 1601ca95c5..63a4a8fd2a 100644 --- a/network/netplay/netplay_io.c +++ b/network/netplay/netplay_io.c @@ -26,8 +26,13 @@ #include "../../configuration.h" #include "../../retroarch.h" +#include "../../command.h" #include "../../tasks/tasks_internal.h" +#include "../../discord/discord.h" + +extern bool discord_is_inited; + static void handle_play_spectate(netplay_t *netplay, uint32_t client_num, struct netplay_connection *connection, uint32_t cmd, uint32_t cmd_size, uint32_t *payload); @@ -115,6 +120,14 @@ void netplay_hangup(netplay_t *netplay, struct netplay_connection *connection) else { dmsg = msg_hash_to_str(MSG_NETPLAY_CLIENT_HANGUP); +#ifdef HAVE_DISCORD + if (discord_is_inited) + { + discord_userdata_t userdata; + userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); + } +#endif netplay->is_connected = false; } RARCH_LOG("[netplay] %s\n", dmsg); diff --git a/retroarch.c b/retroarch.c index 3183464fdd..dd8f098043 100644 --- a/retroarch.c +++ b/retroarch.c @@ -682,6 +682,7 @@ static void retroarch_parse_input_and_config(int argc, char *argv[]) strlcat(launch_arguments, " ", sizeof(launch_arguments)); } string_trim_whitespace_left(launch_arguments); + string_trim_whitespace_right(launch_arguments); /* Handling the core type is finicky. Based on the arguments we pass in, * we handle it differently. @@ -2407,6 +2408,18 @@ void retroarch_fail(int error_code, const char *error) bool retroarch_main_quit(void) { + +#ifdef HAVE_DISCORD + if (discord_is_inited) + { + discord_userdata_t userdata; + userdata.status = DISCORD_PRESENCE_SHUTDOWN; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); + } + command_event(CMD_EVENT_DISCORD_DEINIT, NULL); + discord_is_inited = false; +#endif + if (!rarch_ctl(RARCH_CTL_IS_SHUTDOWN, NULL)) { command_event(CMD_EVENT_AUTOSAVE_STATE, NULL); @@ -2418,11 +2431,6 @@ bool retroarch_main_quit(void) rarch_ctl(RARCH_CTL_SET_SHUTDOWN, NULL); rarch_menu_running_finished(); -#ifdef HAVE_DISCORD - command_event(CMD_EVENT_DISCORD_DEINIT, NULL); - discord_is_inited = false; -#endif - return true; } diff --git a/tasks/task_content.c b/tasks/task_content.c index cb111a310c..616e381c44 100644 --- a/tasks/task_content.c +++ b/tasks/task_content.c @@ -100,8 +100,12 @@ #include "../paths.h" #include "../verbosity.h" +#include "../discord/discord.h" + #include "task_patch.c" +extern bool discord_is_inited; + #define MAX_ARGS 32 typedef struct content_stream content_stream_t; @@ -1708,6 +1712,17 @@ static bool task_load_content_callback(content_ctx_info_t *content_info, if (firmware_update_status(&content_ctx)) goto end; +#ifdef HAVE_DISCORD + if (discord_is_inited) + { + discord_userdata_t userdata; + userdata.status = DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); + userdata.status = DISCORD_PRESENCE_MENU; + command_event(CMD_EVENT_DISCORD_UPDATE, &userdata); + } +#endif + ret = task_load_content(content_info, &content_ctx, true, loading_from_cli, &error_string); end: