diff --git a/Makefile b/Makefile index d04740eb3..ccca86e86 100644 --- a/Makefile +++ b/Makefile @@ -48,8 +48,10 @@ EXT_OPTIONS_MENU ?= 1 TEXTSAVES ?= 0 # Load resources from external files EXTERNAL_DATA ?= 0 -# Enable Discord Rich Presence +# Enable Discord Rich Presence (outdated, no longer supported) DISCORDRPC ?= 0 +# Enable Discord Game SDK (used for Discord server hosting) +DISCORD_SDK ?= 1 # Enable docker build workarounds DOCKERBUILD ?= 0 @@ -289,13 +291,17 @@ LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h))) # Hi, I'm a PC SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes -SRC_DIRS += src/pc/network src/pc/network/packets src/pc/network/socket src/pc/network/discord +SRC_DIRS += src/pc/network src/pc/network/packets src/pc/network/socket ASM_DIRS := #ifeq ($(DISCORDRPC),1) # SRC_DIRS += src/pc/discord #endif +ifeq ($(DISCORD_SDK),1) + SRC_DIRS += src/pc/network/discord +endif + BIN_DIRS := bin bin/$(VERSION) ULTRA_SRC_DIRS := lib/src lib/src/math @@ -425,13 +431,15 @@ RPC_LIBS := #endif DISCORD_SDK_LIBS := -ifeq ($(WINDOWS_BUILD),1) - DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dll -else ifeq ($(OSX_BUILD),1) - # needs testing - DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dylib -else - DISCORD_SDK_LIBS := lib/discordsdk/libdiscord_game_sdk.so +ifeq ($(DISCORD_SDK), 1) + ifeq ($(WINDOWS_BUILD),1) + DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dll + else ifeq ($(OSX_BUILD),1) + # needs testing + DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dylib + else + DISCORD_SDK_LIBS := lib/discordsdk/libdiscord_game_sdk.so + endif endif # Automatic dependency files @@ -460,19 +468,18 @@ else CXX := emcc endif -LD := $(CXX) - #ifeq ($(DISCORDRPC),1) -# LD := $(CXX) -#else ifeq ($(WINDOWS_BUILD),1) -# ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL -# LD := $(CC) -# else ifeq ($(CROSS),x86_64-w64-mingw32.static-) -# LD := $(CC) -# else -# LD := $(CXX) -# endif -#endif +ifeq ($(DISCORD_SDK),1) + LD := $(CXX) +else ifeq ($(WINDOWS_BUILD),1) + ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL + LD := $(CC) + else ifeq ($(CROSS),x86_64-w64-mingw32.static-) + LD := $(CC) + else + LD := $(CXX) + endif +endif ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL CPP := cpp -P @@ -621,6 +628,12 @@ endif # CFLAGS += -DDISCORDRPC #endif +# Check for Discord SDK option +ifeq ($(DISCORD_SDK),1) + CC_CHECK += -DDISCORD_SDK + CFLAGS += -DDISCORD_SDK +endif + # Check for texture fix option ifeq ($(TEXTURE_FIX),1) CC_CHECK += -DTEXTURE_FIX @@ -692,9 +705,13 @@ endif ifeq ($(WINDOWS_BUILD),1) LDFLAGS += -L"ws2_32" -lwsock32 - LDFLAGS += -Wl,-Bdynamic -ldiscord_game_sdk -Wl,-Bstatic + ifeq ($(DISCORD_SDK),1) + LDFLAGS += -Wl,-Bdynamic -ldiscord_game_sdk -Wl,-Bstatic + endif else - LDFLAGS += -ldiscord_game_sdk -Wl,-rpath . -Wl,-rpath lib/discordsdk + ifeq ($(DISCORD_SDK),1) + LDFLAGS += -ldiscord_game_sdk -Wl,-rpath . -Wl,-rpath lib/discordsdk + endif endif diff --git a/src/menu/custom_menu.c b/src/menu/custom_menu.c index 1e77a4d76..ab78b9ab8 100644 --- a/src/menu/custom_menu.c +++ b/src/menu/custom_menu.c @@ -72,17 +72,23 @@ static void host_menu_draw_strings(void) { } static void host_menu_do_host(void) { +#ifndef DISCORD_SDK + configNetworkSystem = 1; +#endif if (configNetworkSystem == 0) { network_set_system(NS_DISCORD); - } - else { + } else { network_set_system(NS_SOCKET); } custom_menu_close_system(); } static void host_menu_setting_network_system(void) { +#ifdef DISCORD_SDK configNetworkSystem = (configNetworkSystem == 0) ? 1 : 0; +#else + configNetworkSystem = 1; +#endif } static void host_menu_setting_interaction(void) { diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 22dddae44..0e033076a 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -321,6 +321,10 @@ void configfile_load(const char *filename) { } fs_close(file); + +#ifndef DISCORD_SDK + configNetworkSystem = 1; +#endif } // Writes the config file to 'filename' diff --git a/src/pc/network/network.c b/src/pc/network/network.c index f229089d9..b0b2962b2 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -3,7 +3,9 @@ #include "object_fields.h" #include "object_constants.h" #include "socket/socket.h" +#ifdef DISCORD_SDK #include "discord/discord.h" +#endif #include "pc/configfile.h" #include "pc/debuglog.h" @@ -11,7 +13,11 @@ extern s16 sCurrPlayMode; enum NetworkType gNetworkType = NT_NONE; +#ifdef DISCORD_SDK struct NetworkSystem* gNetworkSystem = &gNetworkSystemDiscord; +#else +struct NetworkSystem* gNetworkSystem = &gNetworkSystemSocket; +#endif #define LOADING_LEVEL_THRESHOLD 10 u8 networkLoadingLevel = 0; @@ -27,7 +33,9 @@ struct ServerSettings gServerSettings = { void network_set_system(enum NetworkSystemType nsType) { switch (nsType) { case NS_SOCKET: gNetworkSystem = &gNetworkSystemSocket; break; +#ifdef DISCORD_SDK case NS_DISCORD: gNetworkSystem = &gNetworkSystemDiscord; break; +#endif default: LOG_ERROR("Unknown network system: %d", nsType); } } diff --git a/src/pc/network/network_player.h b/src/pc/network/network_player.h index a2c1c0974..1a7941be6 100644 --- a/src/pc/network/network_player.h +++ b/src/pc/network/network_player.h @@ -10,6 +10,7 @@ #define NETWORK_PLAYER_TIMEOUT 10 enum NetworkPlayerType { + NPT_UNKNOWN, NPT_LOCAL, NPT_SERVER, NPT_CLIENT,