Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Initial work on implementing Discord Rich Presence
- Loading branch information
Showing
6 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
Copyright (C) 2018 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program 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 Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#include "desktop/discord_rich_presence.hpp" | ||
|
||
#include <discord-rpc.h> | ||
|
||
#include <algorithm> | ||
#include <cstring> | ||
|
||
namespace desktop | ||
{ | ||
namespace | ||
{ | ||
const char* DISCORD_APP_ID = "407478227485982720"; | ||
const char* STEAM_APP_ID = "599390"; | ||
|
||
void callback_disconnected(int errorCode, const char* message) | ||
{ | ||
|
||
} | ||
|
||
} // end anon namespace | ||
|
||
rich_presence_manager::rich_presence_manager() | ||
{ | ||
DiscordEventHandlers handlers; | ||
std::memset(&handlers, 0, sizeof(handlers)); | ||
|
||
// FIXME | ||
handlers.ready = nullptr; | ||
handlers.errored = nullptr; | ||
handlers.disconnected = &callback_disconnected; | ||
|
||
// TODO: we might want to add the ability to join/observe games directly from | ||
// discord in the future, but that requires special approval by Discord. Leaving | ||
// these callbacks null for now. | ||
handlers.joinGame = nullptr; | ||
handlers.spectateGame = nullptr; | ||
handlers.joinRequest = nullptr; | ||
|
||
Discord_Initialize(DISCORD_APP_ID, &handlers, 1, STEAM_APP_ID); | ||
} | ||
|
||
rich_presence_manager::~rich_presence_manager() | ||
{ | ||
Discord_Shutdown(); | ||
} | ||
|
||
void rich_presence_manager::update_presence( | ||
const std::string state, | ||
const std::string details, | ||
const unsigned party_size, | ||
const unsigned party_max) const | ||
{ | ||
DiscordRichPresence data; | ||
std::memset(&data, 0, sizeof(data)); | ||
|
||
data.state = state.c_str(); | ||
data.details = details.c_str(); | ||
data.largeImageKey = "weslogo"; | ||
data.partySize = party_size; | ||
data.partyMax = party_max; | ||
|
||
Discord_UpdatePresence(&data); | ||
} | ||
|
||
} // namespace desktop1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright (C) 2018 by the Battle for Wesnoth Project http://www.wesnoth.org/ | ||
This program 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 Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY. | ||
See the COPYING file for more details. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace desktop | ||
{ | ||
class rich_presence_manager | ||
{ | ||
public: | ||
rich_presence_manager(); | ||
~rich_presence_manager(); | ||
|
||
void update_presence( | ||
const std::string state, | ||
const std::string details, | ||
const unsigned party_size = 0, | ||
const unsigned party_max = 0) const; | ||
|
||
private: | ||
}; | ||
|
||
} // namespace desktop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters