Added error handling for coopnet

This commit is contained in:
MysterD 2023-04-16 16:06:30 -07:00
parent 85c93481ae
commit 4dec136324
4 changed files with 30 additions and 7 deletions

View File

@ -21,6 +21,10 @@ IMPORT_FAIL = "\\#ffa0a0\\Failed to import\n\\#c8c8c8\\'@'"
IMPORT_FAIL_INGAME = "\\#ffa0a0\\Can not import while in-game" IMPORT_FAIL_INGAME = "\\#ffa0a0\\Can not import while in-game"
COOPNET_CONNECTION_FAILED = "\\#ffa0a0\\Could not connect to CoopNet!" COOPNET_CONNECTION_FAILED = "\\#ffa0a0\\Could not connect to CoopNet!"
COOPNET_DISCONNECTED = "\\#ffa0a0\\Lost connection to CoopNet!" COOPNET_DISCONNECTED = "\\#ffa0a0\\Lost connection to CoopNet!"
LOBBY_NOT_FOUND = "\\#ffa0a0\\The lobby no longer exists!"
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!"
[CHAT] [CHAT]
KICKING = "Kicking '@'!" KICKING = "Kicking '@'!"

View File

@ -26,7 +26,7 @@ enum MPacketErrorNumber {
typedef struct { typedef struct {
void (*OnConnected)(uint64_t aUserId); void (*OnConnected)(uint64_t aUserId);
void (*OnDisconnected)(void); void (*OnDisconnected)(bool aIntentional);
void (*OnLobbyCreated)(uint64_t aLobbyId, const char* aGame, const char* aVersion, const char* aHostName, const char* aMode, uint16_t aMaxConnections); 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, uint64_t aDestId); void (*OnLobbyJoined)(uint64_t aLobbyId, uint64_t aUserId, uint64_t aOwnerId, uint64_t aDestId);
void (*OnLobbyLeft)(uint64_t aLobbyId, uint64_t aUserId); void (*OnLobbyLeft)(uint64_t aLobbyId, uint64_t aUserId);

Binary file not shown.

View File

@ -22,7 +22,6 @@ static uint64_t sLocalLobbyId = 0;
static uint64_t sLocalLobbyOwnerId = 0; static uint64_t sLocalLobbyOwnerId = 0;
static enum NetworkType sNetworkType; static enum NetworkType sNetworkType;
static bool sReconnecting = false; static bool sReconnecting = false;
static bool sIntentionalDisconnect = false;
static CoopNetRc coopnet_initialize(void); static CoopNetRc coopnet_initialize(void);
@ -38,9 +37,9 @@ static void coopnet_on_connected(uint64_t userId) {
coopnet_set_local_user_id(userId); coopnet_set_local_user_id(userId);
} }
static void coopnet_on_disconnected(void) { static void coopnet_on_disconnected(bool intentional) {
LOG_INFO("Coopnet shutdown!"); LOG_INFO("Coopnet shutdown!");
if (!sIntentionalDisconnect) { if (!intentional) {
djui_popup_create(DLANG(NOTIF, COOPNET_DISCONNECTED), 2); djui_popup_create(DLANG(NOTIF, COOPNET_DISCONNECTED), 2);
} }
coopnet_shutdown(); coopnet_shutdown();
@ -89,6 +88,28 @@ static void coopnet_on_lobby_left(uint64_t lobbyId, uint64_t userId) {
} }
} }
static void coopnet_on_error(enum MPacketErrorNumber error) {
switch (error) {
case MERR_LOBBY_NOT_FOUND:
djui_popup_create(DLANG(NOTIF, LOBBY_NOT_FOUND), 2);
network_shutdown(false, false, false, false);
break;
case MERR_LOBBY_JOIN_FULL:
djui_popup_create(DLANG(NOTIF, LOBBY_JOIN_FULL), 2);
network_shutdown(false, false, false, false);
break;
case MERR_LOBBY_JOIN_FAILED:
djui_popup_create(DLANG(NOTIF, LOBBY_JOIN_FAILED), 2);
network_shutdown(false, false, false, false);
break;
case MERR_LOBBY_PASSWORD_INCORRECT:
djui_popup_create(DLANG(NOTIF, LOBBY_PASSWORD_INCORRECT), 2);
network_shutdown(false, false, false, false);
break;
default:
break;
}
}
static bool ns_coopnet_initialize(enum NetworkType networkType, bool reconnecting) { static bool ns_coopnet_initialize(enum NetworkType networkType, bool reconnecting) {
sNetworkType = networkType; sNetworkType = networkType;
sReconnecting = reconnecting; sReconnecting = reconnecting;
@ -170,12 +191,9 @@ static void ns_coopnet_get_lobby_secret(UNUSED char* destination, UNUSED u32 des
static void ns_coopnet_shutdown(bool reconnecting) { static void ns_coopnet_shutdown(bool reconnecting) {
if (reconnecting) { return; } if (reconnecting) { return; }
LOG_INFO("Coopnet shutdown!"); LOG_INFO("Coopnet shutdown!");
sIntentionalDisconnect = true;
coopnet_shutdown(); coopnet_shutdown();
gCoopNetCallbacks.OnLobbyListGot = NULL; gCoopNetCallbacks.OnLobbyListGot = NULL;
gCoopNetCallbacks.OnLobbyListFinish = NULL; gCoopNetCallbacks.OnLobbyListFinish = NULL;
//coopnet_update();
sIntentionalDisconnect = false;
sLocalLobbyId = 0; sLocalLobbyId = 0;
sLocalLobbyOwnerId = 0; sLocalLobbyOwnerId = 0;
@ -188,6 +206,7 @@ static CoopNetRc coopnet_initialize(void) {
gCoopNetCallbacks.OnReceive = coopnet_on_receive; gCoopNetCallbacks.OnReceive = coopnet_on_receive;
gCoopNetCallbacks.OnLobbyJoined = coopnet_on_lobby_joined; gCoopNetCallbacks.OnLobbyJoined = coopnet_on_lobby_joined;
gCoopNetCallbacks.OnLobbyLeft = coopnet_on_lobby_left; gCoopNetCallbacks.OnLobbyLeft = coopnet_on_lobby_left;
gCoopNetCallbacks.OnError = coopnet_on_error;
gCoopNetCallbacks.OnPeerDisconnected = coopnet_on_peer_disconnected; gCoopNetCallbacks.OnPeerDisconnected = coopnet_on_peer_disconnected;
if (coopnet_is_connected()) { return COOPNET_OK; } if (coopnet_is_connected()) { return COOPNET_OK; }