Made banning work on CoopNet

This commit is contained in:
MysterD 2023-04-14 22:06:56 -07:00
parent a1c218f9fc
commit 4b7bb73232
5 changed files with 68 additions and 5 deletions

View file

@ -28,7 +28,7 @@ typedef struct {
void (*OnConnected)(uint64_t aUserId);
void (*OnDisconnected)(void);
void (*OnLobbyCreated)(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections);
void (*OnLobbyJoined)(uint64_t aLobbyId, uint64_t aUserId, uint64_t aOwnerId);
void (*OnLobbyJoined)(uint64_t aLobbyId, uint64_t aUserId, uint64_t aOwnerId, uint64_t aDestId);
void (*OnLobbyLeft)(uint64_t aLobbyId, uint64_t aUserId);
void (*OnLobbyListGot)(uint64_t aLobbyId, uint64_t aOwnerId, uint16_t aConnections, uint16_t aMaxConnections, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode);
void (*OnLobbyListFinish)(void);

Binary file not shown.

View file

@ -53,11 +53,18 @@ static void coopnet_on_receive(uint64_t userId, const uint8_t* data, uint64_t da
network_receive(localIndex, &userId, (u8*)data, dataLength);
}
static void coopnet_on_lobby_joined(uint64_t lobbyId, uint64_t userId, uint64_t ownerId) {
static void coopnet_on_lobby_joined(uint64_t lobbyId, uint64_t userId, uint64_t ownerId, uint64_t destId) {
LOG_INFO("coopnet_on_lobby_joined!");
coopnet_set_user_id(0, ownerId);
sLocalLobbyId = lobbyId;
sLocalLobbyOwnerId = ownerId;
if (userId == coopnet_get_local_user_id()) {
coopnet_clear_dest_ids();
}
coopnet_save_dest_id(userId, destId);
if (userId == coopnet_get_local_user_id() && gNetworkType == NT_CLIENT) {
network_send_mod_list_request();
}
@ -65,6 +72,7 @@ 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!");
coopnet_clear_dest_id(userId);
if (lobbyId == sLocalLobbyId && userId == coopnet_get_local_user_id()) {
network_shutdown(false, false, true);
}
@ -78,11 +86,13 @@ static bool ns_coopnet_initialize(enum NetworkType networkType) {
}
static char* ns_coopnet_get_id_str(u8 localIndex) {
static char id_str[22] = { 0 };
static char id_str[32] = { 0 };
if (localIndex == UNKNOWN_LOCAL_INDEX) {
snprintf(id_str, 22, "???");
snprintf(id_str, 32, "???");
} else {
snprintf(id_str, 22, "%lld", (long long int)ns_coopnet_get_id(localIndex));
uint64_t userId = ns_coopnet_get_id(localIndex);
uint64_t destId = coopnet_get_dest_id(userId);
snprintf(id_str, 32, "%" PRIu64 "", destId);
}
return id_str;
}

View file

@ -6,6 +6,54 @@
static uint64_t sLocalUserId = 0;
static uint64_t sNetworkUserIds[MAX_PLAYERS] = { 0 };
#define MAX_DEST_IDS (MAX_PLAYERS * 2)
struct DestinationId {
uint64_t userId;
uint64_t destId;
};
struct DestinationId sDestinationIds[MAX_DEST_IDS] = { 0 };
void coopnet_save_dest_id(uint64_t userId, uint64_t destId) {
struct DestinationId* dest = NULL;
for (int i = 0; i < MAX_DEST_IDS; i++) {
if (sDestinationIds[i].userId == userId) {
sDestinationIds[i].destId = destId;
return;
} else if (dest == NULL && sDestinationIds[i].userId == 0) {
dest = &sDestinationIds[i];
}
}
if (dest) {
dest->userId = userId;
dest->destId = destId;
}
}
void coopnet_clear_dest_id(uint64_t userId) {
for (int i = 0; i < MAX_DEST_IDS; i++) {
if (sDestinationIds[i].userId == userId) {
sDestinationIds[i].userId = 0;
sDestinationIds[i].destId = 0;
}
}
}
void coopnet_clear_dest_ids(void) {
for (int i = 0; i < MAX_DEST_IDS; i++) {
sDestinationIds[i].userId = 0;
sDestinationIds[i].destId = 0;
}
}
uint64_t coopnet_get_dest_id(uint64_t userId) {
for (int i = 0; i < MAX_DEST_IDS; i++) {
if (sDestinationIds[i].userId == userId) {
return sDestinationIds[i].destId;
}
}
return 0;
}
u8 coopnet_user_id_to_local_index(uint64_t userId) {
for (int i = 1; i < MAX_PLAYERS; i++) {
if (gNetworkPlayers[i].connected && sNetworkUserIds[i] == userId) {

View file

@ -2,6 +2,11 @@
#include "PR/ultratypes.h"
void coopnet_save_dest_id(uint64_t userId, uint64_t destId);
void coopnet_clear_dest_id(uint64_t userId);
void coopnet_clear_dest_ids(void);
uint64_t coopnet_get_dest_id(uint64_t userId);
u8 coopnet_user_id_to_local_index(uint64_t userId);
void coopnet_set_user_id(uint8_t localIndex, uint64_t userId);
uint64_t coopnet_get_local_user_id(void);