From d76c80951b61500ee26664aa6a1dabb0c28b967a Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Mon, 23 Sep 2013 15:43:02 -0400 Subject: [PATCH 1/3] 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; From bd3c14104ab73c181773608931732ccf3684f731 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 24 Sep 2013 16:12:33 -0400 Subject: [PATCH 2/3] command fixes --- src/chat.c | 2 +- src/commands.c | 33 +++++++++++++++++++++------------ src/groupchat.c | 2 +- src/main.c | 4 ++++ src/prompt.c | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/chat.c b/src/chat.c index c214860..17d323d 100644 --- a/src/chat.c +++ b/src/chat.c @@ -118,7 +118,7 @@ static void print_chat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/commands.c b/src/commands.c index ab40367..5a57af4 100644 --- a/src/commands.c +++ b/src/commands.c @@ -48,7 +48,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) { - if (argc < 1 || argc > 2) { + if (argc < 1) { wprintw(window, "Invalid syntax.\n"); return; } @@ -62,7 +62,7 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) uint8_t *msg; - if (argc == 2) { + if (argc > 1) { msg = argv[2]; if (msg == NULL) { @@ -71,7 +71,7 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) } if (msg[0] != '\"') { - wprintw(window, "Messages must be enclosed in quotes.\n"); + wprintw(window, "Message must be enclosed in quotes.\n"); return; } @@ -192,12 +192,12 @@ void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **a int groupnum = tox_add_groupchat(m); if (groupnum == -1) { - wprintw(window, "Group chat failed to initialize.\n"); + wprintw(window, "Group chat instnace failed to initialize.\n"); return; } if (init_groupchat_win(prompt, m, groupnum) == -1) { - wprintw(window, "Group chat failed to initialize.\n"); + wprintw(window, "Group chat window failed to initialize.\n"); tox_del_groupchat(m, groupnum); return; } @@ -235,7 +235,7 @@ void cmd_invite(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv return; } - wprintw(window, "Invited friend %s to group chat %d.\n", friendname, groupnum); + wprintw(window, "Invited '%s' to group chat %d.\n", friendname, groupnum); } void cmd_join(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) @@ -281,25 +281,34 @@ void cmd_join(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) void cmd_msg(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) { /* check arguments */ - if (argc != 2) { + if (argc < 2) { wprintw(window, "Invalid syntax.\n"); return; } - char *id = argv[1]; + uint8_t *name = argv[1]; uint8_t *msg = argv[2]; - if (id == NULL || msg == NULL) { + if (name == NULL || msg == NULL) { wprintw(window, "Invalid syntax.\n"); return; } + if (msg[0] != '\"') { + wprintw(window, "Messages must be enclosed in quotes.\n"); + return; + } + msg[strlen(++msg)-1] = L'\0'; + int friendnum = get_friendnum(name); - if (tox_sendmessage(m, atoi(id), msg, strlen(msg) + 1) == 0) + if (friendnum == -1) { + wprintw(window, "Friend '%s' not found.\n", name); + return; + } + + if (tox_sendmessage(m, friendnum, msg, strlen(msg) + 1) == 0) wprintw(window, "Failed to send message.\n"); - else - wprintw(window, "Message successfully sent.\n"); } void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) diff --git a/src/groupchat.c b/src/groupchat.c index 68ebd6d..6df0efb 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -88,7 +88,7 @@ static void print_groupchat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/main.c b/src/main.c index ca1a8a5..c2f96b9 100644 --- a/src/main.c +++ b/src/main.c @@ -19,6 +19,8 @@ #include #include #include +#include + #ifdef _WIN32 #include @@ -449,6 +451,8 @@ int main(int argc, char *argv[]) /* Draw */ draw_active_window(m); + + usleep((uint)1000); } exit_toxic(m); diff --git a/src/prompt.c b/src/prompt.c index 7df2d7c..08d82d4 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -99,7 +99,7 @@ static void print_prompt_help(ToxWindow *self) wprintw(self->window, " /clear : Clear this window\n"); wattron(self->window, A_BOLD); - wprintw(self->window, " * Messages must be enclosed in quotation marks.\n"); + wprintw(self->window, " * Command argument messages must be enclosed in quotation marks.\n"); wprintw(self->window, " * Use the TAB key to navigate through the tabs.\n"); wattroff(self->window, A_BOLD); From 051069606b4bf76e55171bf2952778661bf2337b Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 24 Sep 2013 16:18:22 -0400 Subject: [PATCH 3/3] typo and slight word change --- src/chat.c | 2 +- src/commands.c | 2 +- src/groupchat.c | 2 +- src/prompt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chat.c b/src/chat.c index 17d323d..7768035 100644 --- a/src/chat.c +++ b/src/chat.c @@ -118,7 +118,7 @@ static void print_chat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/commands.c b/src/commands.c index 5a57af4..a2c7db1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -192,7 +192,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **a int groupnum = tox_add_groupchat(m); if (groupnum == -1) { - wprintw(window, "Group chat instnace failed to initialize.\n"); + wprintw(window, "Group chat instance failed to initialize.\n"); return; } diff --git a/src/groupchat.c b/src/groupchat.c index 6df0efb..3527194 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -88,7 +88,7 @@ static void print_groupchat_help(ChatContext *ctx) wprintw(ctx->history, " /help : Print this message again\n"); wattron(ctx->history, A_BOLD); - wprintw(ctx->history, "\n * Command argument messages must be enclosed in quotation marks.\n"); + wprintw(ctx->history, "\n * Argument messages must be enclosed in quotation marks.\n"); wattroff(ctx->history, A_BOLD); wattroff(ctx->history, COLOR_PAIR(CYAN)); diff --git a/src/prompt.c b/src/prompt.c index 08d82d4..9c9ddc3 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -99,7 +99,7 @@ static void print_prompt_help(ToxWindow *self) wprintw(self->window, " /clear : Clear this window\n"); wattron(self->window, A_BOLD); - wprintw(self->window, " * Command argument messages must be enclosed in quotation marks.\n"); + wprintw(self->window, " * Argument messages must be enclosed in quotation marks.\n"); wprintw(self->window, " * Use the TAB key to navigate through the tabs.\n"); wattroff(self->window, A_BOLD);