]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/opserv.c
proto: add extra metadata to oper handler
[irc/evilnet/x3.git] / src / opserv.c
index 42020d1b4e0e985905a2ff51730d76f8345561c4..e4c210abc077ddd5d7fe8d592a4271b5aaf89e3d 100644 (file)
@@ -305,8 +305,8 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
     { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
     { "OSMSG_SSYNC_RUNNING", "Synchronizing shuns from %s." },
-    { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, lastmod %s, expires %s): %s" },
-    { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, lastmod %s, expires %s): %s" },
+    { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
+    { "OSMSG_STRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
     { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
     { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
     { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
@@ -1304,7 +1304,7 @@ opserv_block(struct userNode *target, char *src_handle, char *reason, unsigned l
                  "G-line requested by %s.", src_handle);
     if (!duration)
         duration = opserv_conf.block_gline_duration;
-    return gline_add(src_handle, mask, duration, reason, now, now, 1, silent ? 1 : 0);
+    return gline_add(src_handle, mask, duration, reason, now, 1, silent ? 1 : 0);
 }
 
 static MODCMD_FUNC(cmd_block)
@@ -1376,7 +1376,7 @@ static MODCMD_FUNC(cmd_gline)
         reply("MSG_INVALID_DURATION", argv[2]);
         return 0;
     }
-    gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, now, 1, 0);
+    gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, 1, 0);
     reply("OSMSG_GLINE_ISSUED", gline->target);
     return 1;
 }
@@ -1506,7 +1506,7 @@ opserv_shun(struct userNode *target, char *src_handle, char *reason, unsigned lo
         snprintf(reason, MAXLEN, "Shun requested by %s.", src_handle);
     }
     if (!duration) duration = opserv_conf.block_shun_duration;
-    return shun_add(src_handle, mask, duration, reason, now, now, 1);
+    return shun_add(src_handle, mask, duration, reason, now, 1);
 }
 
 static MODCMD_FUNC(cmd_sblock)
@@ -1578,7 +1578,7 @@ static MODCMD_FUNC(cmd_shun)
         reply("MSG_INVALID_DURATION", argv[2]);
         return 0;
     }
-    shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, now, 1);
+    shun = shun_add(user->handle_info->handle, argv[1], duration, reason, now, 1);
     reply("OSMSG_SHUN_ISSUED", shun->target);
     return 1;
 }
@@ -2173,25 +2173,8 @@ static MODCMD_FUNC(cmd_whois)
     reply("OSMSG_WHOIS_NO_NOTICE", target->no_notice ? "YES":"NO");
   
     if (target->modes) {
-        bpos = 0;
+        bpos = irc_user_modes(target, buffer, sizeof(buffer));
 #define buffer_cat(str) (herelen = strlen(str), memcpy(buffer+bpos, str, herelen), bpos += herelen)
-        if (IsInvisible(target)) buffer[bpos++] = 'i';
-        if (IsWallOp(target)) buffer[bpos++] = 'w';
-        if (IsOper(target)) buffer[bpos++] = 'o';
-        if (IsGlobal(target)) buffer[bpos++] = 'g';
-
-        // sethost - reed/apples
-        // if (IsHelperIrcu(target)) buffer[bpos++] = 'h';
-        if (IsSetHost(target)) buffer[bpos++] = 'h';
-
-        if (IsService(target)) buffer[bpos++] = 'k';
-        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;
@@ -2758,7 +2741,7 @@ opserv_part_channel(void *data)
 static int alert_check_user(const char *key, void *data, void *extra);
 
 static int
-opserv_new_user_check(struct userNode *user)
+opserv_new_user_check(struct userNode *user, UNUSED_ARG(void *extra))
 {
     struct opserv_hostinfo *ohi;
     struct gag_entry *gag;
@@ -2811,9 +2794,9 @@ opserv_new_user_check(struct userNode *user)
 
         strcpy(target + 2, user->hostname);
         if (checkDefCon(DEFCON_GLINE_NEW_CLIENTS))
-            gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, now, 1, 0);
+            gline_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1, 0);
         else if (checkDefCon(DEFCON_SHUN_NEW_CLIENTS))
-            shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, now, 1);
+            shun_add(opserv->nick, target, DefConGlineExpire, DefConGlineReason, now, 1);
           
         return 0;
     }
@@ -2837,7 +2820,7 @@ opserv_new_user_check(struct userNode *user)
         } else if (ohi->clients.used > limit) {
             char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' };
             strcpy(target + 2, addr);
-            gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, now, 1, 1);
+            gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "Excessive connections from a single host.", now, 1, 1);
         }
     }
 
@@ -2845,7 +2828,7 @@ opserv_new_user_check(struct userNode *user)
 }
 
 static void
-opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why))
+opserv_user_cleanup(struct userNode *user, UNUSED_ARG(struct userNode *killer), UNUSED_ARG(const char *why), UNUSED_ARG(void *extra))
 {
     struct opserv_hostinfo *ohi;
     char addr[IRC_NTOP_MAX_SIZE];
@@ -5883,6 +5866,30 @@ trace_print_func(struct userNode *match, void *extra)
     return 0;
 }
 
+static int
+trace_privmsg_func(struct userNode *match, void *extra)
+{
+    struct discrim_and_source *das = extra;
+    char *reason;
+    if (das->discrim->reason) {
+        reason = das->discrim->reason;
+        irc_privmsg_user(opserv, match, reason);
+    }
+    return 0;
+}
+
+static int
+trace_notice_func(struct userNode *match, void *extra)
+{
+    struct discrim_and_source *das = extra;
+    char *reason;
+    if (das->discrim->reason) {
+        reason = das->discrim->reason;
+        irc_notice_user(opserv, match, reason);
+    }
+    return 0;
+}
+
 static int
 trace_count_func(UNUSED_ARG(struct userNode *match), UNUSED_ARG(void *extra))
 {
@@ -6170,6 +6177,10 @@ static MODCMD_FUNC(cmd_trace)
         action = trace_print_func;
     else if (!irccasecmp(argv[1], "count"))
         action = trace_count_func;
+    else if (!irccasecmp(argv[1], "privmsg"))
+        action = trace_privmsg_func;
+    else if (!irccasecmp(argv[1], "notice"))
+        action = trace_notice_func;
     else if (!irccasecmp(argv[1], "domains"))
         action = trace_domains_func;
     else if (!irccasecmp(argv[1], "gline"))
@@ -6504,19 +6515,14 @@ gtrace_print_func(struct gline *gline, void *extra)
 {
     struct gline_extra *xtra = extra;
     char issued[INTERVALLEN];
-    char lastmod[INTERVALLEN];
     char expires[INTERVALLEN];
 
     intervalString(issued, now - gline->issued, xtra->user->handle_info);
-    if (gline->lastmod)
-        intervalString(lastmod, now - gline->lastmod, xtra->user->handle_info);
-    else
-        strcpy(lastmod, "<unknown>");
     if (gline->expires)
         intervalString(expires, gline->expires - now, xtra->user->handle_info);
     else
         strcpy(expires, "never");
-    send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason);
+    send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, expires, gline->reason);
 }
 
 static MODCMD_FUNC(cmd_stats_glines) {
@@ -6613,19 +6619,14 @@ strace_print_func(struct shun *shun, void *extra)
 {
     struct shun_extra *xtra = extra;
     char issued[INTERVALLEN];
-    char lastmod[INTERVALLEN];
     char expires[INTERVALLEN];
 
     intervalString(issued, now - shun->issued, xtra->user->handle_info);
-    if (shun->lastmod)
-        intervalString(lastmod, now - shun->lastmod, xtra->user->handle_info);
-    else
-        strcpy(lastmod, "<unknown>");
     if (shun->expires)
         intervalString(expires, shun->expires - now, xtra->user->handle_info);
     else
         strcpy(expires, "never");
-    send_message(xtra->user, opserv, "OSMSG_STRACE_FORMAT", shun->target, issued, shun->issuer, lastmod, expires, shun->reason);
+    send_message(xtra->user, opserv, "OSMSG_STRACE_FORMAT", shun->target, issued, shun->issuer, expires, shun->reason);
 }
 
 static MODCMD_FUNC(cmd_stats_shuns) {
@@ -7219,7 +7220,7 @@ opserv_db_cleanup(void)
     free_string_list(opserv_bad_words);
     dict_delete(opserv_exempt_channels);
     dict_delete(opserv_trusted_hosts);
-    unreg_del_user_func(opserv_user_cleanup);
+    unreg_del_user_func(opserv_user_cleanup, NULL);
     dict_delete(opserv_hostinfo_dict);
     dict_delete(opserv_nick_based_alerts);
     dict_delete(opserv_account_based_alerts);
@@ -7359,6 +7360,8 @@ init_opserv(const char *nick)
     opserv_define_func("TRACE", cmd_trace, 100, 0, 3);
     opserv_define_func("TRACE PRINT", NULL, 0, 0, 0);
     opserv_define_func("TRACE COUNT", NULL, 0, 0, 0);
+    opserv_define_func("TRACE PRIVMSG", NULL, 0, 0, 0);
+    opserv_define_func("TRACE NOTICE", NULL, 0, 0, 0);
     opserv_define_func("TRACE DOMAINS", NULL, 0, 0, 0);
     opserv_define_func("TRACE GLINE", NULL, 600, 0, 0);
     opserv_define_func("TRACE SHUN", NULL, 600, 0, 0);
@@ -7390,9 +7393,9 @@ init_opserv(const char *nick)
     opserv_waiting_connections = dict_new();
     dict_set_free_data(opserv_waiting_connections, opserv_free_waiting_connection);
 
-    reg_new_user_func(opserv_new_user_check);
+    reg_new_user_func(opserv_new_user_check, NULL);
     reg_nick_change_func(opserv_alert_check_nick);
-    reg_del_user_func(opserv_user_cleanup);
+    reg_del_user_func(opserv_user_cleanup, NULL);
     reg_new_channel_func(opserv_channel_check); 
     reg_del_channel_func(opserv_channel_delete);
     reg_join_func(opserv_join_check);