Add coopnet defines

This commit is contained in:
MysterD 2023-04-09 23:45:52 -07:00
parent 033035b887
commit a65136be93
6 changed files with 34 additions and 10 deletions

View File

@ -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

View File

@ -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));

View File

@ -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);

View File

@ -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

View File

@ -1,6 +1,8 @@
#ifndef COOPNET_H
#define COOPNET_H
#ifdef COOPNET
extern struct NetworkSystem gNetworkSystemCoopNet;
#endif
#endif

View File

@ -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;
}
}