mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 00:32:49 +00:00
[discord] populate data correctly
This commit is contained in:
parent
4d0729187f
commit
fed74b9e70
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@ -15,7 +15,10 @@
|
||||
"*.rh": "c",
|
||||
"array": "c",
|
||||
"file_stream.h": "c",
|
||||
"driver.h": "c"
|
||||
"driver.h": "c",
|
||||
"iosfwd": "c",
|
||||
"xlocbuf": "c",
|
||||
"xmemory0": "c"
|
||||
},
|
||||
"C_Cpp.dimInactiveRegions": false,
|
||||
}
|
@ -28,6 +28,7 @@
|
||||
#ifdef HAVE_NETWORKING
|
||||
#include "../../network/netplay/netplay.h"
|
||||
#include "../../network/netplay/netplay_discovery.h"
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CHEEVOS
|
||||
@ -44,6 +45,8 @@ static int64_t ellapsed_time = 0;
|
||||
static bool discord_ready = false;
|
||||
static unsigned discord_status = 0;
|
||||
|
||||
struct netplay_room *room;
|
||||
|
||||
DiscordRichPresence discord_presence;
|
||||
|
||||
static void handle_discord_ready(const DiscordUser* connectedUser)
|
||||
@ -67,6 +70,21 @@ static void handle_discord_error(int errcode, const char* message)
|
||||
static void handle_discord_join(const char* secret)
|
||||
{
|
||||
RARCH_LOG("[Discord] join (%s)\n", secret);
|
||||
static struct string_list *list = NULL;
|
||||
list = string_split(secret, "|");
|
||||
|
||||
char tmp_hostname[32];
|
||||
snprintf(tmp_hostname,
|
||||
sizeof(tmp_hostname),
|
||||
"%s|%s", list->elems[0].data, list->elems[1].data);
|
||||
|
||||
if (netplay_driver_ctl(RARCH_NETPLAY_CTL_IS_DATA_INITED, NULL))
|
||||
deinit_netplay();
|
||||
netplay_driver_ctl(RARCH_NETPLAY_CTL_ENABLE_CLIENT, NULL);
|
||||
|
||||
task_push_netplay_crc_scan(atoi(list->elems[3].data),
|
||||
list->elems[2].data,
|
||||
tmp_hostname, list->elems[4].data);
|
||||
}
|
||||
|
||||
static void handle_discord_spectate(const char* secret)
|
||||
@ -155,9 +173,26 @@ void discord_update(enum discord_presence presence)
|
||||
}
|
||||
break;
|
||||
case DISCORD_PRESENCE_NETPLAY_HOSTING:
|
||||
discord_presence.joinSecret = "JOINJOINJOIN";
|
||||
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);
|
||||
|
||||
char party_id[128];
|
||||
snprintf(party_id, sizeof(party_id), "%d|%s", room->id, room->nickname);
|
||||
char join_secret[128];
|
||||
snprintf(join_secret, sizeof(join_secret), "%s|%d|%s|%u|%s",
|
||||
room->host_method == NETPLAY_HOST_METHOD_MITM ? room->mitm_address : room->address,
|
||||
room->host_method == NETPLAY_HOST_METHOD_MITM ? room->mitm_port : room->port,
|
||||
room->gamename, room->gamecrc, room->corename);
|
||||
RARCH_LOG("%s\n", join_secret);
|
||||
discord_presence.joinSecret = strdup(join_secret);
|
||||
discord_presence.spectateSecret = "SPECSPECSPEC";
|
||||
discord_presence.partyId = "RADIUS";
|
||||
discord_presence.partyId = party_id;
|
||||
discord_presence.partyMax = 0;
|
||||
discord_presence.partySize = 0;
|
||||
break;
|
||||
|
@ -640,6 +640,15 @@ static void netplay_announce_cb(void *task_data, void *user_data, const char *er
|
||||
{
|
||||
RARCH_LOG("[netplay] announcing netplay game... \n");
|
||||
|
||||
#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
|
||||
|
||||
if (task_data)
|
||||
{
|
||||
unsigned i, ip_len, port_len;
|
||||
@ -1498,14 +1507,6 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
||||
case RARCH_NETPLAY_CTL_ENABLE_SERVER:
|
||||
netplay_enabled = true;
|
||||
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;
|
||||
|
||||
case RARCH_NETPLAY_CTL_ENABLE_CLIENT:
|
||||
@ -1541,6 +1542,7 @@ bool netplay_driver_ctl(enum rarch_netplay_ctl_state state, void *data)
|
||||
case RARCH_NETPLAY_CTL_IS_CONNECTED:
|
||||
ret = false;
|
||||
goto done;
|
||||
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user