diff --git a/lib/coopnet/include/libcoopnet.h b/lib/coopnet/include/libcoopnet.h index 1e69cd9c..433ccab5 100644 --- a/lib/coopnet/include/libcoopnet.h +++ b/lib/coopnet/include/libcoopnet.h @@ -1,9 +1,10 @@ #ifndef LIBCOOPNET_H #define LIBCOOPNET_H -#if defined(__cplusplus) +#if defined(__cplusplus) #include extern "C" { +class Connection; #endif #include @@ -38,6 +39,12 @@ typedef struct { void (*OnError)(enum MPacketErrorNumber aErrorNumber, uint64_t tag); void (*OnPeerConnected)(uint64_t aPeerId); void (*OnPeerDisconnected)(uint64_t aPeerId); + void (*OnLoadBalance)(const char* aHost, uint32_t port); + uint64_t (*DestIdFunction)(uint64_t aInput); +#if defined(__cplusplus) + bool (*ConnectionIsAllowed)(Connection*, bool); + void (*OnReceiveInfoBits)(Connection* aConnection, uint64_t aDestId, uint64_t aInfoBits, const char* aName); +#endif } CoopNetCallbacks; typedef struct { @@ -48,7 +55,7 @@ extern CoopNetCallbacks gCoopNetCallbacks; extern CoopNetSettings gCoopNetSettings; bool coopnet_is_connected(void); -CoopNetRc coopnet_begin(const char* aHost, uint32_t aPort); +CoopNetRc coopnet_begin(const char* aHost, uint32_t aPort, const char* aName, uint64_t aDestId); CoopNetRc coopnet_shutdown(void); CoopNetRc coopnet_update(void); CoopNetRc coopnet_lobby_create(const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections, const char* aPassword, const char* aDescription); @@ -60,7 +67,7 @@ CoopNetRc coopnet_send(const uint8_t* aData, uint64_t aDataLength); CoopNetRc coopnet_send_to(uint64_t aPeerId, const uint8_t* aData, uint64_t aDataLength); CoopNetRc coopnet_unpeer(uint64_t aPeerId); -#if defined(__cplusplus) +#if defined(__cplusplus) } #endif #endif \ No newline at end of file diff --git a/lib/coopnet/linux/libcoopnet.a b/lib/coopnet/linux/libcoopnet.a index b5abf3e5..1df18afa 100644 Binary files a/lib/coopnet/linux/libcoopnet.a and b/lib/coopnet/linux/libcoopnet.a differ diff --git a/src/pc/configfile.c b/src/pc/configfile.c index ee664dc3..285bfa48 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -158,6 +158,7 @@ bool configForce4By3 = false; char configCoopNetIp[MAX_CONFIG_STRING] = DEFAULT_COOPNET_IP; unsigned int configCoopNetPort = DEFAULT_COOPNET_PORT; char configPassword[MAX_CONFIG_STRING] = ""; +char configDestId[MAX_CONFIG_STRING] = "0"; bool configFadeoutDistantSounds = true; static const struct ConfigOption options[] = { @@ -269,6 +270,7 @@ static const struct ConfigOption options[] = { {.name = "coopnet_ip", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configCoopNetIp, .maxStringLength = MAX_CONFIG_STRING}, {.name = "coopnet_port", .type = CONFIG_TYPE_UINT , .uintValue = &configCoopNetPort}, {.name = "coopnet_password", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configPassword, .maxStringLength = MAX_CONFIG_STRING}, + {.name = "coopnet_dest", .type = CONFIG_TYPE_STRING, .stringValue = (char*)&configDestId, .maxStringLength = MAX_CONFIG_STRING}, {.name = "fade_distant_sounds", .type = CONFIG_TYPE_BOOL , .boolValue = &configFadeoutDistantSounds}, }; diff --git a/src/pc/configfile.h b/src/pc/configfile.h index e927046c..1ee53e25 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -115,6 +115,7 @@ extern bool configForce4By3; extern char configCoopNetIp[]; extern unsigned int configCoopNetPort; extern char configPassword[]; +extern char configDestId[]; extern bool configFadeoutDistantSounds; void configfile_load(void); diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index 43904325..3daafb0c 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -54,6 +54,14 @@ static void coopnet_on_peer_disconnected(uint64_t peerId) { } } +static void coopnet_on_load_balance(const char* host, uint32_t port) { + if (host && strlen(host) > 0) { + snprintf(configCoopNetIp, MAX_CONFIG_STRING, "%s", host); + } + configCoopNetPort = port; + configfile_save(configfile_name()); +} + static void coopnet_on_receive(uint64_t userId, const uint8_t* data, uint64_t dataLength) { coopnet_set_user_id(0, userId); u8 localIndex = coopnet_user_id_to_local_index(userId); @@ -68,6 +76,7 @@ static void coopnet_on_lobby_joined(uint64_t lobbyId, uint64_t userId, uint64_t if (userId == coopnet_get_local_user_id()) { coopnet_clear_dest_ids(); + snprintf(configDestId, MAX_CONFIG_STRING, "%" PRIu64 "", destId); } coopnet_save_dest_id(userId, destId); @@ -262,10 +271,14 @@ static CoopNetRc coopnet_initialize(void) { gCoopNetCallbacks.OnLobbyLeft = coopnet_on_lobby_left; gCoopNetCallbacks.OnError = coopnet_on_error; gCoopNetCallbacks.OnPeerDisconnected = coopnet_on_peer_disconnected; + gCoopNetCallbacks.OnLoadBalance = coopnet_on_load_balance; if (coopnet_is_connected()) { return COOPNET_OK; } - CoopNetRc rc = coopnet_begin(configCoopNetIp, configCoopNetPort); + char* endptr = NULL; + uint64_t destId = strtoull(configDestId, &endptr, 10); + + CoopNetRc rc = coopnet_begin(configCoopNetIp, configCoopNetPort, configPlayerName, destId); if (rc == COOPNET_FAILED) { djui_popup_create(DLANG(NOTIF, COOPNET_CONNECTION_FAILED), 2); }