diff --git a/src/chat/misc.c b/src/chat/misc.c index 821b13e..d9ec904 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -554,11 +554,24 @@ void *why2_communicate_thread(void *arg) goto deallocation; } - if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + //KEEP READING UNTIL CODE ARRIVES + char *code = NULL; + why2_bool exiting_read = 0; + do { - force_exiting = 1; //FAILURE - goto deallocation; - } + //DEALLOCATE + why2_deallocate(code); + + if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + { + force_exiting = 1; //FAILURE + goto deallocation; + } + + //COMPARE CODE + code = get_string_from_json_string(raw, "code"); + exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_USERNAME) == 0; + } while (!exiting_read); decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE