1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-13 02:23:01 +01:00

guarantee unique nicks

This commit is contained in:
Jfreegman 2013-09-22 20:25:48 -04:00
parent 7fed456e3b
commit bde7aacc8d
2 changed files with 14 additions and 1 deletions

View File

@ -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;
}

View File

@ -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) {