X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/5aa400d2612f104275d7f6b466a71f3139b4375b..ef5e03051fd86d66844d61f3fcc1c7a82957826a:/src/opserv.c diff --git a/src/opserv.c b/src/opserv.c index dce0fd6..9f1539e 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -5,7 +5,7 @@ * * x3 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, @@ -18,6 +18,7 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include "config.h" #include "chanserv.h" #include "conf.h" #include "common.h" @@ -44,7 +45,6 @@ #include #endif - #define OPSERV_CONF_NAME "services/opserv" #define KEY_ALERT_CHANNEL "alert_channel" @@ -76,6 +76,8 @@ #define KEY_WARN "chanwarn" #define KEY_MAX "max" #define KEY_TIME "time" +#define KEY_LAST "last" +#define KEY_EXPIRE "expire" #define KEY_MAX_CLIENTS "max_clients" #define KEY_LIMIT "limit" #define KEY_EXPIRES "expires" @@ -164,6 +166,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_NO_DEBUG_CHANNEL", "No debug channel has been configured." }, { "OSMSG_INVITE_DONE", "Invited $b%s$b to $b%s$b." }, { "OSMSG_ALREADY_THERE", "You are already in $b%s$b." }, + { "OSMSG_USER_ALREADY_THERE", "%s is already in $b%s$b." }, { "OSMSG_NOT_THERE", "You not in $b%s$b." }, { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, { "OSMSG_MARK_SET", "Set the MARK." }, @@ -179,6 +182,8 @@ static const struct message_entry msgtab[] = { { "OSMSG_OPALL_DONE", "Opped everyone on $b%s$b." }, { "OSMSG_HOP_DONE", "Halfopped the requested lusers." }, { "OSMSG_HOPALL_DONE", "Halfopped everyone on $b%s$b." }, + { "OMSG_BAD_SVSNICK", "$b%s$b is an invalid nickname." }, + { "OSMSG_WHOIS_IDENT", "%s (%s@%s) from %d.%d.%d.%d" }, { "OSMSG_WHOIS_NICK", "Nick : %s" }, { "OSMSG_WHOIS_HOST", "Host : %s@%s" }, @@ -206,6 +211,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_WHOIS_CHANNELS", "Channels : %s" }, { "OSMSG_WHOIS_HIDECHANS", "Channel list omitted for your sanity." }, { "OSMSG_WHOIS_VERSION", "Version : %s" }, + { "OSMSG_WHOIS_MARK", "Mark : %s" }, { "OSMSG_WHOIS_NO_NOTICE", "No_notices : %s" }, { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." }, { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." }, @@ -311,8 +317,10 @@ static const struct message_entry msgtab[] = { { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts matching '$b%s$b'$b" }, { "OSMSG_ALERTS_BAR", "----------------------------------------------" }, { "OSMSG_ALERTS_HEADER", "Name Action (by Oper)" }, - { "OSMSG_ALERTS_DESC", " Criteria: %s" }, + { "OSMSG_ALERTS_DESC", " $uCriteria$u: %s" }, + { "OSMSG_ALERTS_LAST", " $uTriggered$u: %s" }, { "OSMSG_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, + { "OSMSG_ALERT_EXPIRE", " $uExpires:$u: %s" }, { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, /* routing messages */ { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" }, @@ -456,6 +464,7 @@ static dict_t opserv_waiting_connections; /* data is struct waitingConnection */ static dict_t opserv_hostinfo_dict; /* data is struct opserv_hostinfo* */ static dict_t opserv_user_alerts; /* data is struct opserv_user_alert* */ static dict_t opserv_nick_based_alerts; /* data is struct opserv_user_alert* */ +static dict_t opserv_account_based_alerts; /* data is struct opserv_user_alert* */ static dict_t opserv_channel_alerts; /* data is struct opserv_user_alert* */ static struct module *opserv_module; static struct log_type *OS_LOG; @@ -524,7 +533,7 @@ opserv_free_waiting_connection(void *data) typedef struct opservDiscrim { struct chanNode *channel; - char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget, *mark; + char *mask_nick, *mask_ident, *mask_host, *mask_info, *mask_version, *server, *reason, *accountmask, *chantarget, *mark, *mask_mark, *modes; irc_in_addr_t ip_mask; unsigned long limit; time_t min_ts, max_ts; @@ -553,6 +562,7 @@ static discrim_t opserv_discrim_create(struct userNode *user, struct userNode *b static unsigned int opserv_discrim_search(discrim_t discrim, discrim_search_func dsf, void *data); static int gag_helper_func(struct userNode *match, void *extra); static int ungag_helper_func(struct userNode *match, void *extra); +static void alert_expire(void* name); typedef enum { REACT_NOTICE, @@ -571,6 +581,8 @@ struct opserv_user_alert { char *text_discrim, *split_discrim; discrim_t discrim; opserv_alert_reaction reaction; + int last; + time_t expire; }; /* funny type to make it acceptible to dict_set_free_data, far below */ @@ -1398,8 +1410,10 @@ opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG return; /* channel is invite only */ } - if (channel->members.used >= channel->limit) { - return; /* channel is invite on */ + if (channel->limit > 0) { + if (channel->members.used >= channel->limit) { + return; /* channel is invite on */ + } } if (*channel->key) { @@ -1619,7 +1633,7 @@ static MODCMD_FUNC(cmd_svsjoin) channel = AddChannel(argv[2], now, NULL, NULL, NULL); } if (GetUserMode(channel, target)) { - reply("OSMSG_ALREADY_THERE", channel->name); + reply("OSMSG_USER_ALREADY_THERE", target->nick, channel->name); return 0; } irc_svsjoin(opserv, target, channel); @@ -1627,6 +1641,23 @@ static MODCMD_FUNC(cmd_svsjoin) return 1; } +static MODCMD_FUNC(cmd_svsnick) +{ + struct userNode *target; + + target = GetUserH(argv[1]); + if (!target) { + reply("MSG_NICK_UNKNOWN", argv[1]); + return 0; + } + if(!is_valid_nick(argv[2])) { + reply("OMSG_BAD_SVSNICK", argv[2]); + return 0; + } + irc_svsnick(opserv, target, argv[2]); + return 1; +} + static MODCMD_FUNC(cmd_join) { struct userNode *bot = cmd->parent->bot; @@ -1796,28 +1827,29 @@ static MODCMD_FUNC(cmd_kickbanall) static MODCMD_FUNC(cmd_svspart) { struct userNode *target; + struct chanNode *target_channel; if(!IsChannelName(argv[2])) { reply("MSG_NOT_CHANNEL_NAME"); return 0; } + if(!(target_channel = GetChannel(argv[2]))) + { + reply("MSG_INVALID_CHANNEL"); + return 0; + } target = GetUserH(argv[1]); if (!target) { reply("MSG_NICK_UNKNOWN", argv[1]); return 0; } - if (!(channel = GetChannel(argv[2]))) { - reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); - return 0; - } - - if (!GetUserMode(channel, target)) { - reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, channel->name); + if (!GetUserMode(target_channel, target)) { + reply("OSMSG_NOT_ON_CHANNEL", cmd->parent->bot->nick, target_channel->name); return 0; } - irc_svspart(opserv, target, channel); + irc_svspart(opserv, target, target_channel); reply("OSMSG_SVSPART_SENT"); return 1; } @@ -2035,6 +2067,9 @@ static MODCMD_FUNC(cmd_whois) if(target->version_reply) { reply("OSMSG_WHOIS_VERSION", target->version_reply); } + if(target->mark) { + reply("OSMSG_WHOIS_MARK", target->mark); + } reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO"); if (target->modes) { @@ -2054,6 +2089,10 @@ static MODCMD_FUNC(cmd_whois) if (IsDeaf(target)) buffer[bpos++] = 'd'; if (target->handle_info) buffer[bpos++] = 'r'; if (IsHiddenHost(target)) buffer[bpos++] = 'x'; + if (IsBotM(target)) buffer[bpos++] = 'B'; + if (IsHideChans(target)) buffer[bpos++] = 'n'; + if (IsHideIdle(target)) buffer[bpos++] = 'I'; + if (IsXtraOp(target)) buffer[bpos++] = 'X'; if (IsGagged(target)) buffer_cat(" (gagged)"); if (IsRegistering(target)) buffer_cat(" (registered account)"); buffer[bpos] = 0; @@ -2392,6 +2431,8 @@ static MODCMD_FUNC(cmd_stats_alerts) { dict_iterator_t it; struct opserv_user_alert *alert; const char *reaction; + char t_buffer[INTERVALLEN]; + char expire_buffer[30]; char *m = NULL; if(argc > 1) @@ -2402,7 +2443,7 @@ static MODCMD_FUNC(cmd_stats_alerts) { reply("OSMSG_ALERTS_BAR"); for (it = dict_first(opserv_user_alerts); it; it = iter_next(it)) { alert = iter_data(it); - if(m && (!match_ircglob(alert->text_discrim, m) && strcasecmp(alert->owner, m)) ) + if(m && (!match_ircglob(alert->text_discrim, m) && strcasecmp(alert->owner, m) && strcasecmp(iter_key(it), m))) continue; /* not a match to requested filter */ switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; @@ -2418,7 +2459,15 @@ static MODCMD_FUNC(cmd_stats_alerts) { default: reaction = ""; break; } reply("OSMSG_ALERT_IS", iter_key(it), reaction, alert->owner); + if (alert->expire) { + strftime(expire_buffer, sizeof(expire_buffer), "%Y-%m-%d %H:%M:%S %z", localtime(&alert->expire)); + reply("OSMSG_ALERT_EXPIRE", expire_buffer); + } reply("OSMSG_ALERTS_DESC", alert->text_discrim); + if (alert->last > 0) + reply("OSMSG_ALERTS_LAST", intervalString(t_buffer, now - alert->last, user->handle_info)); + else + reply("OSMSG_ALERTS_LAST", "Never"); } reply("OSMSG_ALERT_END"); return 1; @@ -2664,7 +2713,7 @@ opserv_new_user_check(struct userNode *user) } if (checkDefCon(DEFCON_NO_NEW_CLIENTS)) { - irc_kill(opserv, user, DefConGlineReason); + DelUser(user, opserv, 1, DefConGlineReason); return 0; } @@ -2804,7 +2853,7 @@ opserv_notice_handler(struct userNode *user, struct userNode *bot, char *text, U if(text[0] == '\001') { text++; cmd = mysep(&text, " "); - if(!irccasecmp(cmd, "VERSION")) { + if(cmd && !irccasecmp(cmd, "VERSION")) { char *version = mysep(&text, "\n"); if(!version) version = ""; @@ -3032,7 +3081,7 @@ rank_outside_rec(struct route *route, char *server, int count) return(max + 1); } else { - log_module(MAIN_LOG, LOG_ERROR, "routing struct rank_outsideness() couldnt find %s", server); + log_module(MAIN_LOG, LOG_WARNING, "routing struct rank_outsideness() couldnt find %s", server); return 0; } } @@ -3105,7 +3154,7 @@ change_route_uplinks(struct route *route) strcpy(lastserver, servicename); rptr = find_routeList_server(route, self->uplink->name); if(!rptr) { - log_module(MAIN_LOG, LOG_ERROR, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered."); + log_module(MAIN_LOG, LOG_WARNING, "Cannot convert routing map to center: My uplink is not on the map! Marking map as uncentered."); route->centered = false; return false; } @@ -3152,7 +3201,7 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) /* since it doesnt exist, remove the active setting */ dict_remove(opserv_routing_plan_options, plan_name); } - log_module(MAIN_LOG, LOG_ERROR, "activate_routing() couldnt find active routing plan!"); + log_module(MAIN_LOG, LOG_WARNING, "activate_routing() couldnt find active routing plan!"); return 0; } } @@ -3177,6 +3226,8 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) /* Delete the existing active route */ wipe_route_list(opserv_route); + if(!rp || !rp->servers) + return 1; for(it = dict_first(rp->servers); it; it = iter_next(it)) { const char* servername = iter_key(it); struct routingPlanServer *rps = iter_data(it), @@ -3649,7 +3700,7 @@ routing_handle_connect_failure(struct server *source, char *server, char *messag char *active; struct routingPlan *rp; struct routingPlanServer *rps; - log_module(MAIN_LOG, LOG_ERROR, "Failed to connect %s to %s: %s", server, source->name, message); + log_module(MAIN_LOG, LOG_WARNING, "Failed to connect %s to %s: %s", server, source->name, message); /* remove the waiting connection n timeq */ routing_delete_connect_timer(server); /* check if routing is active.. */ @@ -4621,7 +4672,7 @@ add_gag_helper(const char *key, void *data, UNUSED_ARG(void *extra)) } static struct opserv_user_alert * -opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim) +opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_reaction reaction, const char *text_discrim, int last, int expire) { unsigned int wordc; char *wordv[MAXNUMPARAMS], *discrim_copy; @@ -4635,9 +4686,11 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react alert = malloc(sizeof(*alert)); alert->owner = strdup(req->handle_info ? req->handle_info->handle : req->nick); alert->text_discrim = strdup(text_discrim); + alert->last = last; discrim_copy = strdup(text_discrim); /* save a copy of the discrim */ wordc = split_line(discrim_copy, false, ArrayLength(wordv), wordv); alert->discrim = opserv_discrim_create(req, opserv, wordc, wordv, 0); + alert->expire = expire; /* Check for missing required criteria or broken records */ if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) || (reaction==REACT_SVSPART && !alert->discrim->chantarget) || @@ -4662,6 +4715,11 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react dict_insert(opserv_channel_alerts, name_dup, alert); if (alert->discrim->mask_nick) dict_insert(opserv_nick_based_alerts, name_dup, alert); + if (alert->discrim->accountmask) + dict_insert(opserv_account_based_alerts, name_dup, alert); + + if (alert->expire) + timeq_add(alert->expire, alert_expire, (void*)name_dup); return alert; } @@ -4686,6 +4744,8 @@ static int add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) { dict_t alert_dict; + char *str; + int last = 0, expire = 0; const char *discrim, *react, *owner; opserv_alert_reaction reaction; struct opserv_user_alert *alert; @@ -4696,6 +4756,13 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) } discrim = database_get_data(alert_dict, KEY_DISCRIM, RECDB_QSTRING); react = database_get_data(alert_dict, KEY_REACTION, RECDB_QSTRING); + str = database_get_data(alert_dict, KEY_LAST, RECDB_QSTRING); + if (str) + last = atoi(str); + str = database_get_data(alert_dict, KEY_EXPIRE, RECDB_QSTRING); + if (str) + expire = atoi(str); + if (!react || !irccasecmp(react, "notice")) reaction = REACT_NOTICE; else if (!irccasecmp(react, "kill")) @@ -4722,7 +4789,7 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) log_module(OS_LOG, LOG_ERROR, "Invalid reaction %s for alert %s.", react, key); return 0; } - alert = opserv_add_user_alert(opserv, key, reaction, discrim); + alert = opserv_add_user_alert(opserv, key, reaction, discrim, last, expire); if (!alert) { log_module(OS_LOG, LOG_ERROR, "Unable to create alert %s from database.", key); return 0; @@ -4992,6 +5059,8 @@ opserv_saxdb_write(struct saxdb_context *ctx) saxdb_start_record(ctx, iter_key(it), 0); saxdb_write_string(ctx, KEY_DISCRIM, alert->text_discrim); saxdb_write_string(ctx, KEY_OWNER, alert->owner); + saxdb_write_int(ctx, KEY_LAST, alert->last); + saxdb_write_int(ctx, KEY_EXPIRE, alert->expire); switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; case REACT_KILL: reaction = "kill"; break; @@ -5193,6 +5262,8 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int } discrim->accountmask = argv[++i]; discrim->authed = 1; + } else if (irccasecmp(argv[i], "marked") == 0) { + discrim->mask_mark = argv[++i]; } else if (irccasecmp(argv[i], "chantarget") == 0) { if(!IsChannelName(argv[i+1])) { send_message(user, bot, "MSG_NOT_CHANNEL_NAME"); @@ -5358,6 +5429,8 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int discrim->domain_depth = strtoul(argv[++i], NULL, 0); } else if (irccasecmp(argv[i], "clones") == 0) { discrim->min_clones = strtoul(argv[++i], NULL, 0); + } else if (irccasecmp(argv[i], "modes") == 0) { + discrim->modes = argv[++i]; } else { send_message(user, bot, "MSG_INVALID_CRITERIA", argv[i]); goto fail; @@ -5384,7 +5457,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int { if(discrim->mask_nick) { - int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_nick, discrim->mask_nick, REG_EXTENDED|REG_NOSUB); discrim->has_regex_nick = !err; if(err) { @@ -5398,7 +5471,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_ident) { - int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_ident, discrim->mask_ident, REG_EXTENDED|REG_NOSUB); discrim->has_regex_ident = !err; if(err) { @@ -5412,7 +5485,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_host) { - int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_host, discrim->mask_host, REG_EXTENDED|REG_NOSUB); discrim->has_regex_host = !err; if(err) { @@ -5426,7 +5499,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_info) { - int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_info, discrim->mask_info, REG_EXTENDED|REG_NOSUB); discrim->has_regex_info = !err; if(err) { @@ -5440,7 +5513,7 @@ opserv_discrim_create(struct userNode *user, struct userNode *bot, unsigned int if(discrim->mask_version) { - int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_ICASE|REG_NOSUB); + int err = regcomp(&discrim->regex_version, discrim->mask_version, REG_EXTENDED|REG_NOSUB); discrim->has_regex_version = !err; if(err) { @@ -5488,6 +5561,7 @@ discrim_match(discrim_t discrim, struct userNode *user) || (discrim->info_space == 0 && user->info[0] == ' ') || (discrim->info_space == 1 && user->info[0] != ' ') || (discrim->server && !match_ircglob(user->uplink->name, discrim->server)) + || (discrim->mask_mark && (!user->mark || !match_ircglob(user->mark, discrim->mask_mark))) || (discrim->accountmask && (!user->handle_info || !match_ircglob(user->handle_info->handle, discrim->accountmask))) || (discrim->ip_mask_bits && !irc_check_mask(&user->ip, &discrim->ip_mask, discrim->ip_mask_bits)) ) @@ -5542,6 +5616,57 @@ discrim_match(discrim_t discrim, struct userNode *user) return 0; } + if (discrim->modes) { + unsigned int ii, matches = 0; + for (ii = 0; ii < strlen(discrim->modes); ii++) { + switch(discrim->modes[ii]) { + case 'O': + if(IsOper(user)) matches++; + break; + case 'o': + if(IsOper(user)) matches++; + break; + case 'i': + if(IsInvisible(user)) matches++; + break; + case 'w': + if(IsWallOp(user)) matches++; + break; + case 's': + if(IsServNotice(user)) matches++; + break; + case 'd': + if(IsDeaf(user)) matches++; + break; + case 'k': + if(IsService(user)) matches++; + break; + case 'g': + if(IsGlobal(user)) matches++; + break; + case 'h': + if(IsSetHost(user)) matches++; + break; + case 'B': + if(IsBotM(user)) matches++; + break; + case 'n': + if(IsHideChans(user)) matches++; + break; + case 'I': + if(IsHideIdle(user)) matches++; + break; + case 'X': + if(IsXtraOp(user)) matches++; + break; + case 'x': + if(IsHiddenHost(user)) matches++; + break; + } + } + if (matches != strlen(discrim->modes)) return 0; + } + access = user->handle_info ? user->handle_info->opserv_level : 0; if ((access < discrim->min_level) || (access > discrim->max_level)) { @@ -5725,20 +5850,22 @@ trace_svsjoin_func(struct userNode *match, void *extra) } if (checkrestrictions) { - if (trace_check_bans(target, channel) == 1) { - return; /* found on lamer list */ + if (trace_check_bans(match, channel) == 1) { + return 1; /* found on lamer list */ } if (channel->modes & MODE_INVITEONLY) { - return; /* channel is invite only */ + return 1; /* channel is invite only */ } - if (channel->members.used >= channel->limit) { - return; /* channel is invite on */ + if (channel->limit > 0) { + if (channel->members.used >= channel->limit) { + return 1; /* channel is invite on */ + } } if (*channel->key) { - return; /* channel is password protected */ + return 1; /* channel is password protected */ } } @@ -6403,6 +6530,8 @@ alert_check_user(const char *key, void *data, void *extra) if (alert->discrim->option_log) log_module(OS_LOG, LOG_INFO, "Alert %s triggered by user %s!%s@%s (%s).", key, user->nick, user->ident, user->hostname, alert->discrim->reason); + alert->last = now; + /* Return 1 to halt alert matching, such as when killing the user that triggered the alert. */ switch (alert->reaction) { @@ -6449,11 +6578,19 @@ alert_check_user(const char *key, void *data, void *extra) return 0; } +static void +opserv_alert_check_account(struct userNode *user, UNUSED_ARG(struct handle_info *old_handle)) +{ + dict_foreach(opserv_account_based_alerts, alert_check_user, user); +} + static void opserv_alert_check_nick(struct userNode *user, UNUSED_ARG(const char *old_nick)) { struct gag_entry *gag; - dict_foreach(opserv_nick_based_alerts, alert_check_user, user); + + dict_foreach(opserv_nick_based_alerts, alert_check_user, user); + /* Gag them if appropriate (and only if). */ user->modes &= ~FLAGS_GAGGED; for (gag = gagList; gag; gag = gag->next) { @@ -6591,6 +6728,7 @@ static MODCMD_FUNC(cmd_addalert) struct svccmd *subcmd; const char *name; char buf[MAXLEN]; + int expire = 0; name = argv[1]; sprintf(buf, "addalert %s", argv[2]); @@ -6625,8 +6763,12 @@ static MODCMD_FUNC(cmd_addalert) reply("OSMSG_UNKNOWN_REACTION", argv[2]); return 0; } + + if (argc >= 4 && !irccasecmp(argv[3], "expire")) + expire = now + ParseInterval(argv[4]); + if (!svccmd_can_invoke(user, opserv_service->bot, subcmd, channel, SVCCMD_NOISY) - || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + 3, argc - 3, NULL))) { + || !opserv_add_user_alert(user, name, reaction, unsplit_string(argv + (expire ? 5 : 3), argc - (expire ? 5 : 3), NULL), 0, expire)) { reply("OSMSG_ALERT_ADD_FAILED"); return 0; } @@ -6634,13 +6776,30 @@ static MODCMD_FUNC(cmd_addalert) return 1; } +static int delete_alert(char const* name) +{ + dict_remove(opserv_nick_based_alerts, (char const*)name); + dict_remove(opserv_channel_alerts, (char const*)name); + dict_remove(opserv_account_based_alerts, (char const*)name); + return dict_remove(opserv_user_alerts, (char const*)name); +} + +static void alert_expire(void* name) +{ + int present = 0; + struct opserv_user_alert* alert = NULL; + + alert = dict_find(opserv_user_alerts, (char const*)name, &present); + + if (present && alert && alert->expire > 0 && alert->expire <= now) + delete_alert(name); +} + static MODCMD_FUNC(cmd_delalert) { unsigned int i; for (i=1; i