From d76c80951b61500ee26664aa6a1dabb0c28b967a Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 23 Sep 2013 15:43:02 -0400 Subject: [PATCH] set friendnames using api function --- src/prompt.c | 3 --- src/windows.c | 6 ++++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/prompt.c b/src/prompt.c index 9a55a29..7df2d7c 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -226,8 +226,6 @@ static void prompt_onConnectionChange(ToxWindow *self, Tox *m, int friendnum , u if (tox_getname(m, friendnum, nick) == -1) return; - nick[TOXIC_MAX_NAME_LENGTH] = '\0'; - if (!nick[0]) snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME); @@ -281,7 +279,6 @@ static void prompt_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint if (tox_getname(m, friendnumber, name) == -1) return; - name[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */ wprintw(self->window, "\nGroup chat invite from %s.\n", name); int ngc = get_num_groupchats(); diff --git a/src/windows.c b/src/windows.c index cea50d9..3ba8509 100644 --- a/src/windows.c +++ b/src/windows.c @@ -64,17 +64,19 @@ void on_nickchange(Tox *m, int friendnumber, uint8_t *string, uint16_t length, v if (length >= TOXIC_MAX_NAME_LENGTH) { /* length includes null byte */ string[TOXIC_MAX_NAME_LENGTH] = L'\0'; - length = TOXIC_MAX_NAME_LENGTH+1; + length = TOXIC_MAX_NAME_LENGTH + 1; + tox_setfriendname(m, friendnumber, string, length); } /* 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 */ + char n_buf[strlen(string)+4]; /* must have room for friendnum chars relative to MAX_FRIENDS_NUM */ snprintf(n_buf, sizeof(n_buf), "%s%d", string, friendnumber); strcpy(string, n_buf); length = strlen(n_buf) + 1; + tox_setfriendname(m, friendnumber, string, length); } int i;