*** VERSION 5.2.0 ***
[NeonServV5.git] / src / cmd_neonserv_bans.c
1 /* cmd_neonserv_bans.c - NeonServ v5.2
2  * Copyright (C) 2011  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #include "cmd_neonserv.h"
19
20 /*
21 * argv[0]    (optional) mask
22 */
23 CMD_BIND(neonserv_cmd_bans) {
24     MYSQL_RES *res;
25     MYSQL_ROW row;
26     //ban list
27     int i, with_expire = 0, cindex = 0;
28     char triggered_str[MAXLEN], expires_str[MAXLEN];
29     struct Table *table;
30     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);
31     res = mysql_use();
32     table = table_init(5, mysql_num_rows(res) + 1, 0);
33     char *content[5];
34     //add a NULL row (we add values later)
35     content[0] = NULL;
36     content[1] = NULL;
37     content[2] = NULL;
38     content[3] = NULL;
39     content[4] = NULL;
40     table_add(table, content);
41     while ((row = mysql_fetch_row(res)) != NULL) {
42         if(argc > 0 && match(argv[0], row[0])) continue;
43         content[0] = row[0];
44         content[1] = row[1];
45         content[2] = (strcmp(row[2], "0") ? timeToStr(user, (time(0) - atoi(row[2])), 2, triggered_str) : get_language_string(user, "NS_USERS_SEEN_NEVER"));
46         if(strcmp(row[3], "0")) {
47             if(!with_expire) {
48                 //we're using expire times now...
49                 for(i = 0; i < cindex; i++)
50                     table_change_field(table, i+1, 3, get_language_string(user, "NS_USERS_SEEN_NEVER"));
51                 with_expire = 1;
52             }
53             content[3] = timeToStr(user, (atoi(row[3]) - time(0)), 2, expires_str);
54         } else
55             content[3] = (with_expire ? get_language_string(user, "NS_USERS_SEEN_NEVER") : NULL);
56         content[4] = row[4];
57         cindex++;
58         table_add(table, content);
59     }
60     //now we add the table header
61     content[0] = get_language_string(user, "NS_BANS_HEADER_MASK");
62     content[1] = get_language_string(user, "NS_BANS_HEADER_SETBY");
63     content[2] = get_language_string(user, "NS_BANS_HEADER_TRIGGERED");
64     content[3] = (with_expire ? get_language_string(user, "NS_BANS_HEADER_EXPIRES") : NULL);
65     content[4] = get_language_string(user, "NS_BANS_HEADER_REASON");
66     table_change(table, 0, content);
67     char **table_lines = table_end(table);
68     for(i = 0; i < table->entrys; i++) {
69         reply(getTextBot(), user, table_lines[i]);
70     }
71     if(!cindex)
72         reply(getTextBot(), user, "NS_TABLE_NONE");
73     reply(getTextBot(), user, "NS_TABLE_COUNT", cindex);
74     table_free(table);
75 }