Skip to content

Commit

Permalink
add discord files
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-asm committed May 29, 2018
1 parent b378566 commit d5c2bc9
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,19 @@ ifeq ($(HAVE_NETWORKING), 1)
$(LIBRETRO_COMM_DIR)/utils/md5.o
endif

ifeq ($(HAVE_DISCORD), 1)
DEFINES += -DHAVE_DISCORD
DEFINES += -Ideps/discord-rpc/include/ -Ideps/discord-rpc/thirdparty/rapidjson-1.1.0/include/
OBJ += deps/discord-rpc/src/connection_win.o \
deps/discord-rpc/src/discord_register_win.o \
deps/discord-rpc/src/discord_rpc.o \
deps/discord-rpc/src/rpc_connection.o \
deps/discord-rpc/src/serialization.o \
discord/discord.o
LIBS += -lpsapi -ladvapi32

endif

ifeq ($(HAVE_NETWORKGAMEPAD), 1)
OBJ += input/input_remote.o \
cores/libretro-net-retropad/net_retropad_core.o
Expand Down
6 changes: 5 additions & 1 deletion command.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include "cheevos/var.h"
#endif

#ifdef HAVE_DISCORD
#include "discord/discord.h"
#endif

#ifdef HAVE_MENU
#include "menu/menu_driver.h"
#include "menu/menu_content.h"
Expand Down Expand Up @@ -1275,8 +1279,8 @@ static bool command_event_init_core(enum rarch_core_type *data)
if (!core_load(settings->uints.input_poll_type_behavior))
return false;

rarch_ctl(RARCH_CTL_SET_FRAME_LIMIT, NULL);

rarch_ctl(RARCH_CTL_SET_FRAME_LIMIT, NULL);
return true;
}

Expand Down
121 changes: 121 additions & 0 deletions discord/discord.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2018 - Andrés Suárez
*
* 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/>.
*/

#include "discord.h"

static const char* APPLICATION_ID = "450822022025576457";
static int FrustrationLevel = 0;
static int64_t start_time;

static bool discord_ready = false;
static unsigned discord_status = 0;

DiscordRichPresence discord_presence;

static void handle_discord_ready(const DiscordUser* connectedUser)
{
RARCH_LOG("[discord] connected to user %s#%s - %s\n",
connectedUser->username,
connectedUser->discriminator,
connectedUser->userId);
}

static void handle_discord_disconnected(int errcode, const char* message)
{
RARCH_LOG("[discord] disconnected (%d: %s)\n", errcode, message);
}

static void handle_discord_error(int errcode, const char* message)
{
RARCH_LOG("[discord] error (%d: %s)\n", errcode, message);
}

static void handle_discord_join(const char* secret)
{
RARCH_LOG("[discord] join (%s)\n", secret);
}

static void handle_discord_spectate(const char* secret)
{
RARCH_LOG("[discord] spectate (%s)\n", secret);
}

static void handle_discord_join_request(const DiscordUser* request)
{
int response = -1;
char yn[4];
RARCH_LOG("[discord] join request from %s#%s - %s\n",
request->username,
request->discriminator,
request->userId);
}

void discord_update(unsigned presence)
{
if (!discord_ready || discord_status != DISCORD_PRESENCE_MENU && discord_status == presence)
return;

RARCH_LOG("[discord] updating (%d)\n", presence);
memset(&discord_presence, 0, sizeof(discord_presence));

switch (presence)
{
case DISCORD_PRESENCE_MENU:
discord_presence.state = "In-Menu";
discord_presence.largeImageKey = "icon";
discord_presence.instance = 0;
discord_presence.startTimestamp = start_time;
break;
case DISCORD_PRESENCE_GAME:
start_time = time(0);
discord_presence.state = "Link's House";
discord_presence.details = "Legend of Zelda, The - Link's Awakening DX";
discord_presence.largeImageKey = "icon";
//discord_presence.smallImageKey = "icon";
discord_presence.instance = 0;
discord_presence.startTimestamp = start_time;
break;
default:
break;
}
Discord_UpdatePresence(&discord_presence);
discord_status = presence;
}

void discord_init()
{
RARCH_LOG("[discord] initializing\n");
start_time = time(0);

DiscordEventHandlers handlers;
memset(&handlers, 0, sizeof(handlers));
handlers.ready = handle_discord_ready;
handlers.disconnected = handle_discord_disconnected;
handlers.errored = handle_discord_error;
handlers.joinGame = handle_discord_join;
handlers.spectateGame = handle_discord_spectate;
handlers.joinRequest = handle_discord_join_request;
Discord_Initialize(APPLICATION_ID, &handlers, 1, NULL);

discord_ready = true;
}

void discord_shutdown()
{
RARCH_LOG("[discord] shutting down\n");
Discord_ClearPresence();
Discord_Shutdown();
discord_ready = false;
}
47 changes: 47 additions & 0 deletions discord/discord.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2018 - Andrés Suárez
*
* 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/>.
*/

#ifndef __RARCH_DISCORD_H
#define __RARCH_DISCORD_H

#include <stdlib.h>
#include <stdarg.h>
#include <stdint.h>
#include <string.h>
#include <math.h>

#include <boolean.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <retro_timers.h>

#include "discord_rpc.h"
#include "verbosity.h"

enum discord_presence
{
DISCORD_PRESENCE_MENU = 0,
DISCORD_PRESENCE_GAME,
DISCORD_PRESENCE_CHEEVO_UNLOCKED,
DISCORD_PRESENCE_NETPLAY_HOSTING,
DISCORD_PRESENCE_NETPLAY_CLIENT
};


void discord_init();
void discord_shutdown();
void discord_update(unsigned presence);

#endif /* __RARCH_DISCORD_H */
Binary file modified media/canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions qb/config.libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ else
HAVE_NETWORK_CMD='no'
HAVE_NETWORKGAMEPAD='no'
HAVE_CHEEVOS='no'
HAVE_DISCORD='no'
fi

check_lib '' STDIN_CMD "$CLIB" fcntl
Expand Down
1 change: 1 addition & 0 deletions qb/config.params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ HAVE_QT=auto # Qt companion support
C89_QT=no
HAVE_XSHM=no # XShm video driver support
HAVE_CHEEVOS=yes # Retro Achievements
HAVE_DISCORD=yes # Discord Integration
HAVE_SHADERPIPELINE=yes # Additional shader-based pipelines
C89_SHADERPIPELINE=no
HAVE_VULKAN=auto # Vulkan support
Expand Down
19 changes: 17 additions & 2 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
#include "cheevos/cheevos.h"
#endif

#ifdef HAVE_DISCORD
#include "discord/discord.h"
#endif

#ifdef HAVE_NETWORKING
#include "network/netplay/netplay.h"
#endif
Expand Down Expand Up @@ -1374,17 +1378,21 @@ bool retroarch_main_init(int argc, char *argv[])
rarch_error_on_init = false;
rarch_is_inited = true;

#ifdef HAVE_DISCORD
discord_init();
discord_update(DISCORD_PRESENCE_MENU);
#endif

if (rarch_first_start)
rarch_first_start = false;

return true;

error:
command_event(CMD_EVENT_CORE_DEINIT, NULL);
rarch_is_inited = false;

if (rarch_first_start)
rarch_first_start = false;
rarch_first_start = false;

return false;
}
Expand Down Expand Up @@ -2322,6 +2330,10 @@ bool retroarch_main_quit(void)
runloop_shutdown_initiated = true;
rarch_menu_running_finished();

#ifdef HAVE_DISCORD
discord_shutdown();
#endif

return true;
}

Expand Down Expand Up @@ -3325,6 +3337,9 @@ int runloop_iterate(unsigned *sleep_ms)
if (runloop_check_cheevos())
cheevos_test();
#endif
#ifdef HAVE_DISCORD
discord_update(DISCORD_PRESENCE_GAME);
#endif

for (i = 0; i < max_users; i++)
{
Expand Down

0 comments on commit d5c2bc9

Please sign in to comment.