1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-15 07:33:01 +01:00

fix ban API calls

This commit is contained in:
Jfreegman 2015-06-08 21:56:32 -04:00
parent b36ada0f5b
commit 1ba0891f71
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63

View File

@ -119,27 +119,21 @@ void cmd_kick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
void cmd_ban(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_ban(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {
int banlist_size = tox_group_get_ban_list_size(m, self->num); int num_banned = tox_group_get_ban_list_size(m, self->num);
if (banlist_size == -1) { if (num_banned == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to get the ban list."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to get the ban list.");
return; return;
} }
if (banlist_size == 0) { if (num_banned == 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ban list is empty."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ban list is empty.");
return; return;
} }
struct Tox_Group_Ban *ban_list = malloc(banlist_size); struct Tox_Group_Ban ban_list[num_banned];
if (ban_list == NULL) if (tox_group_get_ban_list(m, self->num, ban_list) == -1) {
return;
int num_banned = tox_group_get_ban_list(m, self->num, ban_list);
if (num_banned == -1) {
free(ban_list);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to get the ban list."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to get the ban list.");
return; return;
} }
@ -147,14 +141,14 @@ void cmd_ban(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
uint16_t i; uint16_t i;
for (i = 0; i < num_banned; ++i) { for (i = 0; i < num_banned; ++i) {
ban_list[i].nick[ban_list[i].nick_len] = '\0';
struct tm tm_set = *localtime((const time_t *) &ban_list[i].time_set); struct tm tm_set = *localtime((const time_t *) &ban_list[i].time_set);
char time_str[64]; char time_str[64];
strftime(time_str, sizeof(time_str), "%e %b %Y %H:%M:%S%p", &tm_set); strftime(time_str, sizeof(time_str), "%e %b %Y %H:%M:%S%p", &tm_set);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "[ID: %d] %s : %s : %s", ban_list[i].id, line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "ID %d : %s [Set:%s]", ban_list[i].id,
ban_list[i].ip_address, ban_list[i].nick, time_str); ban_list[i].nick, time_str);
} }
free(ban_list);
return; return;
} }