X-Git-Url: https://jfr.im/git/irc/evilnet/x3.git/blobdiff_plain/a62ba70c7df022d0738b33c603cc3e340727bbd8..283cfa834c5e05d55462ffe643f0c301ef21ed4a:/src/opserv.c?ds=sidebyside diff --git a/src/opserv.c b/src/opserv.c index 292ceef..5e0a7cd 100644 --- a/src/opserv.c +++ b/src/opserv.c @@ -163,8 +163,10 @@ 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_NOT_THERE", "You not in $b%s$b." }, { "OSMSG_JOIN_DONE", "I have joined $b%s$b." }, { "OSMSG_SVSJOIN_SENT", "Sent the SVSJOIN." }, + { "OSMSG_SVSPART_SENT", "Sent the SVSPART." }, { "OSMSG_ALREADY_JOINED", "I am already in $b%s$b." }, { "OSMSG_NOT_ON_CHANNEL", "$b%s$b does not seem to be on $b%s$b." }, { "OSMSG_KICKALL_DONE", "I have cleared out %s." }, @@ -201,6 +203,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_NO_NOTICE", "No_notices : %s" }, { "OSMSG_UNBAN_DONE", "Ban(s) removed from channel %s." }, { "OSMSG_CHANNEL_VOICED", "All users on %s voiced." }, { "OSMSG_CHANNEL_DEVOICED", "All voiced users on %s de-voiced." }, @@ -278,6 +281,7 @@ static const struct message_entry msgtab[] = { { "OSMSG_USER_SEARCH_COUNT", "There were %4u matches" }, { "OSMSG_USER_SEARCH_COUNT_BAR", "------------ Found %4u matches -----------" }, { "OSMSG_SVSJOIN_NO_TARGET", "SVSJOIN action requires chantarget criteria (where should they join?)" }, + { "OSMSG_SVSPART_NO_TARGET", "SVSPART action requires chantarget criteria (where should they join?)" }, { "OSMSG_CHANNEL_SEARCH_RESULTS", "The following channels were found:" }, { "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" }, { "OSMSG_SHUN_SEARCH_RESULTS", "The following shun were found:" }, @@ -300,22 +304,24 @@ static const struct message_entry msgtab[] = { { "OSMSG_ALERT_ADD_FAILED", "Unable to add alert. Check syntax, required parts, and access" }, { "OSMSG_REMOVED_ALERT", "Removed alert named $b%s$b." }, { "OSMSG_NO_SUCH_ALERT", "No alert named $b%s$b could be found." }, - { "OSMSG_ALERTS_LIST", "$bCurrent $O alerts$b" }, + { "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_ALERT_IS", "$b%-20s$b %-6s (by %s)" }, { "OSMSG_ALERT_END", "----------------End of Alerts-----------------" }, /* routing messages */ - { "OSMSG_ROUTINGPLAN_LIST", "$bRouting Plans$b" }, + { "OSMSG_ROUTINGPLAN", "$bRouting Plan(s)$b" }, + { "OSMSG_ROUTINGPLAN_LIST_HEAD", "$bRouting Plans$b" }, { "OSMSG_ROUTINGPLAN_BAR", "----------------------------------------------" }, - { "OSMSG_ROUTINGPLAN_END", "-------------End of Routing Plans-------------" }, + { "OSMSG_ROUTINGPLAN_END", "------------End of Routing Plan(s)------------" }, { "OSMSG_ROUTINGPLAN_OPTION", "%s is set to %s" }, { "OSMSG_ROUTINGPLAN_ACTIVE", "Auto routing is active, using plan '%s'." }, { "OSMSG_ROUTING_ACTIVATION_ERROR", "There was an error activating the routing plan. Check for loops, and make sure the map includes my own uplink." }, { "OSMSG_ROUTINGPLAN_OPTION_NOT_FOUND", "There is no routing plan option '%s'." }, { "OSMSG_ROUTINGPLAN_OPTION_NOT_SET", "Option '%s' is not currently set." }, { "OSMSG_ROUTINGPLAN_NAME", "$b%s:$b" }, + { "OSMSG_ROUTINGPLAN_LIST", "$b%s$b" }, { "OSMSG_ROUTINGPLAN_SERVER"," %s:%d <-- %s[%d/%s] (%s)" }, { "OSMSG_ADDPLAN_SUCCESS", "Added new routing plan '%s'." }, { "OSMSG_ADDPLAN_FAILED", "Could not add new plan '%s' (does it already exist?)." }, @@ -550,6 +556,7 @@ typedef enum { REACT_TRACK, REACT_SHUN, REACT_SVSJOIN, + REACT_SVSPART, REACT_VERSION } opserv_alert_reaction; @@ -738,7 +745,7 @@ static MODCMD_FUNC(cmd_defcon) showDefConSettings(user, cmd); if (DefConTimeOut > 0) { - timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA & TIMEQ_IGNORE_WHEN); + timeq_del(0, defcon_timeout, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); timeq_add(now + DefConTimeOut, defcon_timeout, NULL); } @@ -1372,6 +1379,29 @@ opserv_svsjoin(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG /* Should we tell the user they got joined? -Rubin*/ } +static void +opserv_svspart(struct userNode *target, UNUSED_ARG(char *src_handle), UNUSED_ARG(char *reason), char *channame) +{ + struct chanNode *channel; + + if(!channame || !IsChannelName(channame)) { + /* Not a valid channel name. We shouldnt ever get this if we check properly in addalert */ + return; + } + + if (!(channel = GetChannel(channame))) { + /* channel doesnt exist */ + return; + } + + if (!GetUserMode(channel, target)) { + /* not in it */ + return; + } + + irc_svspart(opserv, target, channel); +} + static struct shun * opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned long duration) { @@ -1468,7 +1498,7 @@ static MODCMD_FUNC(cmd_refreshs) } static void -opserv_ison(struct userNode *tell, struct userNode *target, const char *message) +opserv_ison(struct userNode *bot, struct userNode *tell, struct userNode *target, const char *message) { struct modeNode *mn; unsigned int count, here_len, n, maxlen; @@ -1482,7 +1512,7 @@ opserv_ison(struct userNode *tell, struct userNode *target, const char *message) here_len = strlen(mn->channel->name); if ((count + here_len + 4) > maxlen) { buff[count] = 0; - send_message(tell, opserv, message, buff); + send_message(tell, bot, message, buff); count = 0; } if (mn->modes & MODE_CHANOP) @@ -1497,7 +1527,7 @@ opserv_ison(struct userNode *tell, struct userNode *target, const char *message) } if (count) { buff[count] = 0; - send_message(tell, opserv, message, buff); + send_message(tell, bot, message, buff); } } @@ -1731,6 +1761,35 @@ static MODCMD_FUNC(cmd_kickbanall) return 1; } +static MODCMD_FUNC(cmd_svspart) +{ + struct userNode *target; + + if(!IsChannelName(argv[2])) { + reply("MSG_NOT_CHANNEL_NAME"); + 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); + return 0; + } + + irc_svspart(opserv, target, channel); + reply("OSMSG_SVSPART_SENT"); + return 1; +} + static MODCMD_FUNC(cmd_part) { char *reason; @@ -1910,6 +1969,7 @@ static MODCMD_FUNC(cmd_whois) if(target->version_reply) { reply("OSMSG_WHOIS_VERSION", target->version_reply); } + reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO"); if (target->modes) { bpos = 0; @@ -1946,7 +2006,7 @@ static MODCMD_FUNC(cmd_whois) intervalString(buffer, now - target->timestamp, user->handle_info); reply("OSMSG_WHOIS_NICK_AGE", buffer); if (target->channels.used <= MAX_CHANNELS_WHOIS) - opserv_ison(user, target, "OSMSG_WHOIS_CHANNELS"); + opserv_ison(cmd->parent->bot, user, target, "OSMSG_WHOIS_CHANNELS"); else reply("OSMSG_WHOIS_HIDECHANS"); return 1; @@ -2266,13 +2326,18 @@ static MODCMD_FUNC(cmd_stats_alerts) { dict_iterator_t it; struct opserv_user_alert *alert; const char *reaction; + char *m = NULL; - reply("OSMSG_ALERTS_LIST"); + if(argc > 1) + m = unsplit_string(argv + 1, argc - 1, NULL); + reply("OSMSG_ALERTS_LIST", m ? m : "*"); reply("OSMSG_ALERTS_BAR"); reply("OSMSG_ALERTS_HEADER"); 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)) ) + continue; /* not a match to requested filter */ switch (alert->reaction) { case REACT_NOTICE: reaction = "notice"; break; case REACT_KILL: reaction = "kill"; break; @@ -2281,6 +2346,7 @@ static MODCMD_FUNC(cmd_stats_alerts) { case REACT_TRACK: reaction = "track"; break; case REACT_SHUN: reaction = "shun"; break; case REACT_SVSJOIN: reaction = "svsjoin"; break; + case REACT_SVSPART: reaction = "svspart"; break; case REACT_VERSION: reaction = "version"; break; default: reaction = ""; break; } @@ -2676,7 +2742,7 @@ opserv_notice_handler(struct userNode *user, struct userNode *bot, char *text, U if(!version) version = ""; /* opserv_debug("Opserv got CTCP VERSION Notice from %s: %s", user->nick, version); */ - user->version_reply = strdup(version); + /* user->version_reply = strdup(version); done in parse-p10.c now */ dict_foreach(opserv_user_alerts, alert_check_user, user); } } @@ -3078,15 +3144,27 @@ activate_routing(struct svccmd *cmd, struct userNode *user, char *plan_name) add_routestruct_server(opserv_route, servername, rps->port, uplink, NULL); } if(change_route_uplinks(opserv_route)) + { return 1; + } else if(user) { reply("OSMSG_ROUTING_ACTIVATION_ERROR"); activate_routing(cmd, user, "*"); return 0; } + /* routing activation failed but we dont do anything? */ return 1; } + +void routing_init() +{ + activate_routing(NULL, NULL, NULL); + + /* start auto-routing system */ + reroute_timer_reset(0); +} + /******************************************************* * Functions to handle online route configuration via opserv */ @@ -3316,6 +3394,9 @@ static MODCMD_FUNC(cmd_reroute) { * and setup timer. */ void reroute_timer(void *data) { + /* Delete any other timers such as this one.. */ + timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); + if(!opserv_route || !opserv_route->servers) return; /* no active route */ char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); @@ -3325,6 +3406,9 @@ void reroute_timer(void *data) { if(freq < 1) return; /* retry_period set to 0, disable */ + /* opserv_debug("Reroute timer checking reroute"); */ + log_module(MAIN_LOG, LOG_DEBUG, "Reroute timer checking reroute()"); + /* Do the reroute C attempt */ if(data) reroute(opserv_route, NULL, NULL, "C"); @@ -3530,10 +3614,23 @@ routing_handle_connect_failure(struct server *source, char *server, char *messag /* Delete any existing timers, and start the timer again * using the passed time for the first run. * - this is called during a retry_period change - * before it has saved the new value. */ + * before it has saved the new value. + * + * If time is 0, lookup the interval. */ void reroute_timer_reset(unsigned int time) { - timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA & TIMEQ_IGNORE_WHEN); + timeq_del(0, reroute_timer, NULL, TIMEQ_IGNORE_DATA | TIMEQ_IGNORE_WHEN); + if(time == 0) { + if(!opserv_route || !opserv_route->servers) + return; /* no active route */ + char *retry_period = dict_find(opserv_routing_plan_options, "RETRY_PERIOD", NULL); + if(!retry_period) + return; /* retry_period invalid */ + time = atoi(retry_period); + if(time < 1) + return; /* retry_period set to 0, disable */ + + } timeq_add(now + time, reroute_timer, "run"); } @@ -3606,21 +3703,34 @@ static MODCMD_FUNC(cmd_stats_routing_plans) { dict_iterator_t rpit; dict_iterator_t it; struct routingPlan *rp; - reply("OSMSG_ROUTINGPLAN_LIST"); - reply("OSMSG_ROUTINGPLAN_BAR"); - for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { - const char* name = iter_key(rpit); - rp = iter_data(rpit); - reply("OSMSG_ROUTINGPLAN_NAME", name); - for(it = dict_first(rp->servers); it; it = iter_next(it)) { - const char* servername = iter_key(it); - struct routingPlanServer *rps = iter_data(it); - reply("OSMSG_ROUTINGPLAN_SERVER", servername, rps->port, rps->uplink, rps->karma, rps->offline? "offline" : "online", rps->secondaryuplink ? rps->secondaryuplink : "None"); - } + if(argc > 1) { + reply("OSMSG_ROUTINGPLAN"); + reply("OSMSG_ROUTINGPLAN_BAR"); + for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { + const char* name = iter_key(rpit); + rp = iter_data(rpit); + if(match_ircglob(name, argv[1])) { + reply("OSMSG_ROUTINGPLAN_NAME", name); + for(it = dict_first(rp->servers); it; it = iter_next(it)) { + const char* servername = iter_key(it); + struct routingPlanServer *rps = iter_data(it); + reply("OSMSG_ROUTINGPLAN_SERVER", servername, rps->port, rps->uplink, rps->karma, rps->offline? "offline" : "online", rps->secondaryuplink ? rps->secondaryuplink : "None"); + } + } + } + reply("OSMSG_ROUTINGPLAN_END"); + } + else { + reply("OSMSG_ROUTINGPLAN_LIST_HEAD"); + reply("OSMSG_ROUTINGPLAN_BAR"); + for(rpit = dict_first(opserv_routing_plans); rpit; rpit = iter_next(rpit)) { + const char* name = iter_key(rpit); + reply("OSMSG_ROUTINGPLAN_LIST", name); + } + reply("OSMSG_ROUTINGPLAN_END"); + route_show_options(cmd, user); } - reply("OSMSG_ROUTINGPLAN_END"); - route_show_options(cmd, user); return 1; } @@ -4461,7 +4571,8 @@ opserv_add_user_alert(struct userNode *req, const char *name, opserv_alert_react 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); - if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget)) { + if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) || + (reaction==REACT_SVSPART && !alert->discrim->chantarget)) { free(alert->text_discrim); free(discrim_copy); free(alert); @@ -4532,6 +4643,8 @@ add_user_alert(const char *key, void *data, UNUSED_ARG(void *extra)) reaction = REACT_SHUN; else if (!irccasecmp(react, "svsjoin")) reaction = REACT_SVSJOIN; + else if (!irccasecmp(react, "svspart")) + reaction = REACT_SVSPART; else if (!irccasecmp(react, "version")) reaction = REACT_VERSION; else { @@ -4816,6 +4929,7 @@ opserv_saxdb_write(struct saxdb_context *ctx) case REACT_TRACK: reaction = "track"; break; case REACT_SHUN: reaction = "shun"; break; case REACT_SVSJOIN: reaction = "svsjoin"; break; + case REACT_SVSPART: reaction = "svspart"; break; case REACT_VERSION: reaction = "version"; break; default: reaction = NULL; @@ -5517,6 +5631,26 @@ trace_svsjoin_func(struct userNode *match, void *extra) return 0; } +static int +trace_svspart_func(struct userNode *match, void *extra) +{ + struct discrim_and_source *das = extra; + char *channame = das->discrim->chantarget; + struct chanNode *channel; + + if(!channame || !IsChannelName(channame)) + return 1; + + if (!(channel = GetChannel(channame))) + return 1; + + if (!GetUserMode(channel, match)) + return 1; + + irc_svspart(opserv, match, channel); + return 0; +} + static int trace_version_func(struct userNode *match, UNUSED_ARG(void *extra)) { @@ -5658,6 +5792,8 @@ static MODCMD_FUNC(cmd_trace) action = trace_gag_func; else if (!irccasecmp(argv[1], "svsjoin")) action = trace_svsjoin_func; + else if (!irccasecmp(argv[1], "svspart")) + action = trace_svspart_func; else if (!irccasecmp(argv[1], "version")) action = trace_version_func; else { @@ -5702,6 +5838,10 @@ static MODCMD_FUNC(cmd_trace) reply("OSMSG_SVSJOIN_NO_TARGET"); ret = 0; } + else if (action == trace_svspart_func && !das.discrim->chantarget) { + reply("OSMSG_SVSPART_NO_TARGET"); + ret = 0; + } else { matches = opserv_discrim_search(das.discrim, action, &das); @@ -6152,6 +6292,9 @@ alert_check_user(const char *key, void *data, void *extra) case REACT_SVSJOIN: opserv_svsjoin(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget); break; + case REACT_SVSPART: + opserv_svspart(user, alert->owner, alert->discrim->reason, alert->discrim->chantarget); + break; case REACT_VERSION: /* Don't auto-version a user who we already have a version on, because the version reply itself * re-triggers this check... @@ -6343,6 +6486,8 @@ static MODCMD_FUNC(cmd_addalert) reaction = REACT_SHUN; else if(!irccasecmp(argv[2], "svsjoin")) reaction = REACT_SVSJOIN; + else if(!irccasecmp(argv[2], "svspart")) + reaction = REACT_SVSPART; else if(!irccasecmp(argv[2], "version")) reaction = REACT_VERSION; else { @@ -6611,6 +6756,7 @@ init_opserv(const char *nick) opserv_define_func("ADDALERT TRACK", NULL, 900, 0, 0); opserv_define_func("ADDALERT KILL", NULL, 900, 0, 0); opserv_define_func("ADDALERT SVSJOIN", NULL, 999, 0, 0); + opserv_define_func("ADDALERT SVSPART", NULL, 999, 0, 0); opserv_define_func("ADDALERT VERSION", NULL, 999, 0, 0); opserv_define_func("ADDBAD", cmd_addbad, 800, 0, 2); opserv_define_func("ADDEXEMPT", cmd_addexempt, 800, 0, 2); @@ -6654,6 +6800,7 @@ init_opserv(const char *nick) opserv_define_func("INVITEME", cmd_inviteme, 100, 0, 0); opserv_define_func("JOIN", cmd_join, 601, 0, 2); opserv_define_func("SVSJOIN", cmd_svsjoin, 999, 0, 3); + opserv_define_func("SVSPART", cmd_svspart, 999, 0, 3); opserv_define_func("JUMP", cmd_jump, 900, 0, 2); opserv_define_func("JUPE", cmd_jupe, 900, 0, 4); opserv_define_func("KICK", cmd_kick, 100, 2, 2); @@ -6717,6 +6864,7 @@ init_opserv(const char *nick) opserv_define_func("TRACE KILL", NULL, 600, 0, 0); opserv_define_func("TRACE VERSION", NULL, 999, 0, 0); opserv_define_func("TRACE SVSJOIN", NULL, 999, 0, 0); + opserv_define_func("TRACE SVSPART", NULL, 999, 0, 0); opserv_define_func("UNBAN", cmd_unban, 100, 2, 2); opserv_define_func("UNGAG", cmd_ungag, 600, 0, 2); opserv_define_func("UNGLINE", cmd_ungline, 600, 0, 2); @@ -6757,7 +6905,9 @@ init_opserv(const char *nick) } /* start auto-routing system */ - reroute_timer(NULL); + /* this cant be done here, because the routing system isnt marked active yet. */ + /* reroute_timer(NULL); */ + /* start the karma timer, using the saved one if available */ routing_karma_timer(dict_find(opserv_routing_plan_options, "KARMA_TIMER", NULL));