diff --git a/src/execute.c b/src/execute.c index 927e5f4..f4b4d9f 100644 --- a/src/execute.c +++ b/src/execute.c @@ -85,18 +85,19 @@ static struct cmd_func chat_commands[] = { }; static struct cmd_func group_commands[] = { - { "/chatid", cmd_chatid }, - { "/ignore", cmd_ignore }, - { "/passwd", cmd_set_passwd }, - { "/privacy", cmd_set_privacy }, - { "/rejoin", cmd_rejoin }, - { "/topic", cmd_set_topic }, - { "/unignore", cmd_unignore }, + { "/chatid", cmd_chatid }, + { "/ignore", cmd_ignore }, + { "/passwd", cmd_set_passwd }, + { "/peerlimit", cmd_set_peerlimit }, + { "/privacy", cmd_set_privacy }, + { "/rejoin", cmd_rejoin }, + { "/topic", cmd_set_topic }, + { "/unignore", cmd_unignore }, #ifdef AUDIO - { "/mute", cmd_mute }, - { "/sense", cmd_sense }, + { "/mute", cmd_mute }, + { "/sense", cmd_sense }, #endif /* AUDIO */ - { NULL, NULL }, + { NULL, NULL }, }; #define NUM_SPECIAL_COMMANDS 8 diff --git a/src/group_commands.c b/src/group_commands.c index 734a823..92cc4d2 100644 --- a/src/group_commands.c +++ b/src/group_commands.c @@ -21,6 +21,7 @@ */ #include +#include #include "toxic.h" #include "windows.h" @@ -112,6 +113,47 @@ void cmd_set_passwd(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar } } +void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) +{ + int maxpeers = 0; + + if (argc < 1) { + maxpeers = tox_group_get_peer_limit(m, self->num); + + if (maxpeers == -1) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve peer limit"); + return; + } + + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit is set to %d", maxpeers); + return; + } + + maxpeers = atoi(argv[1]); + + if (maxpeers <= 0) { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit must be a value greater than 0"); + return; + } + + int ret = tox_group_set_peer_limit(m, self->num, (uint32_t) maxpeers); + + switch (ret) { + case 0: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer limit has been set to %d", maxpeers); + return; + } + case -2: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "You do not have permission to set the peer limit."); + return; + } + default: { + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set the peer limit"); + return; + } + } +} + void cmd_set_privacy(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { const char *pstate_str = NULL; diff --git a/src/group_commands.h b/src/group_commands.h index 8d83043..bd536c0 100644 --- a/src/group_commands.h +++ b/src/group_commands.h @@ -29,6 +29,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_set_peerlimit(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_privacy(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]); diff --git a/src/groupchat.c b/src/groupchat.c index d966f4a..e37e565 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -70,9 +70,9 @@ extern struct user_settings *user_settings; extern struct Winthread Winthread; #ifdef AUDIO -#define AC_NUM_GROUP_COMMANDS 30 +#define AC_NUM_GROUP_COMMANDS 31 #else -#define AC_NUM_GROUP_COMMANDS 26 +#define AC_NUM_GROUP_COMMANDS 27 #endif /* AUDIO */ /* groupchat command names used for tab completion. */ @@ -95,6 +95,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { { "/nick" }, { "/note" }, { "/passwd" }, + { "/peerlimit" }, { "/privacy" }, { "/quit" }, { "/rejoin" }, diff --git a/src/help.c b/src/help.c index 973c05a..4f0f065 100644 --- a/src/help.c +++ b/src/help.c @@ -246,6 +246,7 @@ static void help_draw_group(ToxWindow *self) wprintw(win, " /chatid : Print the group chat id to share with others.\n"); wprintw(win, " /ignore : Ignore peer\n"); wprintw(win, " /passwd : Set group password (leave blank to unset)\n"); + wprintw(win, " /peerlimit : Set group peer limit\n"); wprintw(win, " /privacy : Set group privacy state: private|public\n"); wprintw(win, " /rejoin : Rejoin the group\n"); wprintw(win, " /topic : Set group topic (show current topic if no msg)\n"); @@ -309,7 +310,7 @@ void help_onKey(ToxWindow *self, wint_t key) break; case 'r': - help_init_window(self, 13, 80); + help_init_window(self, 14, 80); self->help->type = HELP_GROUP; break;