1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-27 16:54:52 +01:00

Implement basic discord status report

This commit is contained in:
Ted John
2017-11-10 20:23:23 +00:00
parent c7b7659cd6
commit 83e80d9658
4 changed files with 171 additions and 1 deletions

View File

@@ -59,6 +59,7 @@
#include "intro.h"
#include "localisation/date.h"
#include "localisation/language.h"
#include "network/DiscordService.h"
#include "network/http.h"
#include "network/network.h"
#include "network/twitch.h"
@@ -87,6 +88,9 @@ namespace OpenRCT2
IObjectManager * _objectManager = nullptr;
ITrackDesignRepository * _trackDesignRepository = nullptr;
IScenarioRepository * _scenarioRepository = nullptr;
#ifdef __ENABLE_DISCORD__
DiscordService * _discordService = nullptr;
#endif
// Game states
TitleScreen * _titleScreen = nullptr;
@@ -133,6 +137,9 @@ namespace OpenRCT2
delete _titleScreen;
#ifdef __ENABLE_DISCORD__
delete _discordService;
#endif
delete _scenarioRepository;
delete _trackDesignRepository;
delete _objectManager;
@@ -298,6 +305,9 @@ namespace OpenRCT2
_objectManager = CreateObjectManager(_objectRepository);
_trackDesignRepository = CreateTrackDesignRepository(_env);
_scenarioRepository = CreateScenarioRepository(_env);
#ifdef __ENABLE_DISCORD__
_discordService = new DiscordService();
#endif
if (!language_open(gConfigGeneral.language))
{
@@ -771,6 +781,13 @@ namespace OpenRCT2
game_update();
}
#ifdef __ENABLE_DISCORD__
if (_discordService != nullptr)
{
_discordService->Update();
}
#endif
twitch_update();
chat_update();
console_update();

View File

@@ -32,7 +32,7 @@
<Import Project="..\..\openrct2.common.props" />
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>__ENABLE_LIGHTFX__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>__ENABLE_DISCORD__;__ENABLE_LIGHTFX__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Breakpad)'=='true'">USE_BREAKPAD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>

View File

@@ -0,0 +1,123 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 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 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#ifdef __ENABLE_DISCORD__
#include <discord-rpc.h>
#include "../core/Console.hpp"
#include "../core/Memory.hpp"
#include "../core/String.hpp"
#include "../localisation/localisation.h"
#include "../OpenRCT2.h"
#include "../scenario/scenario.h"
#include "../world/park.h"
#include "DiscordService.h"
#include "network.h"
constexpr const char * APPLICATION_ID = "378612438200877056";
constexpr const char * STEAM_APP_ID = nullptr;
static void OnReady()
{
log_verbose("DiscordService::OnReady()");
}
static void OnDisconnected(int errorCode, const char * message)
{
Console::Error::WriteLine("DiscordService::OnDisconnected(%d, %s)", errorCode, message);
}
static void OnErrored(int errorCode, const char * message)
{
Console::Error::WriteLine("DiscordService::OnErrored(%d, %s)", errorCode, message);
}
DiscordService::DiscordService()
{
DiscordEventHandlers handlers;
Memory::Set(&handlers, 0, sizeof(handlers));
handlers.ready = OnReady;
handlers.disconnected = OnDisconnected;
handlers.errored = OnErrored;
Discord_Initialize(APPLICATION_ID, &handlers, 1, STEAM_APP_ID);
}
DiscordService::~DiscordService()
{
Discord_Shutdown();
}
static std::string GetParkName()
{
utf8 parkName[128];
format_string(parkName, sizeof(parkName), gParkName, &gParkNameArgs);
return std::string(parkName);
}
void DiscordService::Update()
{
Discord_RunCallbacks();
DiscordRichPresence discordPresence;
Memory::Set(&discordPresence, 0, sizeof(discordPresence));
discordPresence.largeImageKey = "logo";
std::string state;
std::string details;
switch (gScreenFlags)
{
default:
details = GetParkName();
if (network_get_mode() == NETWORK_MODE_NONE)
{
state = "Playing Solo";
}
else
{
state = String::ToStd(network_get_server_name());
// NOTE: the party size is displayed next to state
discordPresence.partyId = network_get_server_name();
discordPresence.partySize = network_get_num_players();
discordPresence.partyMax = 256;
// TODO generate secrets for the server
discordPresence.matchSecret = nullptr;
discordPresence.spectateSecret = nullptr;
discordPresence.instance = 1;
}
break;
case SCREEN_FLAGS_TITLE_DEMO:
details = "In Menus";
break;
case SCREEN_FLAGS_SCENARIO_EDITOR:
details = "In Scenario Editor";
break;
case SCREEN_FLAGS_TRACK_DESIGNER:
details = "In Track Designer";
break;
case SCREEN_FLAGS_TRACK_MANAGER:
details = "In Track Manager";
break;
}
discordPresence.state = state.c_str();
discordPresence.details = details.c_str();
Discord_UpdatePresence(&discordPresence);
}
#endif

View File

@@ -0,0 +1,30 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 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 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#ifdef __ENABLE_DISCORD__
class DiscordService
{
public:
DiscordService();
~DiscordService();
void Update();
};
#endif