From a65136be937f88818fb8d023f7b34fd5e29836a0 Mon Sep 17 00:00:00 2001 From: MysterD Date: Sun, 9 Apr 2023 23:45:52 -0700 Subject: [PATCH] Add coopnet defines --- Makefile | 6 +++++- src/pc/djui/djui_panel_host.c | 16 +++++++++++++--- src/pc/djui/djui_panel_host_message.c | 3 +++ src/pc/network/coopnet/coopnet.c | 9 ++++----- src/pc/network/coopnet/coopnet.h | 2 ++ src/pc/network/network.c | 8 +++++++- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 14491bea..5297a2a2 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,8 @@ EXTERNAL_DATA ?= 0 DISCORDRPC ?= 0 # Enable Discord Game SDK (used for Discord server hosting) DISCORD_SDK ?= 1 +# Enable CoopNet SDK (used for CoopNet server hosting) +COOPNET ?= 1 # Enable docker build workarounds DOCKERBUILD ?= 0 # Sets your optimization level for building. @@ -982,7 +984,9 @@ else endif # coopnet -LDFLAGS += -Llib/coopnet/linux -l:libcoopnet.a -l:libjuice.a +ifeq ($(COOPNET),1) + LDFLAGS += -Llib/coopnet/linux -l:libcoopnet.a -l:libjuice.a +endif #ifeq ($(WINDOWS_BUILD),1) # ifeq ($(TARGET_BITS), 32) # LDFLAGS += -Llib/coopnet/win32 -l:libcoopnet.a diff --git a/src/pc/djui/djui_panel_host.c b/src/pc/djui/djui_panel_host.c index 98ee7c72..61f6f313 100644 --- a/src/pc/djui/djui_panel_host.c +++ b/src/pc/djui/djui_panel_host.c @@ -16,9 +16,19 @@ struct DjuiInputbox* sInputboxPort = NULL; static void djui_panel_host_network_system_change(UNUSED struct DjuiBase* base) { #ifndef DISCORD_SDK - struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*) base; - if (selectionbox->value == NS_DISCORD) { - selectionbox->value = NS_SOCKET; + { + struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*) base; + if (*selectionbox->value == NS_DISCORD) { + selectionbox->value = NS_SOCKET; + } + } +#endif +#ifndef COOPNET + { + struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*) base; + if (*selectionbox->value == NS_COOPNET) { + selectionbox->value = NS_SOCKET; + } } #endif djui_base_set_enabled(&sInputboxPort->base, (configNetworkSystem == NS_SOCKET)); diff --git a/src/pc/djui/djui_panel_host_message.c b/src/pc/djui/djui_panel_host_message.c index da44d9c9..1e6835d3 100644 --- a/src/pc/djui/djui_panel_host_message.c +++ b/src/pc/djui/djui_panel_host_message.c @@ -23,6 +23,9 @@ void djui_panel_do_host(void) { #ifndef DISCORD_SDK if (configNetworkSystem == NS_DISCORD) { configNetworkSystem = NS_COOPNET; } +#endif +#ifndef COOPNET + if (configNetworkSystem == NS_COOPNET) { configNetworkSystem = NS_SOCKET; } #endif if (configNetworkSystem >= NS_MAX) { configNetworkSystem = NS_MAX; } network_set_system(configNetworkSystem); diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index 7d5cc828..322150e9 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -3,6 +3,8 @@ #include "pc/network/network.h" #include "pc/debuglog.h" +#ifdef COOPNET + #define HOST "localhost" #define PORT 34197 @@ -30,9 +32,6 @@ static void coopnet_on_connected(uint64_t userId) { } } -static void coopnet_on_peer_connected(UNUSED uint64_t peerId) { -} - static void coopnet_on_peer_disconnected(uint64_t peerId) { u8 localIndex = coopnet_user_id_to_local_index(peerId); if (localIndex != UNKNOWN_LOCAL_INDEX && gNetworkPlayers[localIndex].connected) { @@ -56,7 +55,6 @@ static void coopnet_on_lobby_joined(uint64_t lobbyId, uint64_t userId, uint64_t } } - static void coopnet_on_lobby_left(uint64_t lobbyId, uint64_t userId) { LOG_INFO("coopnet_on_lobby_left!"); if (lobbyId == sLocalLobbyId && userId == sLocalUserId) { @@ -73,7 +71,6 @@ static bool ns_coopnet_initialize(enum NetworkType networkType) { gCoopNetCallbacks.OnReceive = coopnet_on_receive; gCoopNetCallbacks.OnLobbyJoined = coopnet_on_lobby_joined; gCoopNetCallbacks.OnLobbyLeft = coopnet_on_lobby_left; - gCoopNetCallbacks.OnPeerConnected = coopnet_on_peer_connected; gCoopNetCallbacks.OnPeerDisconnected = coopnet_on_peer_disconnected; sNetworkType = networkType; @@ -150,3 +147,5 @@ struct NetworkSystem gNetworkSystemCoopNet = { .requireServerBroadcast = false, .name = "CoopNet", }; + +#endif \ No newline at end of file diff --git a/src/pc/network/coopnet/coopnet.h b/src/pc/network/coopnet/coopnet.h index 92cf1a36..a6804e80 100644 --- a/src/pc/network/coopnet/coopnet.h +++ b/src/pc/network/coopnet/coopnet.h @@ -1,6 +1,8 @@ #ifndef COOPNET_H #define COOPNET_H +#ifdef COOPNET extern struct NetworkSystem gNetworkSystemCoopNet; +#endif #endif \ No newline at end of file diff --git a/src/pc/network/network.c b/src/pc/network/network.c index 0bc71fff..39045a27 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -85,13 +85,19 @@ struct ServerSettings gServerSettings = { void network_set_system(enum NetworkSystemType nsType) { network_forget_all_reliable(); + switch (nsType) { case NS_SOCKET: gNetworkSystem = &gNetworkSystemSocket; break; + #ifdef DISCORD_SDK case NS_DISCORD: gNetworkSystem = &gNetworkSystemDiscord; break; #endif + +#ifdef COOPNET case NS_COOPNET: gNetworkSystem = &gNetworkSystemCoopNet; break; - default: LOG_ERROR("Unknown network system: %d", nsType); +#endif + + default: gNetworkSystem = &gNetworkSystemSocket; LOG_ERROR("Unknown network system: %d", nsType); break; } }