From: pk910 Date: Wed, 5 Oct 2011 19:47:49 +0000 (+0200) Subject: finished cmd_trim (trim bans) X-Git-Tag: v5.3~306 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=c18a539e8070dca20133ed549eaac38f7eb500eb finished cmd_trim (trim bans) --- diff --git a/src/bot_NeonServ.c b/src/bot_NeonServ.c index 23514e8..4df2884 100644 --- a/src/bot_NeonServ.c +++ b/src/bot_NeonServ.c @@ -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 diff --git a/src/cmd_neonserv_netinfo.c b/src/cmd_neonserv_netinfo.c index 7f60d64..e4a34be 100644 --- a/src/cmd_neonserv_netinfo.c +++ b/src/cmd_neonserv_netinfo.c @@ -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; diff --git a/src/cmd_neonserv_trim.c b/src/cmd_neonserv_trim.c index eb58093..8cea78c 100644 --- a/src/cmd_neonserv_trim.c +++ b/src/cmd_neonserv_trim.c @@ -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");