finished cmd_trim (trim bans)
authorpk910 <philipp@zoelle1.de>
Wed, 5 Oct 2011 19:47:49 +0000 (21:47 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 5 Oct 2011 19:53:33 +0000 (21:53 +0200)
src/bot_NeonServ.c
src/cmd_neonserv_netinfo.c
src/cmd_neonserv_trim.c

index 23514e8d67033ceb8bdf73f1720afc661262b458..4df2884cc2759236321b9cac5f6cd44c16bbb1d1 100644 (file)
@@ -105,6 +105,7 @@ static const struct default_language_entry msgtab[] = {
     {"NS_MDELUSER_DONE", "Deleted $b%d$b account(s) matching $b%s$b with access from $b%d$b to $b%d$b from the %s user list."}, /* {ARGS: 10, "Test*", 1, 200, "#TestChan"} */
     {"NS_TRIM_DURATION_TOO_SHORT", "You must include a minimum inactivity duration of at least %d seconds to trim."},
     {"NS_TRIM_DONE", "Trimmed $b%d users$b with access from %d to %d from the %s user list who were inactive for at least %s."}, /* {ARGS: 10, 1, 100, "#TestChan", "10 days"} */
+    {"NS_TRIM_BAN_DONE", "Trimmed $b%d bans$b from the %s ban list who were banned for at least %s."},
     {"NS_GIVEOWNER_SELF", "You cannot give ownership to your own account."},
     {"NS_GIVEOWNER_TIMEOUT", "You must wait %s before you can give ownership of $b%s$b to someone else."}, /* {ARGS: "5 hours", "#TestChan"} */
     {"NS_GIVEOWNER_CONFIRM", "To really give ownership to $b%1$s$b, you must use 'giveownership *%1$s %2$s'."}, /* {ARGS: "TestUser", "abc123"} */
@@ -313,8 +314,7 @@ static const struct default_language_entry msgtab[] = {
     {NULL, NULL}
 };
 
-/* TODO: 
-trim bans
+/* TODO:
 cmd_neonserv_open.c
 set modelock
 cmd_neonserv_modcmd.c
index 7f60d643a7f8e0fd29594d3189f81d9d1cdaf3dd..e4a34bed5a0ecc81cee327deb6108f5f5b50c2d0 100644 (file)
@@ -61,27 +61,22 @@ CMD_BIND(neonserv_cmd_netinfo) {
     int chanuser_count = getChanUserCount();
     float chanuser_memory = chanuser_count * sizeof(struct ChanUser);
     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);
     content[1] = tmp;
     table_add(table, content);
-    
     content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
     sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, (unsigned int) sizeof(struct ChanNode), channel_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
-    
     content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
     sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, (unsigned int) 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 * %u B = %.2f kB)", user_count, user_memory / 1024, user_count, (unsigned int) sizeof(struct UserNode), user_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
-    
     content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
     sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, (unsigned int) sizeof(struct ChanUser), chanuser_memory / 1024);
     content[1] = tmp;
index eb58093c7146cb1f08e2fed81b7d46d12e864345..8cea78c6e5eb6fef5ec77d97bcfe57e1b5bf009c 100644 (file)
@@ -43,6 +43,11 @@ CMD_BIND(neonserv_cmd_trim) {
         }
     }
     int min_access, max_access;
+    int duration = strToTime(user, argv[1]);
+    if(duration < 30) {
+        reply(getTextBot(), user, "NS_TRIM_DURATION_TOO_SHORT", 30);
+        return;
+    }
     if(!stricmp(argv[0], "users")) {
         min_access = 1;
         max_access = getChannelAccess(user, chan, 0) - 1;
@@ -55,7 +60,26 @@ CMD_BIND(neonserv_cmd_trim) {
                 return;
             }
         }
-        //TODO: TRIM BANS
+        MYSQL_RES *res;
+        MYSQL_ROW row;
+        char nameBuf[20];
+        printf_mysql_query("SELECT `ban_mask`, `ban_id`, `ban_timeout` FROM `bans` WHERE `ban_channel` = '%d' AND `ban_triggered` < %d", chan->channel_id, (int) (time(0) - duration));
+        res = mysql_use();
+        int bancount = mysql_num_rows(res);
+        struct ModeBuffer *modenode = initModeBuffer(client, chan);
+        while ((row = mysql_fetch_row(res)) != NULL) {
+            if(strcmp(row[2], "0")) {
+                sprintf(nameBuf, "ban_%s", row[1]);
+                timeq_del_name(nameBuf);
+            }
+            printf_mysql_query("DELETE FROM `bans` WHERE `ban_id` = '%s'", row[1]);
+            modeBufferUnban(modenode, row[0]);
+        }
+        freeModeBuffer(modenode);
+        char timeBuf[MAXLEN];
+        reply(getTextBot(), user, "NS_TRIM_BAN_DONE", bancount, chan->name, timeToStr(user, duration, 3, timeBuf));
+        if(bancount)
+            logEvent(event);
         return;
     } else {
         char *seperator = strstr(argv[0], "-");
@@ -81,12 +105,6 @@ CMD_BIND(neonserv_cmd_trim) {
             }
         }
     }
-    //parse duration...
-    int duration = strToTime(user, argv[1]);
-    if(duration < 30) {
-        reply(getTextBot(), user, "NS_TRIM_DURATION_TOO_SHORT", 30);
-        return;
-    }
     struct neonserv_cmd_trim_cache *cache = malloc(sizeof(*cache));
     if (!cache) {
         perror("malloc() failed");