+/* cmd_global_bots.c - NeonServ v5.2
+ * Copyright (C) 2011 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cmd_global.h"
+
+/*
+* argv[0] (optional) class name
+*/
+
+CMD_BIND(global_cmd_bots) {
+ struct Table *table;
+ MYSQL_RES *res, *res2;
+ MYSQL_ROW row, row2;
+ printf_mysql_query("SELECT `active`, `nick`, `server`, `port`, `pass`, `botclass`, `textbot`, `queue`, `defaulttrigger`, `max_channels`, `register_priority`, `id` FROM `bots`");
+ res = mysql_use();
+ table = table_init(6, mysql_num_rows(res) + 1, 0);
+ char *content[5];
+ content[0] = get_language_string(user, "NS_BOTS_NICK");
+ content[1] = get_language_string(user, "NS_BOTS_SERVER");
+ content[2] = get_language_string(user, "NS_BOTS_CLASS");
+ content[3] = get_language_string(user, "NS_BOTS_FLAGS");
+ content[4] = get_language_string(user, "NS_BOTS_CHANNELS");
+ content[5] = get_language_string(user, "NS_BOTS_TRIGGER");
+ table_add(table, content);
+ char botnick[NICKLEN + 3];
+ char botserver[MAXLEN];
+ char botflags[10];
+ int flagspos;
+ char botchans[20];
+ while ((row = mysql_fetch_row(res)) != NULL) {
+ sprintf(botnick, (strcmp(row[0], "0") ? "%s" : "\00315%s\003"), row[1]);
+ contents[0] = botnick;
+ sprintf(botserver, (strcmp(row[4], "") ? "%s:%s:*" : "%s:%s"), row[2], row[3]);
+ contents[1] = botserver;
+ contents[2] = resolve_botid(atoi(row[5]));
+ flagspos = 0;
+ if(!strcmp(row[6], "1"))
+ botflags[flagspos++] = 't';
+ if(!strcmp(row[7], "1"))
+ botflags[flagspos++] = 'q';
+ botflags[flagspos] = '\0';
+ contents[3] = botflags;
+ printf_mysql_query("SELECT COUNT(*) FROM `bot_channels` WHERE `botid` = '%s'", row[11]);
+ res2 = mysql_use();
+ row2 = mysql_fetch_row(res2);
+ sprintf(botchans, "%s/%s", row2[0], row[9]);
+ contents[4] = botchans;
+ contents[5] = row[8];
+ }
+ char **table_lines = table_end(table);
+ for(i = 0; i < table->entrys; i++) {
+ reply(getTextBot(), user, table_lines[i]);
+ }
+}
\ No newline at end of file