changed Makefile; build all commands as an own file
[NeonServV5.git] / cmd_neonserv_netinfo.c
index a8aece74f697091490a63391fedb7f673486d75b..c8fd1b643d87ecaa4fea62678e2e0ca9912c8765 100644 (file)
@@ -1,13 +1,15 @@
 
+#include "cmd_neonserv.h"
+
 /*
 * no args
 */
 
-static CMD_BIND(neonserv_cmd_netinfo) {
+CMD_BIND(neonserv_cmd_netinfo) {
     reply(getTextBot(), user, "NS_NETINFO_HEADER");
     char tmp[MAXLEN];
     struct Table *table;
-    table = table_init(2, 7, 0);
+    table = table_init(2, 18, 0);
     char *content[2];
     
     content[0] = get_language_string(user, "NS_NETINFO_UPTIME");
@@ -36,11 +38,13 @@ static CMD_BIND(neonserv_cmd_netinfo) {
     
     int channel_count = getChannelCount();
     float channel_memory = channel_count * sizeof(struct ChanNode);
+    int channel_ban_count = getChanBanCount();
+    float channel_ban_memory = channel_ban_count * sizeof(struct BanNode);
     int user_count = getUserCount();
     float user_memory = user_count * sizeof(struct UserNode);
     int chanuser_count = getChanUserCount();
     float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
-    float total_memory = channel_memory + user_memory + chanuser_memory;
+    float total_memory = channel_memory + channel_ban_memory + user_memory + chanuser_memory;
     
     content[0] = get_language_string(user, "NS_NETINFO_CACHE");
     sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
@@ -52,6 +56,11 @@ static CMD_BIND(neonserv_cmd_netinfo) {
     content[1] = tmp;
     table_add(table, content);
     
+    content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
+    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);
+    content[1] = tmp;
+    table_add(table, content);
+    
     content[0] = get_language_string(user, "NS_NETINFO_USER");
     sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", user_count, user_memory / 1024, user_count, sizeof(struct UserNode), user_memory / 1024);
     content[1] = tmp;
@@ -62,6 +71,84 @@ static CMD_BIND(neonserv_cmd_netinfo) {
     content[1] = tmp;
     table_add(table, content);
     
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    printf_mysql_query("SHOW TABLE STATUS");
+    res = mysql_use();
+    int mysql_entrys[4];
+    float mysql_length[5];
+    total_memory = 0;
+    mysql_entrys[0] = 0; mysql_entrys[1] = 0; mysql_entrys[2] = 0; mysql_entrys[3] = 0;
+    mysql_length[0] = 0; mysql_length[1] = 0; mysql_length[2] = 0; mysql_length[3] = 0; mysql_length[4] = 0;
+    while ((row = mysql_fetch_row(res)) != NULL) {
+        if(!stricmp(row[0], "channels")) {
+            mysql_entrys[0] = atoi(row[4]);
+            mysql_length[0] = atof(row[6]);
+            total_memory += atof(row[6]);
+        } else if(!stricmp(row[0], "bans")) {
+            mysql_entrys[1] = atoi(row[4]);
+            mysql_length[1] = atof(row[6]);
+            total_memory += atof(row[6]);
+        } else if(!stricmp(row[0], "users")) {
+            mysql_entrys[2] = atoi(row[4]);
+            mysql_length[2] = atof(row[6]);
+            total_memory += atof(row[6]);
+        } else if(!stricmp(row[0], "chanusers")) {
+            mysql_entrys[3] = atoi(row[4]);
+            mysql_length[3] = atof(row[6]);
+            total_memory += atof(row[6]);
+        } else {
+            mysql_length[4] += atof(row[6]);
+            total_memory += atof(row[6]);
+        }
+    }
+    
+    content[0] = get_language_string(user, "NS_NETINFO_DATABASE");
+    sprintf(tmp, "%.2f kB (%.2f MB)", total_memory / 1024, total_memory / 1024 / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
+    sprintf(tmp, "%d    %.2f kB", mysql_entrys[0], mysql_length[0] / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
+    sprintf(tmp, "%d    %.2f kB", mysql_entrys[1], mysql_length[1] / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_USER");
+    sprintf(tmp, "%d    %.2f kB", mysql_entrys[2], mysql_length[2] / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
+    sprintf(tmp, "%d    %.2f kB", mysql_entrys[3], mysql_length[3] / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_OTHER");
+    sprintf(tmp, "*     %.2f kB", mysql_length[4] / 1024);
+    content[1] = tmp;
+    table_add(table, content);
+    
+    if(strcmp(revision, ""))
+        sprintf(tmp, "%s  (%s)", NEONSERV_VERSION, revision);
+    else 
+        strcpy(tmp, NEONSERV_VERSION);
+    content[0] = get_language_string(user, "NS_NETINFO_VERSION");
+    content[1] = tmp;
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_COMPILER");
+    content[1] = build_language_string(user, tmp, "NS_NETINFO_COMPILER_VALUE", COMPILER, creation);
+    table_add(table, content);
+    
+    content[0] = get_language_string(user, "NS_NETINFO_CODE");
+    content[1] = build_language_string(user, tmp, "NS_NETINFO_CODE_VALUE", codelines);
+    table_add(table, content);
+    
     char **table_lines = table_end(table);
     int i;
     for(i = 0; i < table->entrys; i++) {