mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 19:23:25 +01:00
implement group passwords
This commit is contained in:
parent
f82d58bbfc
commit
f021908f8b
@ -63,9 +63,9 @@ static void kill_infobox(ToxWindow *self);
|
||||
#endif /* AUDIO */
|
||||
|
||||
#ifdef AUDIO
|
||||
#define AC_NUM_CHAT_COMMANDS 27
|
||||
#define AC_NUM_CHAT_COMMANDS 28
|
||||
#else
|
||||
#define AC_NUM_CHAT_COMMANDS 20
|
||||
#define AC_NUM_CHAT_COMMANDS 21
|
||||
#endif /* AUDIO */
|
||||
|
||||
/* Array of chat command names used for tab completion. */
|
||||
@ -78,6 +78,7 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/close" },
|
||||
{ "/connect" },
|
||||
{ "/exit" },
|
||||
{ "/gaccept" },
|
||||
{ "/group" },
|
||||
{ "/help" },
|
||||
{ "/invite" },
|
||||
@ -533,7 +534,7 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, co
|
||||
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
|
||||
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to a group chat.", name);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/gaccept\" to join the chat.");
|
||||
}
|
||||
|
||||
/* Av Stuff */
|
||||
|
@ -78,6 +78,41 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
|
||||
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, silent);
|
||||
}
|
||||
|
||||
void cmd_groupaccept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Friends.list[self->num].group_invite.length == 0) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending group invite");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *passwd = NULL;
|
||||
uint16_t passwd_len = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
passwd = argv[1];
|
||||
passwd_len = strlen(passwd);
|
||||
}
|
||||
|
||||
int groupnumber = tox_group_accept_invite(m, Friends.list[self->num].group_invite.data,
|
||||
Friends.list[self->num].group_invite.length,
|
||||
(uint8_t *) passwd, passwd_len);
|
||||
if (groupnumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (init_groupchat_win(m, groupnumber, NULL, 0) == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
|
||||
tox_group_delete(m, groupnumber, NULL, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc < 1) {
|
||||
@ -149,9 +184,6 @@ void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv
|
||||
ft->state = FILE_TRANSFER_STARTED;
|
||||
|
||||
return;
|
||||
|
||||
|
||||
|
||||
|
||||
on_recv_error:
|
||||
switch (err) {
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "windows.h"
|
||||
#include "toxic.h"
|
||||
|
||||
void cmd_groupaccept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "misc_tools.h"
|
||||
#include "notify.h"
|
||||
|
||||
#define MAX_NUM_ARGS 10 /* Includes command */
|
||||
|
||||
struct cmd_func {
|
||||
const char *name;
|
||||
void (*func)(WINDOW *w, ToxWindow *, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
@ -67,6 +69,7 @@ static struct cmd_func global_commands[] = {
|
||||
|
||||
static struct cmd_func chat_commands[] = {
|
||||
{ "/cancel", cmd_cancelfile },
|
||||
{ "/gaccept", cmd_groupaccept },
|
||||
{ "/invite", cmd_groupinvite },
|
||||
{ "/savefile", cmd_savefile },
|
||||
{ "/sendfile", cmd_sendfile },
|
||||
@ -84,6 +87,7 @@ static struct cmd_func chat_commands[] = {
|
||||
static struct cmd_func group_commands[] = {
|
||||
{ "/chatid", cmd_chatid },
|
||||
{ "/ignore", cmd_ignore },
|
||||
{ "/passwd", cmd_set_passwd },
|
||||
{ "/rejoin", cmd_rejoin },
|
||||
{ "/topic", cmd_set_topic },
|
||||
{ "/unignore", cmd_unignore },
|
||||
@ -94,15 +98,14 @@ static struct cmd_func group_commands[] = {
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
#define NUM_SPECIAL_COMMANDS 9
|
||||
#define NUM_SPECIAL_COMMANDS 8
|
||||
static const char special_commands[NUM_SPECIAL_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
"/ban",
|
||||
"/deop",
|
||||
"/gaccept",
|
||||
"/group",
|
||||
"/ignore",
|
||||
"/nick",
|
||||
"/note",
|
||||
"/op",
|
||||
"/passwd",
|
||||
"/topic",
|
||||
"/unignore"
|
||||
};
|
||||
@ -194,6 +197,10 @@ static int parse_command(WINDOW *w, ToxWindow *self, const char *input, char (*a
|
||||
strcpy(cmd, tmp); /* tmp will always fit inside cmd */
|
||||
}
|
||||
|
||||
/* Ugly special case concatinates all args after arg1 for multi-word group passwords */
|
||||
if (num_args > 2 && strcmp(args[0], "/join") == 0)
|
||||
strcpy(args[2], input + strlen(args[0]) + 1 + strlen(args[1]) + 1);
|
||||
|
||||
free(cmd);
|
||||
return num_args;
|
||||
}
|
||||
|
@ -26,8 +26,6 @@
|
||||
#include "toxic.h"
|
||||
#include "windows.h"
|
||||
|
||||
#define MAX_NUM_ARGS 4 /* Includes command */
|
||||
|
||||
enum {
|
||||
GLOBAL_COMMAND_MODE,
|
||||
CHAT_COMMAND_MODE,
|
||||
|
@ -355,23 +355,6 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
}
|
||||
}
|
||||
|
||||
static void join_invite(ToxWindow *self, Tox *m)
|
||||
{
|
||||
int groupnumber = tox_group_accept_invite(m, Friends.list[self->num].group_invite.data,
|
||||
Friends.list[self->num].group_invite.length);
|
||||
|
||||
if (groupnumber == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (init_groupchat_win(m, groupnumber, NULL, 0) == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
|
||||
tox_group_delete(m, groupnumber, NULL, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
|
||||
@ -379,15 +362,9 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
return;
|
||||
}
|
||||
|
||||
/* If no input check for a group invite */
|
||||
if (argc < 1) {
|
||||
if (!self->is_chat || Friends.list[self->num].group_invite.length == 0) {
|
||||
const char *msg = "You must either be invited to a group or input the group ID of the group you wish to join.";
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
return join_invite(self, m);
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Chat ID is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
const char *chat_id = argv[1];
|
||||
@ -416,10 +393,18 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
id_bin[i] = x;
|
||||
}
|
||||
|
||||
int groupnum = tox_group_new_join(m, (uint8_t *) id_bin);
|
||||
const char *passwd = NULL;
|
||||
uint16_t passwd_len = 0;
|
||||
|
||||
if (argc > 1) {
|
||||
passwd = argv[2];
|
||||
passwd_len = strlen(passwd);
|
||||
}
|
||||
|
||||
int groupnum = tox_group_new_join(m, (uint8_t *) id_bin, (uint8_t *) passwd, passwd_len);
|
||||
|
||||
if (groupnum == -1) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to join group.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,42 @@ void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
|
||||
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 1, BLUE, "-!- Ignoring %s", nick);
|
||||
}
|
||||
|
||||
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
const char *passwd = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
passwd = argv[1];
|
||||
len = strlen(passwd);
|
||||
}
|
||||
|
||||
if (len > TOX_MAX_GROUP_PASSWD_SIZE) {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password exceeds %d character limit", TOX_MAX_GROUP_PASSWD_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = tox_group_set_password(m, self->num, (uint8_t *) passwd, len);
|
||||
|
||||
switch (ret) {
|
||||
case 0: {
|
||||
if (len > 0)
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password has been set to %s", passwd);
|
||||
else
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Password has been unset");
|
||||
return;
|
||||
}
|
||||
case -2: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the password");
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error setting password");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (tox_group_reconnect(m, self->num) == -1)
|
||||
@ -111,7 +147,7 @@ void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
||||
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
|
||||
tox_self_get_name(m, (uint8_t *) selfnick);
|
||||
size_t sn_len = tox_self_get_name_size(m);
|
||||
selfnick[sn_len] = '\0';
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_ignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_rejoin(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
void cmd_unignore(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
|
||||
|
@ -70,9 +70,9 @@ extern struct user_settings *user_settings;
|
||||
extern struct Winthread Winthread;
|
||||
|
||||
#ifdef AUDIO
|
||||
#define AC_NUM_GROUP_COMMANDS 28
|
||||
#define AC_NUM_GROUP_COMMANDS 29
|
||||
#else
|
||||
#define AC_NUM_GROUP_COMMANDS 24
|
||||
#define AC_NUM_GROUP_COMMANDS 25
|
||||
#endif /* AUDIO */
|
||||
|
||||
/* groupchat command names used for tab completion. */
|
||||
@ -97,6 +97,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
||||
{ "/quit" },
|
||||
{ "/rejoin" },
|
||||
{ "/requests" },
|
||||
{ "/passwd" },
|
||||
{ "/status" },
|
||||
{ "/topic" },
|
||||
{ "/unignore" },
|
||||
@ -552,8 +553,8 @@ static void groupchat_onGroupRejected(ToxWindow *self, Tox *m, int groupnum, uin
|
||||
case TOX_GJ_GROUP_FULL:
|
||||
msg = "Group is full. Try again with the 'rejoin' command.";
|
||||
break;
|
||||
case TOX_GJ_INVITES_DISABLED:
|
||||
msg = "Invites for this group have been disabled.";
|
||||
case TOX_GJ_INCORRECT_PASSWORD:
|
||||
msg = "Invalid password.";
|
||||
break;
|
||||
case TOX_GJ_INVITE_FAILED:
|
||||
msg = "Invite failed. Try again with the 'rejoin' command.";
|
||||
|
@ -151,7 +151,7 @@ static void help_draw_global(ToxWindow *self)
|
||||
wprintw(win, " /status <type> <msg> : Set status with optional note\n");
|
||||
wprintw(win, " /note <msg> : Set a personal note\n");
|
||||
wprintw(win, " /group : Create a group chat\n");
|
||||
wprintw(win, " /join <chat id> : Join a group chat\n");
|
||||
wprintw(win, " /join <chat id> <passwd> : Join a group chat with optional password\n");
|
||||
wprintw(win, " /nick <nick> : Set your nickname\n");
|
||||
wprintw(win, " /log <on> or <off> : Enable/disable logging\n");
|
||||
wprintw(win, " /myid : Print your Tox ID\n");
|
||||
@ -184,6 +184,7 @@ static void help_draw_chat(ToxWindow *self)
|
||||
wprintw(win, "Chat Commands:\n");
|
||||
wattroff(win, A_BOLD | COLOR_PAIR(RED));
|
||||
|
||||
wprintw(win, " /gaccept <password> : Accept a group invite with optional password\n");
|
||||
wprintw(win, " /sendfile <path> : Send a file\n");
|
||||
wprintw(win, " /savefile <id> : Receive a file\n");
|
||||
wprintw(win, " /cancel <type> <id> : Cancel file transfer where type: in|out\n");
|
||||
@ -244,7 +245,8 @@ static void help_draw_group(ToxWindow *self)
|
||||
|
||||
wprintw(win, " /chatid : Print the group chat id to share with others.\n");
|
||||
wprintw(win, " /ignore <nick> : Ignore peer\n");
|
||||
wprintw(win, " /rejoin : Rejoin the group (only works if not connected)\n");
|
||||
wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n");
|
||||
wprintw(win, " /rejoin : Rejoin the group\n");
|
||||
wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
|
||||
wprintw(win, " /unignore <nick> : Unignore peer \n");
|
||||
wprintw(win, " /whisper <nick> <msg> : Send private message to nick\n\n");
|
||||
@ -306,7 +308,7 @@ void help_onKey(ToxWindow *self, wint_t key)
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
help_init_window(self, 6, 80);
|
||||
help_init_window(self, 12, 80);
|
||||
self->help->type = HELP_GROUP;
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user