+++ /dev/null
-/* cmd_global_netinfo.c - NeonServ v5.3
- * Copyright (C) 2011-2012 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"
-
-/*
-* no args
-*/
-
-CMD_BIND(global_cmd_netinfo) {
- reply(getTextBot(), user, "NS_NETINFO_HEADER");
- char tmp[MAXLEN];
- struct Table *table;
- table = table_init(2, 19, 0);
- char *content[2];
-
- content[0] = get_language_string(user, "NS_NETINFO_UPTIME");
- content[1] = timeToStr(user, (time(0) - start_time), 3, tmp);
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_BOTS");
- struct ClientSocket *cclient;
- int bot_count = 0, connected_bot_count = 0;
- float traffic_in = 0, traffic_out = 0;
- for(cclient = getBots(0, NULL); cclient; cclient = getBots(0, cclient)) {
- bot_count++;
- if(cclient->flags & SOCKET_FLAG_READY)
- connected_bot_count++;
- traffic_in += cclient->traffic_in;
- traffic_out += cclient->traffic_out;
- }
- sprintf(tmp, "%d (%d connected)", bot_count, connected_bot_count);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_TRAFFIC");
- sprintf(tmp, "in: %.2f kb out: %.2f kb", traffic_in / 1024, traffic_out / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- int channel_count = getChannelCount();
- float channel_memory = channel_count * sizeof(struct ChanNode);
- int channel_ban_count = getChanBanCount();
- float channel_ban_memory = channel_ban_count * sizeof(struct BanNode);
- int user_count = getUserCount();
- float user_memory = user_count * sizeof(struct UserNode);
- int chanuser_count = getChanUserCount();
- float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
- float total_memory = channel_memory + channel_ban_memory + user_memory + chanuser_memory;
- content[0] = get_language_string(user, "NS_NETINFO_CACHE");
- sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
- content[1] = tmp;
- table_add(table, content);
- content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
- sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, (unsigned int) sizeof(struct ChanNode), channel_memory / 1024);
- content[1] = tmp;
- table_add(table, content);
- content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
- sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, (unsigned int) sizeof(struct BanNode), channel_ban_memory / 1024);
- content[1] = tmp;
- table_add(table, content);
- content[0] = get_language_string(user, "NS_NETINFO_USER");
- sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", user_count, user_memory / 1024, user_count, (unsigned int) sizeof(struct UserNode), user_memory / 1024);
- content[1] = tmp;
- table_add(table, content);
- content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
- sprintf(tmp, "%d %.2f kB (%d * %u B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, (unsigned int) sizeof(struct ChanUser), chanuser_memory / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- MYSQL_RES *res;
- MYSQL_ROW row;
- printf_mysql_query("SHOW TABLE STATUS");
- res = mysql_use();
- int mysql_entrys[4];
- float mysql_length[5];
- total_memory = 0;
- mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
- mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
- while ((row = mysql_fetch_row(res)) != NULL) {
- if(!stricmp(row[0], "channels")) {
- mysql_entrys[0] = atoi(row[4]);
- mysql_length[0] = atof(row[6]);
- total_memory += atof(row[6]);
- } else if(!stricmp(row[0], "bans")) {
- mysql_entrys[1] = atoi(row[4]);
- mysql_length[1] = atof(row[6]);
- total_memory += atof(row[6]);
- } else if(!stricmp(row[0], "users")) {
- mysql_entrys[2] = atoi(row[4]);
- mysql_length[2] = atof(row[6]);
- total_memory += atof(row[6]);
- } else if(!stricmp(row[0], "chanusers")) {
- mysql_entrys[3] = atoi(row[4]);
- mysql_length[3] = atof(row[6]);
- total_memory += atof(row[6]);
- } else {
- mysql_length[4] += atof(row[6]);
- total_memory += atof(row[6]);
- }
- }
-
- content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
- sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
- sprintf(tmp, "%d %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
- sprintf(tmp, "%d %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_USER");
- sprintf(tmp, "%d %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
- sprintf(tmp, "%d %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_OTHER");
- sprintf(tmp, "* %.2f kB", mysql_length[4] / 1024);
- content[1] = tmp;
- table_add(table, content);
-
- #ifdef HAVE_THREADS
- content[0] = get_language_string(user, "NS_NETINFO_THREADS");
- sprintf(tmp, "%d (current thread: %i)", running_threads, getCurrentThreadID());
- content[1] = tmp;
- table_add(table, content);
- #endif
-
- if(strcmp(revision, ""))
- sprintf(tmp, "%s.%d (%s)", NEONSERV_VERSION, patchlevel, revision);
- else
- sprintf(tmp, "%s.%d", NEONSERV_VERSION, patchlevel);
- content[0] = get_language_string(user, "NS_NETINFO_VERSION");
- content[1] = tmp;
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
- content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
- table_add(table, content);
-
- content[0] = get_language_string(user, "NS_NETINFO_CODE");
- content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
- 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);
-}
-