+/* cmd_neonserv_info.c - NeonServ v5.0
+ * 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_neonserv.h"
+
+/*
+* no parameters
+*/
+
+CMD_BIND(neonserv_cmd_info) {
+ MYSQL_RES *res;
+ MYSQL_ROW row, row2;
+ struct Table *table;
+ printf_mysql_query("SELECT `channel_defaulttopic`, `channel_modes`, `channel_maxusers`, `channel_lastvisit`, `channel_registered`, `user_user` FROM `channels` LEFT JOIN `users` ON `channel_registrator` = `user_id` WHERE `channel_id` = '%d'", chan->channel_id);
+ res = mysql_use();
+ row = mysql_fetch_row(res);
+ table = table_init(2, 9, 0);
+ char *content[2];
+ reply(getTextBot(), user, "NS_INFO_HEADER", chan->name);
+ content[0] = get_language_string(user, "NS_INFO_DEFAULTTOPIC");
+ content[1] = row[0];
+ table_add(table, content);
+ content[0] = get_language_string(user, "NS_INFO_MODELOCK");
+ content[1] = row[1];
+ table_add(table, content);
+ content[0] = get_language_string(user, "NS_INFO_RECORD");
+ content[1] = row[2];
+ table_add(table, content);
+ printf_mysql_query("SELECT `user_user`, `chanuser_access` FROM `chanusers` LEFT JOIN `users` ON `user_id` = `chanuser_uid` WHERE `chanuser_cid` = '%d'", chan->channel_id);
+ res = mysql_use();
+ char ownerstr[MAXLEN];
+ int ownerpos = 0, usercount = 0;
+ while((row2 = mysql_fetch_row(res))) {
+ if(!strcmp(row2[1], "500"))
+ ownerpos += sprintf(ownerstr + ownerpos, (ownerpos ? ", %s" : "%s"), row2[0]);
+ usercount++;
+ }
+ content[0] = get_language_string(user, "NS_INFO_OWNER");
+ content[1] = ownerstr;
+ table_add(table, content);
+ sprintf(ownerstr, "%d", usercount);
+ content[0] = get_language_string(user, "NS_INFO_USERS");
+ content[1] = ownerstr;
+ table_add(table, content);
+ printf_mysql_query("SELECT COUNT(*) FROM `bans` WHERE `ban_channel` = '%d'", chan->channel_id);
+ res = mysql_use();
+ row2 = mysql_fetch_row(res);
+ content[0] = get_language_string(user, "NS_INFO_BANS");
+ content[1] = row2[0];
+ table_add(table, content);
+ content[0] = get_language_string(user, "NS_INFO_VISITED");
+ content[1] = timeToStr(user, time(0) - atoi(row[3]), 2, ownerstr);
+ table_add(table, content);
+ if(strcmp(row[4], "0")) {
+ content[0] = get_language_string(user, "NS_INFO_REGISTERED");
+ content[1] = timeToStr(user, time(0) - atoi(row[4]), 2, ownerstr);
+ table_add(table, content);
+ }
+ if(row[5]) {
+ content[0] = get_language_string(user, "NS_INFO_REGISTRAR");
+ content[1] = row[5];
+ table_add(table, content);
+ }
+ char **table_lines = table_end(table);
+ int i;
+ for(i = 0; i < table->entrys; i++) {
+ reply(getTextBot(), user, table_lines[i]);
+ }
+ table_free(table);
+
+}