1 /* cmd_neonserv_netinfo.c - NeonServ v5.0
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;
65 content[0] = get_language_string(user, "NS_NETINFO_CACHE");
66 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
68 table_add(table, content);
70 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
71 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);
73 table_add(table, content);
75 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
76 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);
78 table_add(table, content);
80 content[0] = get_language_string(user, "NS_NETINFO_USER");
81 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);
83 table_add(table, content);
85 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
86 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);
88 table_add(table, content);
92 printf_mysql_query("SHOW TABLE STATUS");
95 float mysql_length[5];
97 mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
98 mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
99 while ((row = mysql_fetch_row(res)) != NULL) {
100 if(!stricmp(row[0], "channels")) {
101 mysql_entrys[0] = atoi(row[4]);
102 mysql_length[0] = atof(row[6]);
103 total_memory += atof(row[6]);
104 } else if(!stricmp(row[0], "bans")) {
105 mysql_entrys[1] = atoi(row[4]);
106 mysql_length[1] = atof(row[6]);
107 total_memory += atof(row[6]);
108 } else if(!stricmp(row[0], "users")) {
109 mysql_entrys[2] = atoi(row[4]);
110 mysql_length[2] = atof(row[6]);
111 total_memory += atof(row[6]);
112 } else if(!stricmp(row[0], "chanusers")) {
113 mysql_entrys[3] = atoi(row[4]);
114 mysql_length[3] = atof(row[6]);
115 total_memory += atof(row[6]);
117 mysql_length[4] += atof(row[6]);
118 total_memory += atof(row[6]);
122 content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
123 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
125 table_add(table, content);
127 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
128 sprintf(tmp, "%d %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
130 table_add(table, content);
132 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
133 sprintf(tmp, "%d %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
135 table_add(table, content);
137 content[0] = get_language_string(user, "NS_NETINFO_USER");
138 sprintf(tmp, "%d %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
140 table_add(table, content);
142 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
143 sprintf(tmp, "%d %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
145 table_add(table, content);
147 content[0] = get_language_string(user, "NS_NETINFO_OTHER");
148 sprintf(tmp, "* %.2f kB", mysql_length[4] / 1024);
150 table_add(table, content);
152 if(strcmp(revision, ""))
153 sprintf(tmp, "%s (%s)", NEONSERV_VERSION, revision);
155 strcpy(tmp, NEONSERV_VERSION);
156 content[0] = get_language_string(user, "NS_NETINFO_VERSION");
158 table_add(table, content);
160 content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
161 content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
162 table_add(table, content);
164 content[0] = get_language_string(user, "NS_NETINFO_CODE");
165 content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
166 table_add(table, content);
168 char **table_lines = table_end(table);
170 for(i = 0; i < table->entrys; i++) {
171 reply(getTextBot(), user, table_lines[i]);