diff --git a/include/client/ui.h b/include/client/ui.h index f8a150d..388aa83 100644 --- a/include/client/ui.h +++ b/include/client/ui.h @@ -22,6 +22,7 @@ void draw_border(WINDOW *window, bool active); void add_message(uint8_t *author, uint8_t *recipient, uint8_t *content, uint32_t length, time_t creation); void show_chat(uint8_t *recipient); void add_username(char *username); +void ncurses_deinit(); void ui(); #endif diff --git a/lib/packet.c b/lib/packet.c index 477bf03..8aa3be3 100644 --- a/lib/packet.c +++ b/lib/packet.c @@ -214,11 +214,7 @@ int verify_packet(packet_t *pkt, int fd) int status = recv_packet(pkt, fd, ZSM_TYP_MESSAGE); if (status != ZSM_STA_SUCCESS) { close(fd); - if (status == ZSM_STA_CLOSED_CONNECTION) { - error(1, "Server closed connection"); - } - - return ZSM_STA_ERROR_INTEGRITY; + return status; } uint8_t from[MAX_NAME], to[MAX_NAME]; diff --git a/src/client/client.c b/src/client/client.c index 3fdef33..8b14f5e 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -66,7 +66,12 @@ void *receive_worker(void *arg) while (1) { packet_t pkt; - if (verify_packet(&pkt, sockfd) != ZSM_STA_SUCCESS) { + int status = verify_packet(&pkt, sockfd); + if (status != ZSM_STA_SUCCESS) { + if (status == ZSM_STA_CLOSED_CONNECTION) { + ncurses_deinit(); + error(1, "Server closed connection"); + } error(0, "Error verifying packet"); } size_t cipher_len = pkt.length - NONCE_SIZE - MAX_NAME * 2; diff --git a/src/client/ui.c b/src/client/ui.c index 857b87c..515b50e 100644 --- a/src/client/ui.c +++ b/src/client/ui.c @@ -539,6 +539,13 @@ void send_message() show_chat(recipient); } +void ncurses_deinit() +{ + arraylist_free(users); + arraylist_free(marked); + endwin(); +} + /* * Main loop of user interface */ @@ -577,7 +584,8 @@ void ui(int fd) ch = getch(); switch (ch) { case CTRLD: - goto cleanup; + ncurses_deinit(); + break; /* go up by k or up arrow */ case UP: @@ -617,16 +625,12 @@ void ui(int fd) curs_pos = 0; content[0] = '\0'; } + default: if (current_window == CHAT_WINDOW) get_chatbox_content(ch); } } - -cleanup: - arraylist_free(users); - arraylist_free(marked); - endwin(); return; }