6 static CMD_BIND(neonserv_cmd_netinfo) {
7 reply(getTextBot(), user, "NS_NETINFO_HEADER");
10 table = table_init(2, 18, 0);
13 content[0] = get_language_string(user, "NS_NETINFO_UPTIME");
14 content[1] = timeToStr(user, (time(0) - start_time), 3, tmp);
15 table_add(table, content);
17 content[0] = get_language_string(user, "NS_NETINFO_BOTS");
18 struct ClientSocket *cclient;
19 int bot_count = 0, connected_bot_count = 0;
20 float traffic_in = 0, traffic_out = 0;
21 for(cclient = getBots(0, NULL); cclient; cclient = getBots(0, cclient)) {
23 if(cclient->flags & SOCKET_FLAG_READY)
24 connected_bot_count++;
25 traffic_in += cclient->traffic_in;
26 traffic_out += cclient->traffic_out;
28 sprintf(tmp, "%d (%d connected)", bot_count, connected_bot_count);
30 table_add(table, content);
32 content[0] = get_language_string(user, "NS_NETINFO_TRAFFIC");
33 sprintf(tmp, "in: %.2f kb out: %.2f kb", traffic_in / 1024, traffic_out / 1024);
35 table_add(table, content);
37 int channel_count = getChannelCount();
38 float channel_memory = channel_count * sizeof(struct ChanNode);
39 int channel_ban_count = getChanBanCount();
40 float channel_ban_memory = channel_ban_count * sizeof(struct BanNode);
41 int user_count = getUserCount();
42 float user_memory = user_count * sizeof(struct UserNode);
43 int chanuser_count = getChanUserCount();
44 float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
45 float total_memory = channel_memory + channel_ban_memory + user_memory + chanuser_memory;
47 content[0] = get_language_string(user, "NS_NETINFO_CACHE");
48 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
50 table_add(table, content);
52 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
53 sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, sizeof(struct ChanNode), channel_memory / 1024);
55 table_add(table, content);
57 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
58 sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, sizeof(struct BanNode), channel_ban_memory / 1024);
60 table_add(table, content);
62 content[0] = get_language_string(user, "NS_NETINFO_USER");
63 sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", user_count, user_memory / 1024, user_count, sizeof(struct UserNode), user_memory / 1024);
65 table_add(table, content);
67 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
68 sprintf(tmp, "%d %.2f kB (%d * %lu B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, sizeof(struct ChanUser), chanuser_memory / 1024);
70 table_add(table, content);
74 printf_mysql_query("SHOW TABLE STATUS");
77 float mysql_length[5];
79 mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
80 mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
81 while ((row = mysql_fetch_row(res)) != NULL) {
82 if(!stricmp(row[0], "channels")) {
83 mysql_entrys[0] = atoi(row[4]);
84 mysql_length[0] = atof(row[6]);
85 total_memory += atof(row[6]);
86 } else if(!stricmp(row[0], "bans")) {
87 mysql_entrys[1] = atoi(row[4]);
88 mysql_length[1] = atof(row[6]);
89 total_memory += atof(row[6]);
90 } else if(!stricmp(row[0], "users")) {
91 mysql_entrys[2] = atoi(row[4]);
92 mysql_length[2] = atof(row[6]);
93 total_memory += atof(row[6]);
94 } else if(!stricmp(row[0], "chanusers")) {
95 mysql_entrys[3] = atoi(row[4]);
96 mysql_length[3] = atof(row[6]);
97 total_memory += atof(row[6]);
99 mysql_length[4] += atof(row[6]);
100 total_memory += atof(row[6]);
104 content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
105 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
107 table_add(table, content);
109 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
110 sprintf(tmp, "%d %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
112 table_add(table, content);
114 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
115 sprintf(tmp, "%d %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
117 table_add(table, content);
119 content[0] = get_language_string(user, "NS_NETINFO_USER");
120 sprintf(tmp, "%d %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
122 table_add(table, content);
124 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
125 sprintf(tmp, "%d %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
127 table_add(table, content);
129 content[0] = get_language_string(user, "NS_NETINFO_OTHER");
130 sprintf(tmp, "* %.2f kB", mysql_length[4] / 1024);
132 table_add(table, content);
134 if(strcmp(revision, ""))
135 sprintf(tmp, "%s (%s)", NEONSERV_VERSION, revision);
137 strcpy(tmp, NEONSERV_VERSION);
138 content[0] = get_language_string(user, "NS_NETINFO_VERSION");
140 table_add(table, content);
142 content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
143 content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
144 table_add(table, content);
146 content[0] = get_language_string(user, "NS_NETINFO_CODE");
147 content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
148 table_add(table, content);
150 char **table_lines = table_end(table);
152 for(i = 0; i < table->entrys; i++) {
153 reply(getTextBot(), user, table_lines[i]);