added some database information to cmd_netinfo
authorpk910 <philipp@zoelle1.de>
Fri, 9 Sep 2011 15:08:28 +0000 (17:08 +0200)
committerpk910 <philipp@zoelle1.de>
Fri, 9 Sep 2011 15:15:04 +0000 (17:15 +0200)
ChanNode.c
ChanNode.h
bot_NeonServ.c
cmd_neonserv_netinfo.c

index 6869a954fb7e9833ae82971a4a74c9a6e05b84e6..898169b32494866d913b04942519cc456d9ad1aa 100644 (file)
@@ -196,6 +196,19 @@ int getChanUserCount() {
     return count;
 }
 
+int getChanBanCount() {
+    int i, count = 0;
+    struct ChanNode *chan;
+    struct BanNode *ban;
+    for(i = 0; i < CHANNEL_LIST_SIZE; i++) {
+        for(chan = chanList[i]; chan; chan = chan->next) {
+            for(ban = chan->bans; ban; ban = ban->next)
+                count ++;
+        }
+    }
+    return count;
+}
+
 void delChannel(struct ChanNode* chan, int freeChan) {
     int chanListIndex = get_chanlist_entry(chan->name[1]);
     if(chanListIndex == -1) return;
index 3bc007566809a9c20079f08ef752bb683aefb9e7..d08ac7eced0921b1797df355a774482dc34089bf 100644 (file)
@@ -34,6 +34,7 @@ struct ChanNode* getChanByName(const char *name);
 struct ChanNode* addChannel(const char *chan);
 int getChannelCount();
 int getChanUserCount();
+int getChanBanCount();
 void delChannel(struct ChanNode* chan, int freeChan);
 void freeChanNode(struct ChanNode* chan);
 void checkChannelVisibility(struct ChanNode* chan);
index 27c9d6c16683a3ac0978c910f7af0a5079cdb9f0..9a63e325d3d7dd600a40bcd90de91265b366faba 100644 (file)
@@ -6,6 +6,7 @@
 #include "UserNode.h"
 #include "ChanNode.h"
 #include "ChanUser.h"
+#include "BanNode.h"
 #include "ClientSocket.h"
 #include "mysqlConn.h"
 #include "lang.h"
@@ -136,9 +137,12 @@ static const struct default_language_entry msgtab[] = {
     {"NS_NETINFO_UPTIME", "Uptime:"},
     {"NS_NETINFO_TRAFFIC", "Traffic:"},
     {"NS_NETINFO_CACHE", "Cache:"},
+    {"NS_NETINFO_DATABASE", "Database:"},
     {"NS_NETINFO_CHANNEL", "  Channel:"},
+    {"NS_NETINFO_CHANNEL_BAN", "    Bans:"},
     {"NS_NETINFO_USER", "  User:"},
     {"NS_NETINFO_CHANUSER", "  Channel-User:"},
+    {"NS_NETINFO_OTHER", "  Other:"},
     {"NS_NETINFO_VERSION", "Version:"},
     {"NS_NETINFO_CODE", "Code:"},
     {"NS_NETINFO_CODE_VALUE", "%s lines c code (view it at http://git.pk910.de/?p=NeonServV5.git;a=summary)"},
index d7b1b7fe55c62aeaeb13955cb94b68fd52f288c0..5d814d8f8d9efb9fe0db6050013a91d3be351710 100644 (file)
@@ -7,7 +7,7 @@ static CMD_BIND(neonserv_cmd_netinfo) {
     reply(getTextBot(), user, "NS_NETINFO_HEADER");
     char tmp[MAXLEN];
     struct Table *table;
-    table = table_init(2, 10, 0);
+    table = table_init(2, 18, 0);
     char *content[2];
     
     content[0] = get_language_string(user, "NS_NETINFO_UPTIME");
@@ -36,11 +36,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 +54,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 +69,69 @@ static CMD_BIND(neonserv_cmd_netinfo) {
     content[1] = tmp;
     table_add(table, content);
     
+    MYSQL_RES *res;
+    MYSQL_ROW row;
+    check_mysql();
+    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