2018-05-29 04:43:30 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2019-06-16 18:32:27 +00:00
|
|
|
* Copyright (C) 2018-2019 - Andrés Suárez
|
2018-05-29 04:43:30 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-04 22:41:07 +00:00
|
|
|
#include <file/file_path.h>
|
2019-01-19 22:15:48 +00:00
|
|
|
#include <string/stdstring.h>
|
2019-01-19 22:27:59 +00:00
|
|
|
#include <retro_timers.h>
|
2018-05-29 04:43:30 +00:00
|
|
|
|
2018-08-12 16:38:05 +00:00
|
|
|
#include "discord.h"
|
2018-10-14 02:09:19 +00:00
|
|
|
#include "discord_register.h"
|
2018-08-12 16:38:05 +00:00
|
|
|
|
2019-01-19 22:15:48 +00:00
|
|
|
#include "../deps/discord-rpc/include/discord_rpc.h"
|
|
|
|
|
2018-08-12 16:38:05 +00:00
|
|
|
#include "../retroarch.h"
|
2018-10-13 23:17:17 +00:00
|
|
|
#include "../configuration.h"
|
2018-08-12 16:38:05 +00:00
|
|
|
#include "../core.h"
|
|
|
|
#include "../core_info.h"
|
|
|
|
#include "../paths.h"
|
2018-08-15 04:12:47 +00:00
|
|
|
#include "../playlist.h"
|
2019-01-19 22:15:48 +00:00
|
|
|
#include "../verbosity.h"
|
2018-08-12 16:38:05 +00:00
|
|
|
|
2018-05-29 09:14:21 +00:00
|
|
|
#include "../msg_hash.h"
|
2019-01-20 01:17:43 +00:00
|
|
|
#include "../tasks/task_file_transfer.h"
|
2018-05-29 09:14:21 +00:00
|
|
|
|
2018-09-09 21:41:50 +00:00
|
|
|
#ifdef HAVE_NETWORKING
|
|
|
|
#include "../../network/netplay/netplay.h"
|
|
|
|
#include "../../network/netplay/netplay_discovery.h"
|
2018-09-12 04:26:55 +00:00
|
|
|
#include "../../tasks/tasks_internal.h"
|
2018-09-09 21:41:50 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CHEEVOS
|
2019-05-29 17:26:22 +00:00
|
|
|
#include "../cheevos-new/cheevos.h"
|
2018-09-09 21:41:50 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-17 04:50:17 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-10-17 06:08:15 +00:00
|
|
|
#include "../../menu/menu_cbs.h"
|
2018-10-17 04:50:17 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-17 06:08:15 +00:00
|
|
|
#include <net/net_http.h>
|
|
|
|
#include "../network/net_http_special.h"
|
|
|
|
#include "../tasks/tasks_internal.h"
|
2018-10-17 15:28:36 +00:00
|
|
|
#include <streams/file_stream.h>
|
|
|
|
#include <file/file_path.h>
|
|
|
|
#include "../file_path_special.h"
|
2018-10-17 04:50:17 +00:00
|
|
|
|
2019-02-07 22:36:07 +00:00
|
|
|
#include <features/features_cpu.h>
|
|
|
|
|
2018-05-29 08:40:01 +00:00
|
|
|
static int64_t start_time = 0;
|
2018-08-18 07:12:51 +00:00
|
|
|
static int64_t pause_time = 0;
|
2018-09-09 21:41:50 +00:00
|
|
|
static int64_t ellapsed_time = 0;
|
2018-05-29 04:43:30 +00:00
|
|
|
|
2018-05-29 08:40:01 +00:00
|
|
|
static bool discord_ready = false;
|
2018-12-24 20:06:21 +00:00
|
|
|
static bool discord_avatar_ready = false;
|
2018-05-29 08:40:01 +00:00
|
|
|
static unsigned discord_status = 0;
|
2018-05-29 04:43:30 +00:00
|
|
|
|
2019-02-07 22:36:07 +00:00
|
|
|
/* 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
|
|
|
|
*/
|
2018-10-17 04:50:17 +00:00
|
|
|
|
2019-02-07 22:36:07 +00:00
|
|
|
static char user_name[344];
|
|
|
|
static char self_party_id[128];
|
|
|
|
static char peer_party_id[128];
|
|
|
|
|
|
|
|
static char user_avatar[PATH_MAX_LENGTH];
|
2019-02-07 00:01:11 +00:00
|
|
|
static bool connecting = false;
|
|
|
|
|
2018-10-17 06:08:15 +00:00
|
|
|
static char cdn_url[] = "https://cdn.discordapp.com/avatars";
|
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
DiscordRichPresence discord_presence;
|
|
|
|
|
2018-12-24 19:28:36 +00:00
|
|
|
char* discord_get_own_username(void)
|
|
|
|
{
|
2019-02-03 19:10:28 +00:00
|
|
|
if (discord_is_ready())
|
2019-02-02 18:03:23 +00:00
|
|
|
return user_name;
|
|
|
|
return NULL;
|
2018-12-24 19:28:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char* discord_get_own_avatar(void)
|
|
|
|
{
|
2019-02-03 19:10:28 +00:00
|
|
|
if (discord_is_ready())
|
2019-02-02 18:03:23 +00:00
|
|
|
return user_avatar;
|
|
|
|
return NULL;
|
2018-12-24 20:06:21 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
bool discord_avatar_is_ready(void)
|
2018-12-24 20:06:21 +00:00
|
|
|
{
|
2019-01-10 02:13:04 +00:00
|
|
|
/*To-Do: fix-me, prevent lockups in ozone due to unfinished code*/
|
|
|
|
return false;
|
2018-12-24 20:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void discord_avatar_set_ready(bool ready)
|
|
|
|
{
|
|
|
|
discord_avatar_ready = ready;
|
2018-12-24 19:28:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
bool discord_is_ready(void)
|
2018-12-24 19:28:36 +00:00
|
|
|
{
|
|
|
|
return discord_ready;
|
|
|
|
}
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
static bool discord_download_avatar(
|
|
|
|
const char* user_id, const char* avatar_id)
|
2018-10-17 15:32:29 +00:00
|
|
|
{
|
|
|
|
static char url[PATH_MAX_LENGTH];
|
|
|
|
static char url_encoded[PATH_MAX_LENGTH];
|
2018-12-24 20:06:21 +00:00
|
|
|
static char full_path[PATH_MAX_LENGTH];
|
2018-10-17 15:32:29 +00:00
|
|
|
|
|
|
|
static char buf[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
file_transfer_t *transf = NULL;
|
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] user avatar id: %s\n", user_id);
|
2019-02-07 22:36:07 +00:00
|
|
|
|
2018-10-17 15:32:29 +00:00
|
|
|
fill_pathname_application_special(buf,
|
|
|
|
sizeof(buf),
|
|
|
|
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
2018-12-24 20:06:21 +00:00
|
|
|
fill_pathname_join(full_path, buf, avatar_id, sizeof(full_path));
|
|
|
|
strlcpy(user_avatar, avatar_id, sizeof(user_avatar));
|
2018-10-17 15:32:29 +00:00
|
|
|
|
2019-05-30 19:35:08 +00:00
|
|
|
if (path_is_valid(full_path))
|
2018-10-17 15:32:29 +00:00
|
|
|
return true;
|
|
|
|
|
2019-01-09 01:54:52 +00:00
|
|
|
if (string_is_empty(avatar_id))
|
|
|
|
return false;
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
snprintf(url, sizeof(url), "%s/%s/%s.png", cdn_url, user_id, avatar_id);
|
|
|
|
net_http_urlencode_full(url_encoded, url, sizeof(url_encoded));
|
|
|
|
snprintf(buf, sizeof(buf), "%s.png", avatar_id);
|
2018-10-17 15:32:29 +00:00
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
transf = (file_transfer_t*)calloc(1, sizeof(*transf));
|
|
|
|
transf->enum_idx = MENU_ENUM_LABEL_CB_DISCORD_AVATAR;
|
|
|
|
strlcpy(transf->path, buf, sizeof(transf->path));
|
2018-10-17 15:32:29 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] downloading avatar from: %s\n", url_encoded);
|
2019-01-06 16:04:28 +00:00
|
|
|
task_push_http_transfer(url_encoded, true, NULL, cb_generic_download, transf);
|
|
|
|
|
|
|
|
return false;
|
2018-10-17 15:32:29 +00:00
|
|
|
}
|
2019-01-06 16:04:28 +00:00
|
|
|
#endif
|
2018-10-17 15:32:29 +00:00
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
static void handle_discord_ready(const DiscordUser* connectedUser)
|
|
|
|
{
|
2018-12-24 19:28:36 +00:00
|
|
|
strlcpy(user_name, connectedUser->username, sizeof(user_name));
|
2019-01-06 22:44:30 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] connected to user: %s#%s\n",
|
2018-05-29 04:43:30 +00:00
|
|
|
connectedUser->username,
|
2019-02-07 22:36:07 +00:00
|
|
|
connectedUser->discriminator);
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-10-17 15:32:29 +00:00
|
|
|
discord_download_avatar(connectedUser->userId, connectedUser->avatar);
|
2019-01-06 16:04:28 +00:00
|
|
|
#endif
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_discord_disconnected(int errcode, const char* message)
|
|
|
|
{
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] disconnected (%d: %s)\n", errcode, message);
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_discord_error(int errcode, const char* message)
|
|
|
|
{
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] error (%d: %s)\n", errcode, message);
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 07:00:32 +00:00
|
|
|
static void handle_discord_join_cb(retro_task_t *task,
|
|
|
|
void *task_data, void *user_data, const char *err)
|
2019-01-06 22:44:30 +00:00
|
|
|
{
|
|
|
|
struct netplay_room *room;
|
2019-02-07 22:36:07 +00:00
|
|
|
char join_hostname[PATH_MAX_LENGTH];
|
2019-01-06 22:44:30 +00:00
|
|
|
|
|
|
|
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
|
|
|
|
|
|
|
if (!data || err)
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
data->data = (char*)realloc(data->data, data->len + 1);
|
|
|
|
data->data[data->len] = '\0';
|
|
|
|
|
|
|
|
netplay_rooms_parse(data->data);
|
|
|
|
room = netplay_room_get(0);
|
|
|
|
|
|
|
|
if (room)
|
|
|
|
{
|
|
|
|
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
|
|
|
deinit_netplay();
|
|
|
|
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
|
|
|
|
2019-02-07 22:36:07 +00:00
|
|
|
snprintf(join_hostname, sizeof(join_hostname), "%s|%d",
|
2019-07-14 11:06:47 +00:00
|
|
|
room->host_method == NETPLAY_HOST_METHOD_MITM
|
|
|
|
? room->mitm_address : room->address,
|
|
|
|
room->host_method == NETPLAY_HOST_METHOD_MITM
|
|
|
|
? room->mitm_port : room->port);
|
2019-01-06 22:44:30 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] joining lobby at: %s\n", join_hostname);
|
2019-01-06 22:44:30 +00:00
|
|
|
task_push_netplay_crc_scan(room->gamecrc,
|
2019-02-07 22:36:07 +00:00
|
|
|
room->gamename, join_hostname, room->corename, room->subsystem_name);
|
2019-02-07 00:01:11 +00:00
|
|
|
connecting = true;
|
|
|
|
discord_update(DISCORD_PRESENCE_NETPLAY_CLIENT);
|
2019-01-06 22:44:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
RARCH_ERR("%s: %s\n", msg_hash_to_str(MSG_DOWNLOAD_FAILED), err);
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
if (data->data)
|
|
|
|
free(data->data);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user_data)
|
|
|
|
free(user_data);
|
|
|
|
}
|
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
static void handle_discord_join(const char* secret)
|
|
|
|
{
|
2019-01-06 22:44:30 +00:00
|
|
|
char url [2048] = "http://lobby.libretro.com/";
|
2018-09-12 04:26:55 +00:00
|
|
|
static struct string_list *list = NULL;
|
2019-01-06 16:04:28 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] join secret: (%s)\n", secret);
|
2018-09-12 04:26:55 +00:00
|
|
|
list = string_split(secret, "|");
|
|
|
|
|
2019-02-07 22:36:07 +00:00
|
|
|
strlcpy(peer_party_id, list->elems[0].data, sizeof(peer_party_id));
|
|
|
|
strlcat(url, peer_party_id, sizeof(url));
|
2019-01-06 22:44:30 +00:00
|
|
|
strlcat(url, "/", sizeof(url));
|
2018-09-12 04:26:55 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] querying lobby id: %s at %s\n", peer_party_id, url);
|
2019-01-06 22:44:30 +00:00
|
|
|
task_push_http_transfer(url, true, NULL, handle_discord_join_cb, NULL);
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_discord_spectate(const char* secret)
|
|
|
|
{
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] spectate (%s)\n", secret);
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 23:14:19 +00:00
|
|
|
#ifdef HAVE_MENU
|
2018-10-17 04:50:17 +00:00
|
|
|
static void handle_discord_join_response(void *ignore, const char *line)
|
|
|
|
{
|
2018-10-18 20:55:18 +00:00
|
|
|
/* To-Do: needs in-game widgets
|
2018-10-17 04:50:17 +00:00
|
|
|
if (strstr(line, "yes"))
|
|
|
|
Discord_Respond(user_id, DISCORD_REPLY_YES);
|
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
menu_input_dialog_end();
|
2019-07-20 10:43:43 +00:00
|
|
|
retroarch_menu_running_finished(false);
|
2018-10-17 04:50:17 +00:00
|
|
|
#endif
|
2018-10-18 20:55:18 +00:00
|
|
|
*/
|
2018-10-17 04:50:17 +00:00
|
|
|
}
|
2019-07-10 23:14:19 +00:00
|
|
|
#endif
|
2018-10-17 04:50:17 +00:00
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
static void handle_discord_join_request(const DiscordUser* request)
|
|
|
|
{
|
2018-10-17 06:08:15 +00:00
|
|
|
static char url[PATH_MAX_LENGTH];
|
|
|
|
static char url_encoded[PATH_MAX_LENGTH];
|
2018-10-17 15:28:36 +00:00
|
|
|
static char filename[PATH_MAX_LENGTH];
|
2018-11-14 02:59:39 +00:00
|
|
|
char buf[PATH_MAX_LENGTH];
|
2019-01-06 16:04:28 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
menu_input_ctx_line_t line;
|
|
|
|
#endif
|
2018-10-17 06:08:15 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] join request from %s#%s - %s %s\n",
|
2018-05-29 04:43:30 +00:00
|
|
|
request->username,
|
|
|
|
request->discriminator,
|
2018-10-17 06:08:15 +00:00
|
|
|
request->userId,
|
|
|
|
request->avatar);
|
2018-10-17 04:50:17 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_MENU
|
2019-01-06 16:04:28 +00:00
|
|
|
discord_download_avatar(request->userId, request->avatar);
|
|
|
|
/* To-Do: needs in-game widgets
|
2019-07-20 10:43:43 +00:00
|
|
|
retroarch_menu_running();
|
2018-11-14 02:59:39 +00:00
|
|
|
*/
|
2018-10-17 04:50:17 +00:00
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
memset(&line, 0, sizeof(line));
|
|
|
|
snprintf(buf, sizeof(buf), "%s %s?", msg_hash_to_str(MSG_DISCORD_CONNECTION_REQUEST), request->username);
|
|
|
|
line.label = buf;
|
|
|
|
line.label_setting = "no_setting";
|
|
|
|
line.cb = handle_discord_join_response;
|
2018-10-17 04:50:17 +00:00
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
/* To-Do: needs in-game widgets
|
|
|
|
To-Do: bespoke dialog, should show while in-game and have a hotkey to accept
|
|
|
|
To-Do: show avatar of the user connecting
|
2018-10-17 04:50:17 +00:00
|
|
|
if (!menu_input_dialog_start(&line))
|
2019-01-06 16:04:28 +00:00
|
|
|
return;
|
2018-10-18 20:55:18 +00:00
|
|
|
*/
|
2018-10-17 04:50:17 +00:00
|
|
|
#endif
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 09:09:13 +00:00
|
|
|
void discord_update(enum discord_presence presence)
|
2018-05-29 04:43:30 +00:00
|
|
|
{
|
2018-08-18 07:12:51 +00:00
|
|
|
core_info_t *core_info = NULL;
|
|
|
|
|
|
|
|
core_info_get_current_core(&core_info);
|
2018-08-04 22:41:07 +00:00
|
|
|
|
2018-05-29 08:40:01 +00:00
|
|
|
if (!discord_ready)
|
2018-05-29 04:43:30 +00:00
|
|
|
return;
|
2018-08-12 14:33:52 +00:00
|
|
|
|
2018-09-09 21:41:50 +00:00
|
|
|
if (presence == discord_status)
|
2018-05-29 08:40:01 +00:00
|
|
|
return;
|
|
|
|
|
2019-02-07 00:01:11 +00:00
|
|
|
if (!connecting && (presence == DISCORD_PRESENCE_NONE || presence == DISCORD_PRESENCE_MENU))
|
|
|
|
{
|
2018-09-09 21:41:50 +00:00
|
|
|
memset(&discord_presence, 0, sizeof(discord_presence));
|
2019-02-07 22:36:07 +00:00
|
|
|
peer_party_id[0] = '\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
}
|
2018-05-29 04:43:30 +00:00
|
|
|
|
|
|
|
switch (presence)
|
|
|
|
{
|
|
|
|
case DISCORD_PRESENCE_MENU:
|
2019-01-06 16:04:28 +00:00
|
|
|
discord_presence.details = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISCORD_IN_MENU);
|
|
|
|
discord_presence.largeImageKey = "base";
|
2018-08-18 07:12:51 +00:00
|
|
|
discord_presence.largeImageText = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_CORE);
|
|
|
|
discord_presence.instance = 0;
|
2018-05-29 04:43:30 +00:00
|
|
|
break;
|
2018-08-18 07:12:51 +00:00
|
|
|
case DISCORD_PRESENCE_GAME_PAUSED:
|
2019-01-19 22:15:48 +00:00
|
|
|
discord_presence.smallImageKey = "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);
|
|
|
|
pause_time = time(0);
|
|
|
|
ellapsed_time = difftime(time(0), start_time);
|
2018-09-09 21:41:50 +00:00
|
|
|
discord_presence.startTimestamp = pause_time;
|
|
|
|
break;
|
2018-08-18 07:12:51 +00:00
|
|
|
case DISCORD_PRESENCE_GAME:
|
2018-08-12 14:33:52 +00:00
|
|
|
if (core_info)
|
2018-08-04 22:41:07 +00:00
|
|
|
{
|
2019-02-03 23:49:35 +00:00
|
|
|
const char *system_id = core_info->system_id
|
2019-01-06 16:04:28 +00:00
|
|
|
? core_info->system_id : "core";
|
2019-04-12 16:50:27 +00:00
|
|
|
const char *label = NULL;
|
|
|
|
const struct playlist_entry *entry = NULL;
|
2018-08-15 04:12:47 +00:00
|
|
|
playlist_t *current_playlist = playlist_get_cached();
|
|
|
|
|
|
|
|
if (current_playlist)
|
2019-04-12 16:50:27 +00:00
|
|
|
{
|
2018-08-15 04:12:47 +00:00
|
|
|
playlist_get_index_by_path(
|
2019-04-12 16:50:27 +00:00
|
|
|
current_playlist, path_get(RARCH_PATH_CONTENT), &entry);
|
2019-04-21 19:56:40 +00:00
|
|
|
|
|
|
|
if (entry && !string_is_empty(entry->label))
|
|
|
|
label = entry->label;
|
2019-04-12 16:50:27 +00:00
|
|
|
}
|
2018-08-15 04:12:47 +00:00
|
|
|
|
|
|
|
if (!label)
|
2019-04-12 16:50:27 +00:00
|
|
|
label = path_basename(path_get(RARCH_PATH_BASENAME));
|
2018-09-09 21:41:50 +00:00
|
|
|
#if 0
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] current core: %s\n", system_id);
|
|
|
|
RARCH_LOG("[discord] current content: %s\n", label);
|
2018-05-29 08:40:01 +00:00
|
|
|
#endif
|
2018-08-21 14:41:16 +00:00
|
|
|
discord_presence.largeImageKey = system_id;
|
2018-08-20 19:03:06 +00:00
|
|
|
|
2018-08-18 07:12:51 +00:00
|
|
|
if (core_info->display_name)
|
|
|
|
discord_presence.largeImageText = core_info->display_name;
|
|
|
|
|
2018-09-09 21:41:50 +00:00
|
|
|
start_time = time(0);
|
|
|
|
if (pause_time != 0)
|
|
|
|
start_time = time(0) - ellapsed_time;
|
2018-08-18 07:12:51 +00:00
|
|
|
|
2019-01-19 22:15:48 +00:00
|
|
|
pause_time = 0;
|
2018-09-09 21:41:50 +00:00
|
|
|
ellapsed_time = 0;
|
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
discord_presence.smallImageKey = "playing";
|
2019-01-19 22:15:48 +00:00
|
|
|
discord_presence.smallImageText = msg_hash_to_str(
|
|
|
|
MENU_ENUM_LABEL_VALUE_DISCORD_STATUS_PLAYING);
|
2018-09-09 21:41:50 +00:00
|
|
|
discord_presence.startTimestamp = start_time;
|
2019-01-19 22:15:48 +00:00
|
|
|
discord_presence.details = msg_hash_to_str(
|
|
|
|
MENU_ENUM_LABEL_VALUE_DISCORD_IN_GAME);
|
2018-08-18 07:12:51 +00:00
|
|
|
|
2019-01-06 16:04:28 +00:00
|
|
|
discord_presence.state = label;
|
|
|
|
discord_presence.instance = 0;
|
2019-02-06 05:07:24 +00:00
|
|
|
|
2019-02-07 00:01:11 +00:00
|
|
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
|
|
|
|
{
|
2019-02-07 22:36:07 +00:00
|
|
|
peer_party_id[0] = '\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
discord_presence.partyId = NULL;
|
|
|
|
discord_presence.partyMax = 0;
|
|
|
|
discord_presence.partySize = 0;
|
2019-05-29 08:53:26 +00:00
|
|
|
discord_presence.joinSecret = (const char*)'\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
connecting = false;
|
|
|
|
}
|
2018-08-04 22:41:07 +00:00
|
|
|
}
|
2018-05-29 04:43:30 +00:00
|
|
|
break;
|
2018-05-29 09:09:13 +00:00
|
|
|
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
2019-01-06 16:04:28 +00:00
|
|
|
{
|
|
|
|
char join_secret[128];
|
2019-07-14 11:06:47 +00:00
|
|
|
struct netplay_room *room = netplay_get_host_room();
|
|
|
|
if (room->id == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RARCH_LOG("[discord] netplay room details: id=%d"
|
|
|
|
", nick=%s IP=%s port=%d\n",
|
|
|
|
room->id, room->nickname,
|
|
|
|
room->host_method == NETPLAY_HOST_METHOD_MITM
|
|
|
|
? room->mitm_address : room->address,
|
|
|
|
room->host_method == NETPLAY_HOST_METHOD_MITM
|
|
|
|
? room->mitm_port : room->port);
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(self_party_id,
|
|
|
|
sizeof(self_party_id), "%d", room->id);
|
|
|
|
snprintf(join_secret,
|
|
|
|
sizeof(join_secret), "%d|%" PRId64,
|
|
|
|
room->id, cpu_features_get_time_usec());
|
|
|
|
|
|
|
|
discord_presence.joinSecret = strdup(join_secret);
|
|
|
|
#if 0
|
|
|
|
discord_presence.spectateSecret = "SPECSPECSPEC";
|
|
|
|
#endif
|
|
|
|
discord_presence.partyId = strdup(self_party_id);
|
|
|
|
discord_presence.partyMax = 2;
|
|
|
|
discord_presence.partySize = 1;
|
2019-01-06 22:44:30 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] join secret: %s\n", join_secret);
|
|
|
|
RARCH_LOG("[discord] party id: %s\n", self_party_id);
|
2019-01-06 16:04:28 +00:00
|
|
|
}
|
2018-09-09 21:41:50 +00:00
|
|
|
break;
|
2018-05-29 09:09:13 +00:00
|
|
|
case DISCORD_PRESENCE_NETPLAY_CLIENT:
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] party id: %s\n", peer_party_id);
|
2019-02-07 22:36:07 +00:00
|
|
|
discord_presence.partyId = strdup(peer_party_id);
|
2019-02-06 05:07:24 +00:00
|
|
|
break;
|
2019-02-07 00:01:11 +00:00
|
|
|
case DISCORD_PRESENCE_NETPLAY_NETPLAY_STOPPED:
|
|
|
|
{
|
2019-05-26 19:30:14 +00:00
|
|
|
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL) &&
|
2019-02-07 00:01:11 +00:00
|
|
|
!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_CONNECTED, NULL))
|
|
|
|
{
|
2019-02-07 22:36:07 +00:00
|
|
|
peer_party_id[0] = '\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
discord_presence.partyId = NULL;
|
|
|
|
discord_presence.partyMax = 0;
|
|
|
|
discord_presence.partySize = 0;
|
2019-05-29 08:53:26 +00:00
|
|
|
discord_presence.joinSecret = (const char*)'\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
connecting = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DISCORD_PRESENCE_SHUTDOWN:
|
|
|
|
discord_presence.partyId = NULL;
|
|
|
|
discord_presence.partyMax = 0;
|
|
|
|
discord_presence.partySize = 0;
|
2019-05-29 08:53:26 +00:00
|
|
|
discord_presence.joinSecret = (const char*)'\0';
|
2019-02-07 00:01:11 +00:00
|
|
|
connecting = false;
|
2018-09-09 21:41:50 +00:00
|
|
|
default:
|
2018-05-29 04:43:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-08-18 07:12:51 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] updating (%d)\n", presence);
|
2018-08-18 07:12:51 +00:00
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
Discord_UpdatePresence(&discord_presence);
|
2018-09-09 21:41:50 +00:00
|
|
|
discord_status = presence;
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 08:40:01 +00:00
|
|
|
void discord_init(void)
|
2018-05-29 04:43:30 +00:00
|
|
|
{
|
2019-03-03 18:09:21 +00:00
|
|
|
char full_path[PATH_MAX_LENGTH];
|
2019-01-06 16:04:28 +00:00
|
|
|
char command[PATH_MAX_LENGTH];
|
2018-10-13 23:17:17 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2019-01-06 16:04:28 +00:00
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
DiscordEventHandlers handlers;
|
2018-05-29 08:40:01 +00:00
|
|
|
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] initializing ..\n");
|
2018-05-29 08:40:01 +00:00
|
|
|
start_time = time(0);
|
|
|
|
|
2018-05-29 04:43:30 +00:00
|
|
|
memset(&handlers, 0, sizeof(handlers));
|
2018-05-29 08:40:01 +00:00
|
|
|
handlers.ready = handle_discord_ready;
|
2018-05-29 04:43:30 +00:00
|
|
|
handlers.disconnected = handle_discord_disconnected;
|
2018-05-29 08:40:01 +00:00
|
|
|
handlers.errored = handle_discord_error;
|
|
|
|
handlers.joinGame = handle_discord_join;
|
2018-05-29 04:43:30 +00:00
|
|
|
handlers.spectateGame = handle_discord_spectate;
|
2018-05-29 08:40:01 +00:00
|
|
|
handlers.joinRequest = handle_discord_join_request;
|
|
|
|
|
2018-10-14 02:09:19 +00:00
|
|
|
Discord_Initialize(settings->arrays.discord_app_id, &handlers, 0, NULL);
|
2018-05-29 04:43:30 +00:00
|
|
|
|
2019-02-07 06:59:49 +00:00
|
|
|
#ifdef _WIN32
|
2019-03-03 18:09:21 +00:00
|
|
|
GetModuleFileNameA(NULL, full_path, sizeof(full_path));
|
|
|
|
if (strstr(get_retroarch_launch_arguments(), full_path))
|
|
|
|
strlcpy(command, get_retroarch_launch_arguments(), sizeof(command));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path_basedir(full_path);
|
2019-07-14 11:06:47 +00:00
|
|
|
snprintf(command, sizeof(command), "%s%s",
|
|
|
|
full_path, get_retroarch_launch_arguments());
|
2019-03-03 18:09:21 +00:00
|
|
|
}
|
2019-02-07 00:01:11 +00:00
|
|
|
#else
|
2019-07-14 11:06:47 +00:00
|
|
|
snprintf(command, sizeof(command), "sh -c %s",
|
|
|
|
get_retroarch_launch_arguments());
|
2019-02-07 00:01:11 +00:00
|
|
|
#endif
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] registering startup command: %s\n", command);
|
2018-10-17 03:53:42 +00:00
|
|
|
Discord_Register(settings->arrays.discord_app_id, command);
|
2018-12-24 20:06:21 +00:00
|
|
|
discord_ready = true;
|
2018-05-29 04:43:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 08:40:01 +00:00
|
|
|
void discord_shutdown(void)
|
2018-05-29 04:43:30 +00:00
|
|
|
{
|
2019-02-07 22:58:21 +00:00
|
|
|
RARCH_LOG("[discord] shutting down ..\n");
|
2018-05-29 04:43:30 +00:00
|
|
|
Discord_ClearPresence();
|
|
|
|
Discord_Shutdown();
|
|
|
|
discord_ready = false;
|
2018-05-29 08:40:01 +00:00
|
|
|
}
|