1 /* cmd_neonserv_netinfo.c - NeonServ v5.1
2 * Copyright (C) 2011 Philipp Kreil (pk910)
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.
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.
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/>.
18 #include "cmd_neonserv.h"
24 CMD_BIND(neonserv_cmd_netinfo) {
25 reply(getTextBot(), user, "NS_NETINFO_HEADER");
28 table = table_init(2, 18, 0);
31 content[0] = get_language_string(user, "NS_NETINFO_UPTIME");
32 content[1] = timeToStr(user, (time(0) - start_time), 3, tmp);
33 table_add(table, content);
35 content[0] = get_language_string(user, "NS_NETINFO_BOTS");
36 struct ClientSocket *cclient;
37 int bot_count = 0, connected_bot_count = 0;
38 float traffic_in = 0, traffic_out = 0;
39 for(cclient = getBots(0, NULL); cclient; cclient = getBots(0, cclient)) {
41 if(cclient->flags & SOCKET_FLAG_READY)
42 connected_bot_count++;
43 traffic_in += cclient->traffic_in;
44 traffic_out += cclient->traffic_out;
46 sprintf(tmp, "%d (%d connected)", bot_count, connected_bot_count);
48 table_add(table, content);
50 content[0] = get_language_string(user, "NS_NETINFO_TRAFFIC");
51 sprintf(tmp, "in: %.2f kb out: %.2f kb", traffic_in / 1024, traffic_out / 1024);
53 table_add(table, content);
55 int channel_count = getChannelCount();
56 float channel_memory = channel_count * sizeof(struct ChanNode);
57 int channel_ban_count = getChanBanCount();
58 float channel_ban_memory = channel_ban_count * sizeof(struct BanNode);
59 int user_count = getUserCount();
60 float user_memory = user_count * sizeof(struct UserNode);
61 int chanuser_count = getChanUserCount();
62 float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
63 float total_memory = channel_memory + channel_ban_memory + user_memory + chanuser_memory;
64 content[0] = get_language_string(user, "NS_NETINFO_CACHE");
65 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
67 table_add(table, content);
68 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
69 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);
71 table_add(table, content);
72 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
73 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);
75 table_add(table, content);
76 content[0] = get_language_string(user, "NS_NETINFO_USER");
77 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);
79 table_add(table, content);
80 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
81 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);
83 table_add(table, content);
87 printf_mysql_query("SHOW TABLE STATUS");
90 float mysql_length[5];
92 mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
93 mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
94 while ((row = mysql_fetch_row(res)) != NULL) {
95 if(!stricmp(row[0], "channels")) {
96 mysql_entrys[0] = atoi(row[4]);
97 mysql_length[0] = atof(row[6]);
98 total_memory += atof(row[6]);
99 } else if(!stricmp(row[0], "bans")) {
100 mysql_entrys[1] = atoi(row[4]);
101 mysql_length[1] = atof(row[6]);
102 total_memory += atof(row[6]);
103 } else if(!stricmp(row[0], "users")) {
104 mysql_entrys[2] = atoi(row[4]);
105 mysql_length[2] = atof(row[6]);
106 total_memory += atof(row[6]);
107 } else if(!stricmp(row[0], "chanusers")) {
108 mysql_entrys[3] = atoi(row[4]);
109 mysql_length[3] = atof(row[6]);
110 total_memory += atof(row[6]);
112 mysql_length[4] += atof(row[6]);
113 total_memory += atof(row[6]);
117 content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
118 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
120 table_add(table, content);
122 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
123 sprintf(tmp, "%d %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
125 table_add(table, content);
127 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
128 sprintf(tmp, "%d %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
130 table_add(table, content);
132 content[0] = get_language_string(user, "NS_NETINFO_USER");
133 sprintf(tmp, "%d %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
135 table_add(table, content);
137 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
138 sprintf(tmp, "%d %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
140 table_add(table, content);
142 content[0] = get_language_string(user, "NS_NETINFO_OTHER");
143 sprintf(tmp, "* %.2f kB", mysql_length[4] / 1024);
145 table_add(table, content);
147 if(strcmp(revision, ""))
148 sprintf(tmp, "%s.%d (%s)", NEONSERV_VERSION, patchlevel, revision);
150 sprintf(tmp, "%s.%d", NEONSERV_VERSION, patchlevel);
151 content[0] = get_language_string(user, "NS_NETINFO_VERSION");
153 table_add(table, content);
155 content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
156 content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
157 table_add(table, content);
159 content[0] = get_language_string(user, "NS_NETINFO_CODE");
160 content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
161 table_add(table, content);
163 char **table_lines = table_end(table);
165 for(i = 0; i < table->entrys; i++) {
166 reply(getTextBot(), user, table_lines[i]);