mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
[discord] rewrite secret, party_id
[discord] rewrite secret, party_id [discord] rewrite secret, party_id [discord] rewrite secret, party_id
This commit is contained in:
parent
c1415d70f8
commit
f60923c4a9
2
Makefile
2
Makefile
@ -96,7 +96,7 @@ endif
|
||||
|
||||
DEF_FLAGS += -Wall $(INCLUDE_DIRS) -I. -Ideps -Ideps/stb
|
||||
|
||||
CFLAGS += $(DEF_FLAGS)
|
||||
CFLAGS += $(DEF_FLAGS) -Wformat-truncation
|
||||
CXXFLAGS += $(DEF_FLAGS) -std=c++11 -D__STDC_CONSTANT_MACROS
|
||||
OBJCFLAGS := $(CFLAGS) -D__STDC_CONSTANT_MACROS
|
||||
|
||||
|
@ -55,6 +55,8 @@
|
||||
#include <file/file_path.h>
|
||||
#include "../file_path_special.h"
|
||||
|
||||
#include <features/features_cpu.h>
|
||||
|
||||
static int64_t start_time = 0;
|
||||
static int64_t pause_time = 0;
|
||||
static int64_t ellapsed_time = 0;
|
||||
@ -65,12 +67,21 @@ static unsigned discord_status = 0;
|
||||
|
||||
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];
|
||||
/* 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
|
||||
*/
|
||||
|
||||
static char user_id[24];
|
||||
static char user_name[344];
|
||||
static char self_party_id[128];
|
||||
static char peer_party_id[128];
|
||||
|
||||
static char user_avatar[PATH_MAX_LENGTH];
|
||||
static bool connecting = false;
|
||||
|
||||
static char cdn_url[] = "https://cdn.discordapp.com/avatars";
|
||||
@ -119,6 +130,8 @@ static bool discord_download_avatar(
|
||||
|
||||
file_transfer_t *transf = NULL;
|
||||
|
||||
RARCH_LOG("[Discord] user avatar id: %s\n", user_id);
|
||||
|
||||
fill_pathname_application_special(buf,
|
||||
sizeof(buf),
|
||||
APPLICATION_SPECIAL_DIRECTORY_THUMBNAILS_DISCORD_AVATARS);
|
||||
@ -149,14 +162,11 @@ static bool discord_download_avatar(
|
||||
static void handle_discord_ready(const DiscordUser* connectedUser)
|
||||
{
|
||||
strlcpy(user_name, connectedUser->username, sizeof(user_name));
|
||||
strlcpy(party_name, connectedUser->username, sizeof(user_name));
|
||||
strlcat(party_name, "|", sizeof(party_name));
|
||||
strlcat(party_name, connectedUser->discriminator, sizeof(party_name));
|
||||
|
||||
RARCH_LOG("[Discord] connected to user: %s#%s - avatar id: %s\n",
|
||||
RARCH_LOG("[Discord] connected to user: %s#%s\n",
|
||||
connectedUser->username,
|
||||
connectedUser->discriminator,
|
||||
connectedUser->userId);
|
||||
connectedUser->discriminator);
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
discord_download_avatar(connectedUser->userId, connectedUser->avatar);
|
||||
#endif
|
||||
@ -175,7 +185,7 @@ static void handle_discord_error(int errcode, const char* message)
|
||||
static void handle_discord_join_cb(retro_task_t *task, void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
struct netplay_room *room;
|
||||
char tmp_hostname[32];
|
||||
char join_hostname[PATH_MAX_LENGTH];
|
||||
|
||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||
|
||||
@ -194,13 +204,13 @@ static void handle_discord_join_cb(retro_task_t *task, void *task_data, void *us
|
||||
deinit_netplay();
|
||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
||||
|
||||
snprintf(tmp_hostname, sizeof(tmp_hostname), "%s|%d",
|
||||
snprintf(join_hostname, sizeof(join_hostname), "%s|%d",
|
||||
room->host_method == NETPLAY_HOST_METHOD_MITM ? room->mitm_address : room->address,
|
||||
room->host_method == NETPLAY_HOST_METHOD_MITM ? room->mitm_port : room->port);
|
||||
|
||||
RARCH_LOG("[Discord] joining lobby at: %s\n", tmp_hostname);
|
||||
RARCH_LOG("[Discord] joining lobby at: %s\n", join_hostname);
|
||||
task_push_netplay_crc_scan(room->gamecrc,
|
||||
room->gamename, tmp_hostname, room->corename, room->subsystem_name);
|
||||
room->gamename, join_hostname, room->corename, room->subsystem_name);
|
||||
connecting = true;
|
||||
discord_update(DISCORD_PRESENCE_NETPLAY_CLIENT);
|
||||
}
|
||||
@ -224,24 +234,16 @@ finish:
|
||||
static void handle_discord_join(const char* secret)
|
||||
{
|
||||
char url [2048] = "http://lobby.libretro.com/";
|
||||
char tmp_hostname[32];
|
||||
static struct string_list *list = NULL;
|
||||
|
||||
RARCH_LOG("[Discord] join secret: (%s)\n", secret);
|
||||
list = string_split(secret, "|");
|
||||
|
||||
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));
|
||||
strlcpy(peer_party_id, list->elems[0].data, sizeof(peer_party_id));
|
||||
strlcat(url, peer_party_id, sizeof(url));
|
||||
strlcat(url, "/", sizeof(url));
|
||||
RARCH_LOG("[Discord] querying lobby id: %s at %s\n", list->elems[0].data, url);
|
||||
|
||||
snprintf(tmp_hostname,
|
||||
sizeof(tmp_hostname),
|
||||
"%s|%s", list->elems[0].data, list->elems[1].data);
|
||||
|
||||
RARCH_LOG("[Discord] querying lobby id: %s at %s\n", peer_party_id, url);
|
||||
task_push_http_transfer(url, true, NULL, handle_discord_join_cb, NULL);
|
||||
}
|
||||
|
||||
@ -315,7 +317,7 @@ void discord_update(enum discord_presence presence)
|
||||
if (!connecting && (presence == DISCORD_PRESENCE_NONE || presence == DISCORD_PRESENCE_MENU))
|
||||
{
|
||||
memset(&discord_presence, 0, sizeof(discord_presence));
|
||||
client_party_name[0] = '\0';
|
||||
peer_party_id[0] = '\0';
|
||||
}
|
||||
|
||||
switch (presence)
|
||||
@ -378,7 +380,7 @@ void discord_update(enum discord_presence presence)
|
||||
|
||||
if (!netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_ENABLED, NULL))
|
||||
{
|
||||
client_party_name[0] = '\0';
|
||||
peer_party_id[0] = '\0';
|
||||
discord_presence.partyId = NULL;
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.partySize = 0;
|
||||
@ -398,27 +400,29 @@ void discord_update(enum discord_presence presence)
|
||||
|
||||
{
|
||||
char join_secret[128];
|
||||
snprintf(join_secret, sizeof(join_secret), "%d|%s", room->id, party_name);
|
||||
|
||||
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);
|
||||
/* discord_presence.spectateSecret = "SPECSPECSPEC"; */
|
||||
discord_presence.partyId = strdup(party_name);
|
||||
discord_presence.partyId = strdup(self_party_id);
|
||||
discord_presence.partyMax = 2;
|
||||
discord_presence.partySize = 1;
|
||||
|
||||
RARCH_LOG("[Discord] join secret: %s\n", join_secret);
|
||||
RARCH_LOG("[Discord] party id: %s\n", party_name);
|
||||
RARCH_LOG("[Discord] party id: %s\n", self_party_id);
|
||||
}
|
||||
break;
|
||||
case DISCORD_PRESENCE_NETPLAY_CLIENT:
|
||||
RARCH_LOG("[Discord] party id: %s\n", client_party_name);
|
||||
discord_presence.partyId = strdup(client_party_name);
|
||||
RARCH_LOG("[Discord] party id: %s\n", peer_party_id);
|
||||
discord_presence.partyId = strdup(peer_party_id);
|
||||
break;
|
||||
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';
|
||||
peer_party_id[0] = '\0';
|
||||
discord_presence.partyId = NULL;
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.partySize = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user