]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/opserv.c
$! helpfile syntax for trigger, some cleanup
[irc/evilnet/x3.git] / src / opserv.c
index e28b4d2876e0646ecc65da164e63bc70bef4ada8..c61c82d81e979b856bd7b1bcd340b2940e1dadb1 100644 (file)
@@ -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." },
@@ -277,6 +279,8 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_USER_SEARCH_BAR",    "-------------------------------------------" },
     { "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:" },
@@ -296,6 +300,7 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_ALERT_EXISTS", "An alert named $b%s$b already exists." },
     { "OSMSG_UNKNOWN_REACTION", "Unknown alert reaction $b%s$b." },
     { "OSMSG_ADDED_ALERT", "Added alert named $b%s$b." },
+    { "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" },
@@ -548,6 +553,7 @@ typedef enum {
     REACT_TRACK,
     REACT_SHUN,
     REACT_SVSJOIN,
+    REACT_SVSPART,
     REACT_VERSION
 } opserv_alert_reaction;
 
@@ -1370,6 +1376,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)
 {
@@ -1466,7 +1495,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;
@@ -1480,7 +1509,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)
@@ -1495,7 +1524,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);
     }
 }
 
@@ -1729,6 +1758,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;
@@ -1944,7 +2002,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;
@@ -2279,6 +2337,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 = "<unknown>"; break;
         }
@@ -4459,7 +4518,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) {
+    if (!alert->discrim || (reaction==REACT_SVSJOIN && !alert->discrim->chantarget) ||
+       (reaction==REACT_SVSPART && !alert->discrim->chantarget)) {
         free(alert->text_discrim);
         free(discrim_copy);
         free(alert);
@@ -4530,6 +4590,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 {
@@ -4814,6 +4876,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;
@@ -5498,7 +5561,7 @@ trace_svsjoin_func(struct userNode *match, void *extra)
     char *channame = das->discrim->chantarget;
     struct chanNode *channel;
 
-    if(!IsChannelName(channame)) {
+    if(!channame || !IsChannelName(channame)) {
         //reply("MSG_NOT_CHANNEL_NAME");
         return 1;
     }
@@ -5515,6 +5578,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))
 {
@@ -5631,6 +5714,7 @@ static MODCMD_FUNC(cmd_trace)
     unsigned int matches;
     struct svccmd *subcmd;
     char buf[MAXLEN];
+    int ret = 1;
 
     sprintf(buf, "trace %s", argv[1]);
     if (!(subcmd = dict_find(opserv_service->commands, buf, NULL))) {
@@ -5655,6 +5739,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 {
@@ -5694,20 +5780,31 @@ static MODCMD_FUNC(cmd_trace)
         das.disp_limit = das.discrim->limit;
         das.discrim->limit = INT_MAX;
     }
-    matches = opserv_discrim_search(das.discrim, action, &das);
 
-    if (action == trace_domains_func)
-        dict_foreach(das.dict, opserv_show_hostinfo, &das);
+    if (action == trace_svsjoin_func && !das.discrim->chantarget) {
+        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);
 
-    if (matches)
-    {
-        if(action == trace_print_func)
-            reply("OSMSG_USER_SEARCH_COUNT_BAR", matches);
+        if (action == trace_domains_func)
+            dict_foreach(das.dict, opserv_show_hostinfo, &das);
+
+        if (matches)
+        {
+            if(action == trace_print_func)
+                reply("OSMSG_USER_SEARCH_COUNT_BAR", matches);
+            else
+                reply("OSMSG_USER_SEARCH_COUNT", matches);
+        }
         else
-            reply("OSMSG_USER_SEARCH_COUNT", matches);
+                reply("MSG_NO_MATCHES");
     }
-    else
-            reply("MSG_NO_MATCHES");
 
     if (das.discrim->channel)
         UnlockChannel(das.discrim->channel);
@@ -5726,7 +5823,7 @@ static MODCMD_FUNC(cmd_trace)
 
     free(das.discrim);
     dict_delete(das.dict);
-    return 1;
+    return ret;
 }
 
 typedef void (*cdiscrim_search_func)(struct chanNode *match, void *data, struct userNode *bot);
@@ -6142,6 +6239,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... 
@@ -6320,10 +6420,6 @@ static MODCMD_FUNC(cmd_addalert)
         reaction = REACT_NOTICE;
     else if (!irccasecmp(argv[2], "kill"))
         reaction = REACT_KILL;
-/*
-    else if (!irccasecmp(argv[2], "silent"))
-        reaction = REACT_SILENT;
-*/
     else if (!irccasecmp(argv[2], "gline"))
         reaction = REACT_GLINE;
     else if (!irccasecmp(argv[2], "track")) {
@@ -6337,6 +6433,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 {
@@ -6344,8 +6442,10 @@ static MODCMD_FUNC(cmd_addalert)
         return 0;
     }
     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 + 3, argc - 3, NULL))) {
+        reply("OSMSG_ALERT_ADD_FAILED");
         return 0;
+    }
     reply("OSMSG_ADDED_ALERT", name);
     return 1;
 }
@@ -6603,6 +6703,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);
@@ -6646,6 +6747,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);
@@ -6709,6 +6811,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);