1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 14:13:27 +01:00

Add /list command that lists all group peers w/ public keys

This commit is contained in:
jfreegman 2021-11-12 11:32:37 -05:00
parent 85f9c1241c
commit 408c8f7c10
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
5 changed files with 34 additions and 4 deletions

View File

@ -127,6 +127,7 @@ static struct cmd_func groupchat_commands[] = {
{ "/disconnect",cmd_disconnect },
{ "/ignore", cmd_ignore },
{ "/kick", cmd_kick },
{ "/list", cmd_list },
{ "/mod", cmd_mod },
{ "/passwd", cmd_set_passwd },
{ "/peerlimit", cmd_set_peerlimit },

View File

@ -162,6 +162,34 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
}
}
void cmd_list(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
GroupChat *chat = get_groupchat(self->num);
if (!chat) {
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to fetch GroupChat object.");
return;
}
for (size_t i = 0; i < chat->max_idx; ++i) {
GroupPeer *peer = &chat->peer_list[i];
if (!peer->active) {
continue;
}
char pk_string[TOX_GROUP_PEER_PUBLIC_KEY_SIZE * 2 + 1] = {0};
for (size_t j = 0; j < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++j) {
char d[3];
snprintf(d, sizeof(d), "%02X", peer->public_key[j] & 0xff);
strcat(pk_string, d);
}
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "%s : %s", pk_string, peer->name);
}
}
void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
@ -689,15 +717,13 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[M
get_unix_time() - chat->peer_list[peer_index].last_active);
char pk_string[TOX_GROUP_PEER_PUBLIC_KEY_SIZE * 2 + 1] = {0};
size_t i;
for (i = 0; i < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++i) {
for (size_t i = 0; i < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++i) {
char d[3];
snprintf(d, sizeof(d), "%02X", chat->peer_list[peer_index].public_key[i] & 0xff);
strcat(pk_string, d);
}
TOX_ERR_GROUP_PEER_QUERY conn_err;
Tox_Connection connection_type = tox_group_peer_get_connection_status(m, self->num, peer_id, &conn_err);

View File

@ -30,6 +30,7 @@ void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[
void cmd_disconnect(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_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_list(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_mod(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_prune(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]);

View File

@ -88,6 +88,7 @@ static const char *group_cmd_list[] = {
"/ignore",
"/join",
"/kick",
"/list",
"/log",
"/mod",
"/myid",

View File

@ -302,6 +302,7 @@ static void help_draw_groupchats(ToxWindow *self)
wprintw(win, " /ignore <name> : Ignore a peer\n");
wprintw(win, " /unignore <name> : Unignore an ignored peer\n");
wprintw(win, " /kick <name> : Remove a peer from the group\n");
wprintw(win, " /list : Print a list of peers currently in the group\n");
wprintw(win, " /mod <name> : Promote a peer to moderator\n");
wprintw(win, " /passwd <s> : Set a password needed to join the group\n");
wprintw(win, " /peerlimit <n> : Set the maximum number of peers that can join\n");
@ -488,7 +489,7 @@ void help_onKey(ToxWindow *self, wint_t key)
break;
case L'r':
help_init_window(self, 23, 80);
help_init_window(self, 24, 80);
self->help->type = HELP_GROUP;
break;
}