Another year is about to end... So we have to update these damn copyright information :P
[NeonServV5.git] / src / cmd_global_bots.c
1 /* cmd_global_bots.c - NeonServ v5.3
2  * Copyright (C) 2011-2012  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_global.h"
19
20 /*
21 * argv[0]    (optional) class name
22 */
23
24 CMD_BIND(global_cmd_bots) {
25     struct Table *table;
26     MYSQL_RES *res, *res2;
27     MYSQL_ROW row, row2;
28     printf_mysql_query("SELECT `active`, `nick`, `server`, `port`, `pass`, `botclass`, `textbot`, `queue`, `defaulttrigger`, `max_channels`, `register_priority`, `id` FROM `bots`");
29     res = mysql_use();
30     table = table_init(7, mysql_num_rows(res) + 1, 0);
31     char *content[7];
32     content[0] = get_language_string(user, "NS_BOTS_ID");
33     content[1] = get_language_string(user, "NS_BOTS_NICK");
34     content[2] = get_language_string(user, "NS_BOTS_SERVER");
35     content[3] = get_language_string(user, "NS_BOTS_CLASS");
36     content[4] = get_language_string(user, "NS_BOTS_FLAGS");
37     content[5] = get_language_string(user, "NS_BOTS_CHANNELS");
38     content[6] = get_language_string(user, "NS_BOTS_TRIGGER");
39     table_add(table, content);
40     char botnick[NICKLEN + 3];
41     char botserver[MAXLEN];
42     char botflags[10];
43     int flagspos;
44     char botchans[20];
45     while ((row = mysql_fetch_row(res)) != NULL) {
46         content[0] = row[11];
47         sprintf(botnick, (strcmp(row[0], "0") ? "%s" : "!%s"), row[1]);
48         content[1] = botnick;
49         sprintf(botserver, (strcmp(row[4], "") ? "%s:%s:*" : "%s:%s"), row[2], row[3]);
50         content[2] = botserver;
51         content[3] = (char *) resolve_botid(atoi(row[5]));
52         flagspos = 0;
53         if(!strcmp(row[6], "1"))
54             botflags[flagspos++] = 't';
55         if(!strcmp(row[7], "1"))
56             botflags[flagspos++] = 'q';
57         botflags[flagspos] = '\0';
58         content[4] = botflags;
59         printf_mysql_query("SELECT COUNT(*) FROM `bot_channels` WHERE `botid` = '%s'", row[11]);
60         res2 = mysql_use();
61         row2 = mysql_fetch_row(res2);
62         sprintf(botchans, "%s/%s", row2[0], row[9]);
63         content[5] = botchans;
64         content[6] = row[8];
65         table_add(table, content);
66     }
67     char **table_lines = table_end(table);
68     int i;
69     for(i = 0; i < table->entrys; i++) {
70         reply(getTextBot(), user, table_lines[i]);
71     }
72 }