a8aece74f697091490a63391fedb7f673486d75b
[NeonServV5.git] / cmd_neonserv_netinfo.c
1
2 /*
3 * no args
4 */
5
6 static CMD_BIND(neonserv_cmd_netinfo) {
7     reply(getTextBot(), user, "NS_NETINFO_HEADER");
8     char tmp[MAXLEN];
9     struct Table *table;
10     table = table_init(2, 7, 0);
11     char *content[2];
12     
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);
16     
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)) {
22         bot_count++;
23         if(cclient->flags & SOCKET_FLAG_READY)
24             connected_bot_count++;
25         traffic_in += cclient->traffic_in;
26         traffic_out += cclient->traffic_out;
27     }
28     sprintf(tmp, "%d (%d connected)", bot_count, connected_bot_count);
29     content[1] = tmp;
30     table_add(table, content);
31     
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);
34     content[1] = tmp;
35     table_add(table, content);
36     
37     int channel_count = getChannelCount();
38     float channel_memory = channel_count * sizeof(struct ChanNode);
39     int user_count = getUserCount();
40     float user_memory = user_count * sizeof(struct UserNode);
41     int chanuser_count = getChanUserCount();
42     float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
43     float total_memory = channel_memory + user_memory + chanuser_memory;
44     
45     content[0] = get_language_string(user, "NS_NETINFO_CACHE");
46     sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
47     content[1] = tmp;
48     table_add(table, content);
49     
50     content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
51     sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, sizeof(struct ChanNode), channel_memory / 1024);
52     content[1] = tmp;
53     table_add(table, content);
54     
55     content[0] = get_language_string(user, "NS_NETINFO_USER");
56     sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", user_count, user_memory / 1024, user_count, sizeof(struct UserNode), user_memory / 1024);
57     content[1] = tmp;
58     table_add(table, content);
59     
60     content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
61     sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, sizeof(struct ChanUser), chanuser_memory / 1024);
62     content[1] = tmp;
63     table_add(table, content);
64     
65     char **table_lines = table_end(table);
66     int i;
67     for(i = 0; i < table->entrys; i++) {
68         reply(getTextBot(), user, table_lines[i]);
69     }
70     table_free(table);
71 }
72