RigsofRods
Soft-body Physics Simulation
source
main
network
DiscordRpc.cpp
Go to the documentation of this file.
1
/*
2
This source file is part of Rigs of Rods
3
Copyright 2005-2012 Pierre-Michel Ricordel
4
Copyright 2007-2012 Thomas Fischer
5
Copyright 2013-2020 Petr Ohlidal
6
7
For more information, see http://www.rigsofrods.org/
8
9
Rigs of Rods is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License version 3, as
11
published by the Free Software Foundation.
12
13
Rigs of Rods is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#include "
DiscordRpc.h
"
23
24
#include "
AppContext.h
"
25
26
#ifdef USE_DISCORD_RPC
27
#include <discord_rpc.h>
28
#endif
29
30
using namespace
RoR
;
31
32
#ifdef USE_DISCORD_RPC
33
void
DiscordErrorCallback(
int
,
const
char
*error)
34
{
35
RoR::LogFormat
(
"Discord Error: %s"
, error);
36
}
37
38
void
DiscordReadyCallback(
const
DiscordUser *user)
39
{
40
RoR::LogFormat
(
"Discord Ready: %s"
, user->username);
41
}
42
#endif
43
44
void
DiscordRpc::Init
()
45
{
46
#ifdef USE_DISCORD_RPC
47
if
(
App::io_discord_rpc
->getBool())
48
{
49
DiscordEventHandlers handlers;
50
memset(&handlers, 0,
sizeof
(handlers));
51
handlers.ready = DiscordReadyCallback;
52
handlers.errored = DiscordErrorCallback;
53
54
// Discord_Initialize(const char* applicationId, DiscordEventHandlers* handlers, int autoRegister, const char* optionalSteamId)
55
Discord_Initialize(
"492484203435393035"
, &handlers, 1,
"1234"
);
56
}
57
#endif
58
}
59
60
void
DiscordRpc::UpdatePresence
()
61
{
62
#ifdef USE_DISCORD_RPC
63
if
(
App::io_discord_rpc
->getBool())
64
{
65
char
buffer[256];
66
DiscordRichPresence discordPresence;
67
memset(&discordPresence, 0,
sizeof
(discordPresence));
68
if
(
App::mp_state
->getEnum<MpState>() ==
MpState::CONNECTED
)
69
{
70
discordPresence.state =
"Playing online"
;
71
sprintf(buffer,
"On server: %s:%d on terrain: %s"
,
72
RoR::App::mp_server_host
->getStr().c_str(),
73
RoR::App::mp_server_port
->getInt(),
74
RoR::App::sim_terrain_gui_name
->getStr().c_str());
75
}
76
else
77
{
78
discordPresence.state =
"Playing singleplayer"
;
79
sprintf(buffer,
"On terrain: %s"
,
RoR::App::sim_terrain_gui_name
->getStr().c_str());
80
}
81
discordPresence.details = buffer;
82
discordPresence.startTimestamp = time(0);
83
discordPresence.largeImageKey =
"ror_logo_t"
;
84
discordPresence.largeImageText =
"Rigs of Rods"
;
85
Discord_UpdatePresence(&discordPresence);
86
}
87
#endif
88
}
89
90
void
DiscordRpc::Shutdown
()
91
{
92
#ifdef USE_DISCORD_RPC
93
Discord_Shutdown();
94
#endif
95
}
RoR::MpState::CONNECTED
@ CONNECTED
RoR::App::io_discord_rpc
CVar * io_discord_rpc
Definition:
Application.cpp:205
RoR::DiscordRpc::UpdatePresence
void UpdatePresence()
Definition:
DiscordRpc.cpp:60
RoR::DiscordRpc::Shutdown
void Shutdown()
Definition:
DiscordRpc.cpp:90
RoR::LogFormat
void LogFormat(const char *format,...)
Improved logging utility. Uses fixed 2Kb buffer.
Definition:
Application.cpp:424
AppContext.h
System integration layer; inspired by OgreBites::ApplicationContext.
RoR::App::mp_state
CVar * mp_state
Definition:
Application.cpp:115
DiscordRpc.h
RoR::App::mp_server_port
CVar * mp_server_port
Definition:
Application.cpp:122
RoR::App::mp_server_host
CVar * mp_server_host
Definition:
Application.cpp:121
RoR::DiscordRpc::Init
void Init()
Definition:
DiscordRpc.cpp:44
RoR::App::sim_terrain_gui_name
CVar * sim_terrain_gui_name
Definition:
Application.cpp:98
RoR
Definition:
AppContext.h:36
Generated by
1.8.17