]> jfr.im git - irc/evilnet/x3.git/blobdiff - src/proto-p10.c
proto: add extra metadata to oper handler
[irc/evilnet/x3.git] / src / proto-p10.c
index 930df7887392c2008985d3db16c3fee673755093..aa223f6a1fb1fb66c8b14aa37508cba5b84dd8df 100644 (file)
@@ -95,6 +95,7 @@
 #define CMD_SMO                 "SMO"
 #define CMD_SNO                 "SNO"
 #define CMD_SSHUN              "SSHUN"
+#define CMD_SPAMFILTER          "SPAMFILTER"
 #define CMD_SQUERY              "SQUERY"
 #define CMD_SQUIT               "SQUIT"
 #define CMD_STATS               "STATS"
 #define TOK_SMO                 "SMO"
 #define TOK_SNO                 "SNO"
 #define TOK_SSHUN              "SSU"
+#define TOK_SPAMFILTER          "SF"
 #define TOK_SQUERY              "SQUERY"
 #define TOK_SQUIT               "SQ"
 #define TOK_STATS               "R"
 #define P10_SMO                 TYPE(SMO)
 #define P10_SNO                 TYPE(SNO)
 #define P10_SSHUN              TYPE(SSHUN)
+#define P10_SPAMFILTER          TYPE(SPAMFILTER)
 #define P10_SQUERY              TYPE(SQUERY)
 #define P10_SQUIT               TYPE(SQUIT)
 #define P10_STATS               TYPE(STATS)
@@ -340,6 +343,9 @@ static const char *his_servername;
 static const char *his_servercomment;
 static int extended_accounts;
 
+/* These correspond to 1 << X:      012345678901234567 */
+const char irc_user_mode_chars[] = "o iw dkgn        I";
+
 static struct userNode *AddUser(struct server* uplink, const char *nick, const char *ident, const char *hostname, const char *modes, const char *numeric, const char *userinfo, time_t timestamp, const char *realip);
 
 extern int off_channel;
@@ -575,41 +581,9 @@ irc_user(struct userNode *user)
         return;
     irc_p10_ntop(b64ip, &user->ip);
     if (user->modes) {
-        int modelen;
         char modes[32];
 
-        modelen = 0;
-        if (IsOper(user))
-            modes[modelen++] = 'o';
-        if (IsInvisible(user))
-            modes[modelen++] = 'i';
-        if (IsWallOp(user))
-            modes[modelen++] = 'w';
-        if (IsService(user))
-            modes[modelen++] = 'k';
-        if (IsDeaf(user))
-            modes[modelen++] = 'd';
-        if (IsGlobal(user))
-            modes[modelen++] = 'g';
-        // sethost - reed/apples
-        // if (IsHelperIrcu(user))
-        if (IsSetHost(user))
-            modes[modelen++] = 'h';
-        if (IsFakeHost(user))
-            modes[modelen++] = 'f';
-        if (IsHiddenHost(user))
-            modes[modelen++] = 'x';
-        if (IsBotM(user))
-            modes[modelen++] = 'B';
-        if (IsHideChans(user))
-            modes[modelen++] = 'n';
-        if (IsHideIdle(user))
-            modes[modelen++] = 'I';
-        if (IsXtraOp(user))
-            modes[modelen++] = 'X';
-
-        modes[modelen] = 0;
-
+        irc_user_modes(user, modes, sizeof(modes));
         /* we don't need to put the + in modes because it's in the format string. */
         putsock("%s " P10_NICK " %s %d " FMT_TIME_T " %s %s +%s %s %s :%s",
                 user->uplink->numeric, user->nick, user->uplink->hops+1, user->timestamp, user->ident, user->hostname, modes, b64ip, user->numeric, user->info);
@@ -847,23 +821,15 @@ irc_introduce(const char *passwd)
 void
 irc_gline(struct server *srv, struct gline *gline, int silent)
 {
-    if (gline->lastmod)
-        putsock("%s " P10_GLINE " %s +%s " FMT_TIME_T " " FMT_TIME_T " :%s<%s> %s",
-                self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, gline->lastmod, silent ? "AUTO " : "", gline->issuer, gline->reason);
-    else
-        putsock("%s " P10_GLINE " %s +%s " FMT_TIME_T " :%s<%s> %s",
-                self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, silent ? "AUTO " : "", gline->issuer, gline->reason);
+    putsock("%s " P10_GLINE " %s +%s " FMT_TIME_T " " FMT_TIME_T " :%s<%s> %s",
+            self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, now, silent ? "AUTO " : "", gline->issuer, gline->reason);
 }
 
 void
 irc_shun(struct server *srv, struct shun *shun)
 {
-    if (shun->lastmod)
-        putsock("%s " P10_SHUN " %s +%s %ld %ld :%s",
-                self->numeric, (srv ? srv->numeric : "*"), shun->target, shun->expires-now, shun->lastmod, shun->reason);
-    else
-        putsock("%s " P10_SHUN " %s +%s %ld :%s",
-                self->numeric, (srv ? srv->numeric : "*"), shun->target, shun->expires-now, shun->reason);
+    putsock("%s " P10_SHUN " %s +%s " FMT_TIME_T " :<%s> %s",
+            self->numeric, (srv ? srv->numeric : "*"), shun->target, shun->expires-now, shun->issuer, shun->reason);
 }
 
 void
@@ -1073,7 +1039,7 @@ irc_svspart(struct userNode *from, struct userNode *who, struct chanNode *to)
 }
 
 void
-irc_svsquit(struct userNode *from, struct userNode *who, char *reason)
+irc_svsquit(struct userNode *from, struct userNode *who, char const *reason)
 {
     putsock("%s " P10_SVSQUIT " %s :%s", from->uplink->numeric, who->numeric, reason);
 }
@@ -1320,7 +1286,6 @@ static CMD_FUNC(cmd_whois)
         }
         if (buf[0] != '\0')
             irc_numeric(from, RPL_WHOISCHANNELS, "%s :%s", who->nick, buf);
-        return 1;
     }
 
     if (his_servername && his_servercomment && !IsOper(from) && from != who)
@@ -1401,7 +1366,6 @@ static CMD_FUNC(cmd_eob)
 {
     struct server *sender;
     dict_iterator_t it;
-    unsigned int ii;
 
     if (!(sender = GetServerH(origin)))
         return 0;
@@ -1422,8 +1386,7 @@ static CMD_FUNC(cmd_eob)
     }
     sender->self_burst = 0;
     recalc_bursts(sender);
-    for (ii=0; ii<slf_used; ii++)
-        slf_list[ii](sender);
+    call_server_link_funcs(sender);
     /* let auto-routing figure out if we were
      * wating on this server to link a child to it */
     /* DONT call this if uplink is _US_ */
@@ -1676,7 +1639,8 @@ static struct {
   P(FORCE_LOCAL_OPMODE), P(REMOTEREHASH), P(CHECK), P(SEE_SECRET_CHAN),
   P(SHUN),           P(LOCAL_SHUN),     P(WIDE_SHUN),     P(ZLINE),
   P(LOCAL_ZLINE),    P(WIDE_ZLINE),     P(LIST_CHAN),     P(WHOIS_NOTICE),
-  P(HIDE_IDLE),      P(XTRAOP),         P(HIDE_CHANNELS),
+  P(HIDE_IDLE),      P(XTRAOP),         P(HIDE_CHANNELS), P(DISPLAY_MODE),
+  P(FREEFORM),       P(REMOVE),         P(SPAMFILTER),
 #undef P
   { 0, 0 }
 };
@@ -1744,6 +1708,12 @@ irc_privs(struct userNode *target, char *flag, int add)
     putsock("%s " P10_PRIVS " %s %s%s", self->numeric, target->numeric, (add == PRIV_ADD) ? "+" : "-", flag);
 }
 
+void
+irc_raw_privs(struct userNode *target, const char *privs)
+{
+    putsock("%s " P10_PRIVS " %s %s", self->numeric, target->numeric,  privs);
+}
+
 static CMD_FUNC(cmd_privs)
 {
     char *tstr = NULL;
@@ -2178,37 +2148,28 @@ static CMD_FUNC(cmd_num_topic)
 
 static CMD_FUNC(cmd_num_gline)
 {
-    time_t lastmod;
     if (argc < 7) {
         if (argc < 6)
             return 0;
-        else {
-            lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
-            gline_add(origin, argv[3], atoi(argv[4])-now, argv[argc - 1], now, lastmod, 0, 0);
-        }
+        else
+            gline_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0, 0);
     } else {
-        if (!strcmp(argv[5], "+")) {
-          lastmod = (argc > 6) ? strtoul(argv[5], NULL, 0) : 0;
-          gline_add(origin, argv[3], atoi(argv[4])-now, argv[argc - 1], now, now, 0, 0);
-        }
+        if (!strcmp(argv[5], "+"))
+          gline_add(origin, argv[3], atoi(argv[4])-now, argv[6], now, 0, 0);
     }
     return 1;
 }
 
 static CMD_FUNC(cmd_num_shun)
 {
-    time_t lastmod;
-
     if (argc < 7) {
         if (argc < 6)
             return 0;
         else
-            lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
-            shun_add(origin, argv[3], atoi(argv[4])-now, argv[argc - 1], now, now, 0);
+            shun_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0);
     } else {
         if (!strcmp(argv[5], "+"))
-            lastmod = (argc > 6) ? strtoul(argv[5], NULL, 0) : 0;
-            shun_add(origin, argv[3], atoi(argv[4])-now, argv[argc - 1], now, now, 0);
+            shun_add(origin, argv[3], atoi(argv[4])-now, argv[6], now, 0);
     }
     return 1;
 }
@@ -2432,15 +2393,12 @@ static CMD_FUNC(cmd_away)
 
 static CMD_FUNC(cmd_gline)
 {
-    time_t lastmod;
-
     if (argc < 3)
         return 0;
     if (argv[2][0] == '+') {
         if (argc < 5)
             return 0;
-        lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
-        gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, lastmod, 0, 0);
+        gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0, 0);
         return 1;
     } else if (argv[2][0] == '-') {
         gline_remove(argv[2]+1, 0);
@@ -2459,7 +2417,7 @@ static CMD_FUNC(cmd_sgline)
     if (!(sender = GetServerH(origin)))
         return 0;
 
-    gline_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, now, 1, 0);
+    gline_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, 1, 0);
     return 1;
 }
 
@@ -2473,21 +2431,18 @@ static CMD_FUNC(cmd_sshun)
     if (!(sender = GetServerH(origin)))
         return 0;
 
-    shun_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, now, 1);
+    shun_add(origin, argv[1], strtoul(argv[2], NULL, 0), argv[argc-1], now, 1);
     return 1;
 }
 
 static CMD_FUNC(cmd_shun)
 {
-    time_t lastmod;
-
     if (argc < 3)
         return 0;
     if (argv[2][0] == '+') {
         if (argc < 5)
             return 0;
-        lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
-        shun_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, now, 0);
+        shun_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0);
         return 1;
     } else if (argv[2][0] == '-') {
         shun_remove(argv[2]+1, 0);
@@ -2520,6 +2475,7 @@ parse_cleanup(void)
 {
     unsigned int nn;
     free(of_list);
+    free(of_list_extra);
     free(privmsg_funcs);
     num_privmsg_funcs = 0;
     free(notice_funcs);
@@ -2705,6 +2661,9 @@ init_parse(void)
     /* ignore ALIST for now */
     dict_insert(irc_func_dict, TOK_ALIST, cmd_dummy);
     dict_insert(irc_func_dict, CMD_ALIST, cmd_dummy);
+    /* ignore SPAMFILTER */
+    dict_insert(irc_func_dict, TOK_SPAMFILTER, cmd_dummy);
+    dict_insert(irc_func_dict, CMD_SPAMFILTER, cmd_dummy);
     /* Ignore remote luser */
     dict_insert(irc_func_dict, TOK_LUSERS, cmd_dummy);
     /* We have reliable clock!  Always!  Wraaa! */
@@ -3025,7 +2984,7 @@ static struct userNode*
 AddUser(struct server* uplink, const char *nick, const char *ident, const char *hostname, const char *modes, const char *numeric, const char *userinfo, time_t timestamp, const char *realip)
 {
     struct userNode *oldUser, *uNode;
-    unsigned int n, ignore_user, dummy;
+    unsigned int ignore_user, dummy;
     char *tstr;
     int type;
 
@@ -3123,8 +3082,8 @@ AddUser(struct server* uplink, const char *nick, const char *ident, const char *
     }
     if (IsLocal(uNode))
         irc_user(uNode);
-    for (n=0; (n<nuf_used) && !uNode->dead; n++)
-        nuf_list[n](uNode);
+    if (!uNode->dead)
+        call_new_user_funcs(uNode);
 
     if ((uNode->loc == 1) && (uNode->handle_info))
         send_func_list(uNode);
@@ -3136,7 +3095,6 @@ AddUser(struct server* uplink, const char *nick, const char *ident, const char *
 void
 DelUser(struct userNode* user, struct userNode *killer, int announce, const char *why)
 {
-    unsigned int n;
 
     verify(user);
 
@@ -3152,8 +3110,7 @@ DelUser(struct userNode* user, struct userNode *killer, int announce, const char
 
     /* Call these in reverse order so ChanServ can update presence
        information before NickServ nukes the handle_info. */
-    for (n = duf_used; n > 0; )
-        duf_list[--n](user, killer, why);
+    call_del_user_funcs(user, killer, why);
 
     user->uplink->clients--;
     user->uplink->users[user->num_local] = NULL;