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