diff --git a/src/prompt.c b/src/prompt.c index 0164440..f726750 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -261,7 +261,7 @@ static void prompt_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint int n = add_group_req(group_pub_key, friendnumber); if (n == -1) { - wprintw(self->window, "\nGroup chat queue is full. Discarding invite.\n"); + wprintw(self->window, "\nSomething bad happened.\n"); return; } diff --git a/src/windows.c b/src/windows.c index 3990186..a61d2d6 100644 --- a/src/windows.c +++ b/src/windows.c @@ -81,11 +81,24 @@ void on_action(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, void *userdata) { + if (friendnumber < 0 || friendnumber > MAX_FRIENDS_NUM) + return; + if (length >= TOXIC_MAX_NAME_LENGTH) { /* length includes null byte */ string[TOXIC_MAX_NAME_LENGTH] = L'\0'; length = TOXIC_MAX_NAME_LENGTH+1; } + /* Append friendnumber to duplicate nicks to guarantee uniqueness */ + int n = get_friendnum(string); + + if (n != friendnumber && n != -1) { + char n_buf[strlen(string)+4]; /* must have room for chars relative to MAX_FRIENDS_NUM */ + snprintf(n_buf, sizeof(n_buf), "%s%d", string, friendnumber); + strcpy(string, n_buf); + length = strlen(string) + 1; + } + int i; for (i = 0; i < MAX_WINDOWS_NUM; ++i) {