Prevent people from hosting a discord game when discord fails

This commit is contained in:
MysterD 2020-10-14 21:17:28 -07:00
parent 8750198750
commit 040aa92fd1
3 changed files with 14 additions and 2 deletions

View File

@ -19,6 +19,7 @@
#include "audio/external.h"
#include "config.h"
#include "pc/network/version.h"
#include "pc/network/discord/discord.h"
#define MAIN_MENU_HEADER_TEXT "SM64 COOP"
@ -82,7 +83,12 @@ static void host_menu_draw_strings(void) {
char warning[128];
snprintf(warning, 127, "You must forward port '%d' in your router or use Hamachi.", configHostPort);
print_generic_ascii_string(0, 15, warning);
} else if ((configNetworkSystem == 0) && gDiscordFailed) {
f32 red = (f32)fabs(sin(gGlobalTimer / 20.0f));
gDPSetEnvColor(gDisplayListHead++, 222, 222 * red, 222 * red, gMenuStringAlpha);
char warning[128];
snprintf(warning, 127, "Discord failed to initialize.");
print_generic_ascii_string(0, 15, warning);
}
}

View File

@ -19,6 +19,7 @@
static int64_t applicationId = 752700005210390568;
struct DiscordApplication app = { 0 };
bool gDiscordInitialized = false;
bool gDiscordFailed = false;
void discord_fatal(int rc) {
#if defined(_WIN32) || defined(_WIN64)
@ -139,9 +140,13 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
params.lobby_events = discord_lobby_initialize();
int rc = DiscordCreate(DISCORD_VERSION, &params, &app.core);
if (rc) {
gDiscordFailed = false;
if (networkType != NT_NONE) {
DISCORD_REQUIRE(rc);
} else if (rc) {
LOG_ERROR("DiscordCreate failed: %d", rc);
custom_menu_error("Could not detect Discord.\n\nTry closing the game,\nrestarting Discord,\nand opening the game again.");
gDiscordFailed = true;
return false;
}

View File

@ -26,6 +26,7 @@ void discord_fatal(int rc);
extern struct NetworkSystem gNetworkSystemDiscord;
extern bool gDiscordInitialized;
extern bool gDiscordFailed;
struct DiscordApplication {
struct IDiscordCore* core;