1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-13 01:13:02 +01:00
This commit is contained in:
Jfreegman 2013-11-12 02:41:55 -05:00
parent 7542247c48
commit 5570b7c98a
9 changed files with 61 additions and 64 deletions

View File

@ -330,7 +330,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
} else if (!strncmp(line, "/me ", strlen("/me ")))
send_action(self, ctx, m, line + strlen("/me "));
else
execute(ctx->history, self->prompt, m, line, CHAT_COMMAND_MODE);
execute(ctx->history, self->prompt, m, self->num, line, CHAT_COMMAND_MODE);
} else {
/* make sure the string has at least non-space character */
if (!string_is_empty(line)) {
@ -469,7 +469,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, 0, x, y-4, 0);
wprintw(ctx->history, "\n\n");
execute(ctx->history, self->prompt, m, "/help", CHAT_COMMAND_MODE);
execute(ctx->history, self->prompt, m, self->num, "/help", CHAT_COMMAND_MODE);
wmove(self->window, y - CURS_Y_OFFSET, 0);
}

View File

@ -14,7 +14,7 @@
extern uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
void cmd_chat_help(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_chat_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(window, "Chat commands:\n");
@ -41,7 +41,7 @@ void cmd_chat_help(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*
wattroff(window, COLOR_PAIR(CYAN));
}
void cmd_groupinvite(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_groupinvite(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
wprintw(window, "Invalid syntax.\n");
@ -55,7 +55,7 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char
return;
}
if (tox_invite_friend(m, chatwin->num, groupnum) == -1) {
if (tox_invite_friend(m, num, groupnum) == -1) {
wprintw(window, "Failed to invite friend.\n");
return;
}
@ -63,28 +63,28 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char
wprintw(window, "Invited friend to group chat %d.\n", groupnum);
}
void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc != 1) {
wprintw(window, "Invalid syntax.\n");
return;
}
int num = atoi(argv[1]);
int g_num = atoi(argv[1]);
if ((num == 0 && strcmp(argv[1], "0")) || num >= MAX_FRIENDS_NUM) {
if ((g_num == 0 && strcmp(argv[1], "0")) || g_num >= MAX_FRIENDS_NUM) {
wprintw(window, "No pending group chat invite with that number.\n");
return;
}
uint8_t *groupkey = pending_grp_requests[num];
uint8_t *groupkey = pending_grp_requests[g_num];
if (!strlen(groupkey)) {
wprintw(window, "No pending group chat invite with that number.\n");
return;
}
int groupnum = tox_join_groupchat(m, num, groupkey);
int groupnum = tox_join_groupchat(m, g_num, groupkey);
if (groupnum == -1) {
wprintw(window, "Group chat instance failed to initialize.\n");
@ -98,7 +98,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*
}
}
void cmd_savefile(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_savefile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc != 1) {
wprintw(window, "Invalid syntax.\n");
@ -112,24 +112,22 @@ void cmd_savefile(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*a
return;
}
int friendnum = chatwin->num;
if (!friends[friendnum].file_receiver.pending[filenum]) {
if (!friends[num].file_receiver.pending[filenum]) {
wprintw(window, "No pending file transfers with that number.\n");
return;
}
uint8_t *filename = friends[friendnum].file_receiver.filenames[filenum];
uint8_t *filename = friends[num].file_receiver.filenames[filenum];
if (tox_file_sendcontrol(m, friendnum, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0))
if (tox_file_sendcontrol(m, num, 1, filenum, TOX_FILECONTROL_ACCEPT, 0, 0))
wprintw(window, "Accepted file transfer %u. Saving file as: '%s'\n", filenum, filename);
else
wprintw(window, "File transfer failed.\n");
friends[friendnum].file_receiver.pending[filenum] = false;
friends[num].file_receiver.pending[filenum] = false;
}
void cmd_sendfile(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_sendfile(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (num_file_senders >= MAX_FILES) {
wprintw(window,"Please wait for some of your outgoing file transfers to complete.\n");
@ -167,8 +165,7 @@ void cmd_sendfile(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*a
uint64_t filesize = ftell(file_to_send);
fseek(file_to_send, 0, SEEK_SET);
int friendnum = chatwin->num;
int filenum = tox_new_filesender(m, friendnum, filesize, path, path_len + 1);
int filenum = tox_new_filesender(m, num, filesize, path, path_len + 1);
if (filenum == -1) {
wprintw(window, "Error sending file.\n");
@ -184,9 +181,9 @@ void cmd_sendfile(WINDOW *window, ToxWindow *chatwin, Tox *m, int argc, char (*a
file_senders[i].chatwin = window;
file_senders[i].file = file_to_send;
file_senders[i].filenum = (uint8_t) filenum;
file_senders[i].friendnum = friendnum;
file_senders[i].friendnum = num;
file_senders[i].piecelen = fread(file_senders[i].nextpiece, 1,
tox_filedata_size(m, friendnum), file_to_send);
tox_filedata_size(m, num), file_to_send);
wprintw(window, "Sending file: '%s'\n", path);

View File

@ -2,8 +2,8 @@
* Toxic -- Tox Curses Client
*/
void cmd_chat_help(WINDOW *w, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupinvite(WINDOW *w, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_join_group(WINDOW *w, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_savefile(WINDOW *w, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_sendfile(WINDOW *w, ToxWindow *chatwin, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_chat_help(WINDOW *w, ToxWindow *chatwin, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupinvite(WINDOW *w, ToxWindow *chatwin, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_join_group(WINDOW *w, ToxWindow *chatwin, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_savefile(WINDOW *w, ToxWindow *chatwin, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_sendfile(WINDOW *w, ToxWindow *chatwin, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -12,7 +12,7 @@
struct cmd_func {
const char *name;
void (*func)(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void (*func)(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
};
#define GLOBAL_NUM_COMMANDS 12
@ -78,14 +78,14 @@ static int parse_command(WINDOW *w, char *cmd, char (*args)[MAX_STR_SIZE])
}
/* Matches command to respective function. Returns 0 on match, 1 on no match */
static int do_command(WINDOW *w, ToxWindow *prompt, Tox *m, int num_args, int num_cmds,
static int do_command(WINDOW *w, ToxWindow *prompt, Tox *m, int num, int num_args, int num_cmds,
struct cmd_func *commands, char (*args)[MAX_STR_SIZE])
{
int i;
for (i = 0; i < num_cmds; ++i) {
if (strcmp(args[0], commands[i].name) == 0) {
(commands[i].func)(w, prompt, m, num_args-1, args);
(commands[i].func)(w, prompt, m, num, num_args-1, args);
return 0;
}
}
@ -93,7 +93,7 @@ static int do_command(WINDOW *w, ToxWindow *prompt, Tox *m, int num_args, int nu
return 1;
}
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, char *cmd, int mode)
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode)
{
if (string_is_empty(cmd))
return;
@ -108,7 +108,7 @@ void execute(WINDOW *w, ToxWindow *prompt, Tox *m, char *cmd, int mode)
try specified mode's commands first, then upon failure try global commands. */
switch (mode) {
case CHAT_COMMAND_MODE:
if (do_command(w, prompt, m, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
if (do_command(w, prompt, m, num, num_args, CHAT_NUM_COMMANDS, chat_commands, args) == 0)
return;
break;
@ -116,7 +116,7 @@ void execute(WINDOW *w, ToxWindow *prompt, Tox *m, char *cmd, int mode)
break;
}
if (do_command(w, prompt, m, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
if (do_command(w, prompt, m, num, num_args, GLOBAL_NUM_COMMANDS, global_commands, args) == 0)
return;
wprintw(w, "Invalid command.\n");

View File

@ -10,4 +10,4 @@ enum {
GROUPCHAT_COMMAND_MODE,
};
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, char *cmd, int mode);
void execute(WINDOW *w, ToxWindow *prompt, Tox *m, int num, char *cmd, int mode);

View File

@ -18,7 +18,7 @@ extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_frnd_requests;
/* command functions */
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
/* check arguments */
if (argc != 1) {
@ -26,19 +26,19 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv
return;
}
int num = atoi(argv[1]);
int req = atoi(argv[1]);
if ((num == 0 && strcmp(argv[1], "0"))|| num >= MAX_FRIENDS_NUM) {
if ((req == 0 && strcmp(argv[1], "0"))|| req >= MAX_FRIENDS_NUM) {
wprintw(window, "No pending friend request with that number.\n");
return;
}
if (!strlen(pending_frnd_requests[num])) {
if (!strlen(pending_frnd_requests[req])) {
wprintw(window, "No pending friend request with that number.\n");
return;
}
int friendnum = tox_addfriend_norequest(m, pending_frnd_requests[num]);
int friendnum = tox_addfriend_norequest(m, pending_frnd_requests[req]);
if (friendnum == -1)
wprintw(window, "Failed to add friend.\n");
@ -47,7 +47,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv
on_friendadded(m, friendnum);
}
memset(&pending_frnd_requests[num], 0, TOX_CLIENT_ID_SIZE);
memset(&pending_frnd_requests[req], 0, TOX_CLIENT_ID_SIZE);
int i;
@ -59,7 +59,7 @@ void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv
num_frnd_requests = i;
}
void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
wprintw(window, "Invalid syntax.\n");
@ -109,9 +109,9 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[M
id[i] = toupper(id[i]);
}
int num = tox_addfriend(m, id_bin, msg, strlen(msg) + 1);
int f_num = tox_addfriend(m, id_bin, msg, strlen(msg) + 1);
switch (num) {
switch (f_num) {
case TOX_FAERR_TOOLONG:
wprintw(window, "Message is too long.\n");
break;
@ -135,18 +135,18 @@ void cmd_add(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[M
break;
default:
wprintw(window, "Friend request sent.\n");
on_friendadded(m, num);
on_friendadded(m, f_num);
break;
}
}
void cmd_clear(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_clear(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
wclear(window);
wprintw(window, "\n\n");
}
void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
/* check arguments */
if (argc != 3) {
@ -170,7 +170,7 @@ void cmd_connect(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*arg
free(binary_string);
}
void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
int ngc = get_num_groupchats();
@ -195,7 +195,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*a
wprintw(window, "Group chat created as %d.\n", groupnum);
}
void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
char id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1] = {0};
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
@ -212,7 +212,7 @@ void cmd_myid(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[
wprintw(window, "%s\n", id);
}
void cmd_nick(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_nick(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
/* check arguments */
if (argc != 1) {
@ -240,7 +240,7 @@ void cmd_nick(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[
store_data(m, DATA_FILE);
}
void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
wprintw(window, "Wrong number of arguments.\n");
@ -260,12 +260,12 @@ void cmd_note(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[
prompt_update_statusmessage(prompt, msg, len);
}
void cmd_quit(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_quit(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
exit_toxic(m);
}
void cmd_status(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_status(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
{
uint8_t *msg = NULL;

View File

@ -2,13 +2,13 @@
* Toxic -- Tox Curses Client
*/
void cmd_accept(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_add(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_clear(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_connect(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupchat(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_myid(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_nick(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_note(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_quit(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_status(WINDOW *, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_accept(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_add(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_clear(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_connect(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupchat(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_myid(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_nick(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_note(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_quit(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_status(WINDOW *, ToxWindow *, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -170,7 +170,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
} else if (strncmp(line, "/help", strlen("/help")) == 0)
print_groupchat_help(ctx);
else
execute(ctx->history, self->prompt, m, line, GROUPCHAT_COMMAND_MODE);
execute(ctx->history, self->prompt, m, self->num, line, GROUPCHAT_COMMAND_MODE);
} else {
/* make sure the string has at least non-space character */
if (!string_is_empty(line)) {

View File

@ -133,7 +133,7 @@ static void prompt_onKey(ToxWindow *self, Tox *m, wint_t key)
if (!strncmp(prompt_buf, "/help", strlen("/help")))
print_prompt_help(self);
else
execute(self->window, self, m, prompt_buf, GLOBAL_COMMAND_MODE);
execute(self->window, self, m, self->num, prompt_buf, GLOBAL_COMMAND_MODE);
prompt_buf_pos = 0;
prompt_buf[0] = '\0';