From 2982dc6ddd54cc343527d4958d8f3e8c360013e6 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 21 Feb 2014 21:21:12 -0500 Subject: [PATCH] show pseudo-unique identifier in friend chat windows --- src/chat.c | 15 ++++++++++++--- src/friendlist.c | 1 + src/friendlist.h | 3 +++ src/main.c | 3 +++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/chat.c b/src/chat.c index efec9fa..c404a1e 100644 --- a/src/chat.c +++ b/src/chat.c @@ -547,9 +547,9 @@ static void chat_onDraw(ToxWindow *self, Tox *m) self->x = x2; /* Truncate note if it doesn't fit in statusbar */ - uint16_t maxlen = x2 - getcurx(statusbar->topline) - 4; + uint16_t maxlen = x2 - getcurx(statusbar->topline) - (KEY_IDENT_DIGITS * 2) - 6; if (statusbar->statusmsg_len > maxlen) { - statusbar->statusmsg[maxlen] = '\0'; + statusbar->statusmsg[maxlen-1] = '\0'; statusbar->statusmsg_len = maxlen; } @@ -559,7 +559,16 @@ static void chat_onDraw(ToxWindow *self, Tox *m) wattroff(statusbar->topline, A_BOLD); } - wprintw(statusbar->topline, "\n"); + wclrtoeol(statusbar->topline); + wmove(statusbar->topline, 0, x2 - (KEY_IDENT_DIGITS * 2) - 3); + wprintw(statusbar->topline, "{"); + + int i; + + for (i = 0; i < KEY_IDENT_DIGITS; ++i) + wprintw(statusbar->topline, "%x", friends[self->num].pub_key[i] & 0xff); + + wprintw(statusbar->topline, "}\n"); mvwhline(ctx->linewin, 0, 0, ACS_HLINE, x2); } diff --git a/src/friendlist.c b/src/friendlist.c index f569405..2e425d0 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -130,6 +130,7 @@ static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort friends[i].online = false; friends[i].status = TOX_USERSTATUS_NONE; friends[i].namelength = tox_get_name(m, num, friends[i].name); + tox_get_client_id(m, num, friends[i].pub_key); if (friends[i].namelength == -1 || friends[i].name[0] == '\0') { strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME); diff --git a/src/friendlist.h b/src/friendlist.h index 3abc781..0dd4a8f 100644 --- a/src/friendlist.h +++ b/src/friendlist.h @@ -3,12 +3,15 @@ #include "toxic_windows.h" +#define KEY_IDENT_DIGITS 2 + typedef struct { uint8_t name[TOX_MAX_NAME_LENGTH]; uint16_t namelength; uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH]; uint16_t statusmsg_len; uint8_t pending_groupchat[TOX_CLIENT_ID_SIZE]; + uint8_t pub_key[TOX_CLIENT_ID_SIZE]; int num; int chatwin; bool active; diff --git a/src/main.c b/src/main.c index 465bb7b..3b9bcc1 100644 --- a/src/main.c +++ b/src/main.c @@ -470,6 +470,9 @@ int main(int argc, char *argv[]) int i = 0; int f_use_ipv4 = 0; + // Make sure all written files are read/writeable only by the current user. + umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + for (i = 0; i < argc; ++i) { if (argv[i] == NULL) break;