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 a1d8d73c6d
commit d3735ef097
3 changed files with 14 additions and 2 deletions

View File

@ -19,6 +19,7 @@
#include "audio/external.h" #include "audio/external.h"
#include "config.h" #include "config.h"
#include "pc/network/version.h" #include "pc/network/version.h"
#include "pc/network/discord/discord.h"
#define MAIN_MENU_HEADER_TEXT "SM64 COOP" #define MAIN_MENU_HEADER_TEXT "SM64 COOP"
@ -82,7 +83,12 @@ static void host_menu_draw_strings(void) {
char warning[128]; char warning[128];
snprintf(warning, 127, "You must forward port '%d' in your router or use Hamachi.", configHostPort); snprintf(warning, 127, "You must forward port '%d' in your router or use Hamachi.", configHostPort);
print_generic_ascii_string(0, 15, warning); 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; static int64_t applicationId = 752700005210390568;
struct DiscordApplication app = { 0 }; struct DiscordApplication app = { 0 };
bool gDiscordInitialized = false; bool gDiscordInitialized = false;
bool gDiscordFailed = false;
void discord_fatal(int rc) { void discord_fatal(int rc) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
@ -139,9 +140,13 @@ static bool ns_discord_initialize(enum NetworkType networkType) {
params.lobby_events = discord_lobby_initialize(); params.lobby_events = discord_lobby_initialize();
int rc = DiscordCreate(DISCORD_VERSION, &params, &app.core); 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); 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."); custom_menu_error("Could not detect Discord.\n\nTry closing the game,\nrestarting Discord,\nand opening the game again.");
gDiscordFailed = true;
return false; return false;
} }

View File

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