1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 19:53:25 +01:00

add ability for founder to set group peer limit

This commit is contained in:
Jfreegman 2015-05-24 03:27:50 -04:00
parent 29d0384a90
commit a6d7e9b839
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 59 additions and 13 deletions

View File

@ -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

View File

@ -21,6 +21,7 @@
*/
#include <string.h>
#include <stdlib.h>
#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;

View File

@ -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]);

View File

@ -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" },

View File

@ -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 <nick> : Ignore peer\n");
wprintw(win, " /passwd <password> : Set group password (leave blank to unset)\n");
wprintw(win, " /peerlimit <num> : Set group peer limit\n");
wprintw(win, " /privacy <state> : Set group privacy state: private|public\n");
wprintw(win, " /rejoin : Rejoin the group\n");
wprintw(win, " /topic <msg> : 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;