From af04df0f2638ba8a085cf18b82d510040eec6948 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 17 Apr 2023 20:54:40 -0700 Subject: [PATCH] Add peering failure notification --- lang/English.ini | 1 + lib/coopnet/include/libcoopnet.h | 3 ++- src/pc/network/coopnet/coopnet.c | 18 +++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lang/English.ini b/lang/English.ini index 1d96cee0..5abb8385 100644 --- a/lang/English.ini +++ b/lang/English.ini @@ -26,6 +26,7 @@ LOBBY_JOIN_FULL = "\\#ffa0a0\\The lobby is full!" LOBBY_JOIN_FAILED = "\\#ffa0a0\\Failed to join the lobby!" LOBBY_PASSWORD_INCORRECT = "\\#ffa0a0\\Entered the wrong lobby password!" COOPNET_VERSION = "\\#ffa0a0\\Your version is no longer compatible with CoopNet. Update the game!" +PEER_FAILED = "\\#ffa0a0\\Failed to connect to player '@'" [CHAT] KICKING = "Kicking '@'!" diff --git a/lib/coopnet/include/libcoopnet.h b/lib/coopnet/include/libcoopnet.h index f3a9d6e3..1e69cd9c 100644 --- a/lib/coopnet/include/libcoopnet.h +++ b/lib/coopnet/include/libcoopnet.h @@ -22,6 +22,7 @@ enum MPacketErrorNumber { MERR_LOBBY_JOIN_FAILED, MERR_LOBBY_PASSWORD_INCORRECT, MERR_COOPNET_VERSION, + MERR_PEER_FAILED, MERR_MAX, }; @@ -34,7 +35,7 @@ typedef struct { 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, const char* aDescription); void (*OnLobbyListFinish)(void); void (*OnReceive)(uint64_t aFromUserId, const uint8_t* aData, uint64_t aSize); - void (*OnError)(enum MPacketErrorNumber aErrorNumber); + void (*OnError)(enum MPacketErrorNumber aErrorNumber, uint64_t tag); void (*OnPeerConnected)(uint64_t aPeerId); void (*OnPeerDisconnected)(uint64_t aPeerId); } CoopNetCallbacks; diff --git a/src/pc/network/coopnet/coopnet.c b/src/pc/network/coopnet/coopnet.c index e4065c61..e7c09d81 100644 --- a/src/pc/network/coopnet/coopnet.c +++ b/src/pc/network/coopnet/coopnet.c @@ -90,12 +90,24 @@ static void coopnet_on_lobby_left(uint64_t lobbyId, uint64_t userId) { } } -static void coopnet_on_error(enum MPacketErrorNumber error) { +static void coopnet_on_error(enum MPacketErrorNumber error, uint64_t tag) { switch (error) { case MERR_COOPNET_VERSION: djui_popup_create(DLANG(NOTIF, COOPNET_VERSION), 2); network_shutdown(false, false, false, false); break; + case MERR_PEER_FAILED: + { + char built[256] = { 0 }; + u8 localIndex = coopnet_user_id_to_local_index(tag); + if (localIndex == UNKNOWN_LOCAL_INDEX || gNetworkPlayers[localIndex].name[0] == '\0') { + snprintf(built, 256, "%s", "unknown"); + } else { + djui_language_replace(DLANG(NOTIF, IMPORT_MOD_SUCCESS), built, 256, '@', gNetworkPlayers[localIndex].name); + } + djui_popup_create(built, 2); + } + break; case MERR_LOBBY_NOT_FOUND: djui_popup_create(DLANG(NOTIF, LOBBY_NOT_FOUND), 2); network_shutdown(false, false, false, false); @@ -112,7 +124,8 @@ static void coopnet_on_error(enum MPacketErrorNumber error) { djui_popup_create(DLANG(NOTIF, LOBBY_PASSWORD_INCORRECT), 2); network_shutdown(false, false, false, false); break; - default: + case MERR_NONE: + case MERR_MAX: break; } } @@ -241,7 +254,6 @@ static void ns_coopnet_shutdown(bool reconnecting) { } static CoopNetRc coopnet_initialize(void) { - gCoopNetCallbacks.OnConnected = coopnet_on_connected; gCoopNetCallbacks.OnDisconnected = coopnet_on_disconnected; gCoopNetCallbacks.OnReceive = coopnet_on_receive;