31231d468053df6e78dfcf2b106f11b357ff5739
[NeonServV5.git] / cmd_neonserv_bans.c
1
2 #include "cmd_neonserv.h"
3
4 /*
5 * argv[0]    (optional) mask
6 */
7 CMD_BIND(neonserv_cmd_bans) {
8     MYSQL_RES *res;
9     MYSQL_ROW row;
10     //ban list
11     int i, with_expire = 0, cindex = 0;
12     char triggered_str[MAXLEN], expires_str[MAXLEN];
13     struct Table *table;
14     printf_mysql_query("SELECT `ban_mask`, `user_user`, `ban_triggered`, `ban_timeout`, `ban_reason` FROM `bans` LEFT JOIN `users` ON `ban_owner` = `user_id` WHERE `ban_channel` = '%d'", chan->channel_id);
15     res = mysql_use();
16     table = table_init(5, mysql_num_rows(res) + 1, 0);
17     char *content[5];
18     //add a NULL row (we add values later)
19     content[0] = NULL;
20     content[1] = NULL;
21     content[2] = NULL;
22     content[3] = NULL;
23     content[4] = NULL;
24     table_add(table, content);
25     while ((row = mysql_fetch_row(res)) != NULL) {
26         if(argc > 0 && match(argv[0], row[0])) continue;
27         content[0] = row[0];
28         content[1] = row[1];
29         content[2] = (strcmp(row[2], "0") ? timeToStr(user, (time(0) - atoi(row[2])), 2, triggered_str) : get_language_string(user, "NS_USERS_SEEN_NEVER"));
30         if(strcmp(row[3], "0")) {
31             if(!with_expire) {
32                 //we're using expire times now...
33                 for(i = 0; i < cindex; i++)
34                     table_change_field(table, i+1, 3, get_language_string(user, "NS_USERS_SEEN_NEVER"));
35                 with_expire = 1;
36             }
37             content[3] = timeToStr(user, (atoi(row[3]) - time(0)), 2, expires_str);
38         } else
39             content[3] = (with_expire ? get_language_string(user, "NS_USERS_SEEN_NEVER") : NULL);
40         content[4] = row[4];
41         cindex++;
42         table_add(table, content);
43     }
44     //now we add the table header
45     content[0] = get_language_string(user, "NS_BANS_HEADER_MASK");
46     content[1] = get_language_string(user, "NS_BANS_HEADER_SETBY");
47     content[2] = get_language_string(user, "NS_BANS_HEADER_TRIGGERED");
48     content[3] = (with_expire ? get_language_string(user, "NS_BANS_HEADER_EXPIRES") : NULL);
49     content[4] = get_language_string(user, "NS_BANS_HEADER_REASON");
50     table_change(table, 0, content);
51     char **table_lines = table_end(table);
52     for(i = 0; i < table->entrys; i++) {
53         reply(getTextBot(), user, table_lines[i]);
54     }
55     if(!cindex)
56         reply(getTextBot(), user, "NS_TABLE_NONE");
57     reply(getTextBot(), user, "NS_TABLE_COUNT", cindex);
58     table_free(table);
59 }