Update Linux coopnet

This commit is contained in:
MysterD 2023-06-18 12:20:14 -07:00
parent 69f16bebb5
commit ef66a18fc2
5 changed files with 27 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#if defined(__cplusplus)
#include <cstdint>
extern "C" {
class Connection;
#endif
#include <stdbool.h>
@ -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);

Binary file not shown.

View File

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

View File

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

View File

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