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);
75 printf_mysql_query("SHOW TABLE STATUS");
78 float mysql_length[5];
80 mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
81 mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
82 while ((row = mysql_fetch_row(res)) != NULL) {
83 if(!stricmp(row[0], "channels")) {
84 mysql_entrys[0] = atoi(row[4]);
85 mysql_length[0] = atof(row[6]);
86 total_memory += atof(row[6]);
87 } else if(!stricmp(row[0], "bans")) {
88 mysql_entrys[1] = atoi(row[4]);
89 mysql_length[1] = atof(row[6]);
90 total_memory += atof(row[6]);
91 } else if(!stricmp(row[0], "users")) {
92 mysql_entrys[2] = atoi(row[4]);
93 mysql_length[2] = atof(row[6]);
94 total_memory += atof(row[6]);
95 } else if(!stricmp(row[0], "chanusers")) {
96 mysql_entrys[3] = atoi(row[4]);
97 mysql_length[3] = atof(row[6]);
98 total_memory += atof(row[6]);
100 mysql_length[4] += atof(row[6]);
101 total_memory += atof(row[6]);
105 content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
106 sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
108 table_add(table, content);
110 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
111 sprintf(tmp, "%d %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
113 table_add(table, content);
115 content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
116 sprintf(tmp, "%d %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
118 table_add(table, content);
120 content[0] = get_language_string(user, "NS_NETINFO_USER");
121 sprintf(tmp, "%d %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
123 table_add(table, content);
125 content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
126 sprintf(tmp, "%d %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
128 table_add(table, content);
130 content[0] = get_language_string(user, "NS_NETINFO_OTHER");
131 sprintf(tmp, "* %.2f kB", mysql_length[4] / 1024);
133 table_add(table, content);
135 if(strcmp(revision, ""))
136 sprintf(tmp, "%s (%s)", NEONSERV_VERSION, revision);
138 strcpy(tmp, NEONSERV_VERSION);
139 content[0] = get_language_string(user, "NS_NETINFO_VERSION");
141 table_add(table, content);
143 content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
144 content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
145 table_add(table, content);
147 content[0] = get_language_string(user, "NS_NETINFO_CODE");
148 content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
149 table_add(table, content);
151 char **table_lines = table_end(table);
153 for(i = 0; i < table->entrys; i++) {
154 reply(getTextBot(), user, table_lines[i]);