Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / parse.c
index 7fb9571954dc73335d728507b2639c0a07c60229..152ef99d02797fbee893434da702cd837a4e1aa5 100644 (file)
@@ -27,6 +27,7 @@
 #include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_chattr.h"
+#include "ircd_features.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "msg.h"
@@ -353,11 +354,7 @@ struct Message msgtab[] = {
     TOK_OPER,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-#ifndef NOOPER    
     { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
-#else
-    { m_unregistered, m_oper, m_ignore, m_ignore, m_ignore }
-#endif
   },
   {
     MSG_CONNECT,
@@ -448,11 +445,7 @@ struct Message msgtab[] = {
     TOK_JUPE,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-#ifdef CONFIG_OPERCMDS
     { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
-#else
-    { m_unregistered, m_jupe, ms_jupe, m_jupe, m_ignore }
-#endif /* CONFIG_OPERCMDS */
   },
   {
     MSG_OPMODE,
@@ -531,6 +524,34 @@ struct Message msgtab[] = {
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
     { m_proto, m_proto, m_proto, m_proto, m_ignore }
   },
+  {
+    MSG_SET,
+    TOK_SET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_set, m_ignore }
+  },
+  {
+    MSG_RESET,
+    TOK_RESET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_reset, m_ignore }
+  },
+  {
+    MSG_GET,
+    TOK_GET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_get, m_ignore }
+  },
+  {
+    MSG_PRIVS,
+    TOK_PRIVS,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
+  },
   /* This command is an alias for QUIT during the unregistered part of
    * of the server.  This is because someone jumping via a broken web
    * proxy will send a 'POST' as their first command - which we will
@@ -548,10 +569,6 @@ struct Message msgtab[] = {
 }; 
 
 
-#ifdef GODMODE
-extern int sdbflag;
-#endif /* GODMODE */
-
 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
 
 /*
@@ -786,7 +803,7 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   if (IsDead(cptr))
     return 0;
 
-  para[0] = from->name;
+  para[0] = cli_name(from);
   for (ch = buffer; *ch == ' '; ch++);  /* Eat leading spaces */
   if (*ch == ':')               /* Is any client doing this ? */
   {
@@ -801,7 +818,7 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   {
     ServerStats->is_empt++;
     Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
-        cptr->name, from->name));
+        cli_name(cptr), cli_name(from)));
     return (-1);
   }
 
@@ -840,7 +857,7 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   i = bufend - ((s) ? s : ch);
   mptr->bytes += i;
   if ((mptr->flags & MFLG_SLOW))
-    cptr->since += (2 + i / 120);
+    cli_since(cptr) += (2 + i / 120);
   /*
    * Allow only 1 msg per 2 seconds
    * (on average) to prevent dumping.
@@ -892,25 +909,13 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   }
   para[++i] = NULL;
   ++mptr->count;
-#if 0
-  /*
-   * The "unregistered command check" was ugly and mildly inefficient.
-   * I fixed it. :)  --Shadow
-   */
-  if (!IsUser(cptr) && 0 == (mptr->flags & MFLG_UNREG)) {
-    if (0 == (mptr->flags & MFLG_IGNORE))
-      sendto_one(from, ":%s %d * %s :Register first.", /* XXX DEAD */
-                 me.name, ERR_NOTREGISTERED, ch);
-    return -1;
-  }
-#endif
-  handler = mptr->handlers[cptr->handler];
+
+  handler = mptr->handlers[cli_handler(cptr)];
   assert(0 != handler);
 
-#ifndef IDLE_FROM_MSG
-  if (IsUser(cptr) && handler != m_ping && handler != m_ignore)
-    from->user->last = CurrentTime;
-#endif
+  if (!feature_bool(FEAT_IDLE_FROM_MSG) && IsUser(cptr) &&
+      handler != m_ping && handler != m_ignore)
+    cli_user(from)->last = CurrentTime;
 
   return (*handler) (cptr, from, i, para);
 }
@@ -928,26 +933,10 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
 
   Debug((DEBUG_DEBUG, "Server Parsing: %s", buffer));
 
-#ifdef GODMODE
-  len = strlen(buffer);
-  sdbflag = 1;
-  if (len > 402)
-  {
-    char c = buffer[200];
-    buffer[200] = 0;
-    sendto_ops("RCV:%-8.8s(%.4d): \"%s...%s\"",
-        cptr->name, len, buffer, &buffer[len - 200]);
-    buffer[200] = c;
-  }
-  else
-    sendto_ops("RCV:%-8.8s(%.4d): \"%s\"", cptr->name, len, buffer);
-  sdbflag = 0;
-#endif /* GODMODE */
-
   if (IsDead(cptr))
     return 0;
 
-  para[0] = from->name;
+  para[0] = cli_name(from);
 
   /*
    * A server ALWAYS sends a prefix. When it starts with a ':' it's the
@@ -976,7 +965,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     if (!from)
     {
       Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
-          para[0], buffer, cptr->name));
+          para[0], buffer, cli_name(cptr)));
       ++ServerStats->is_unpf;
       while (*ch == ' ')
         ch++;
@@ -988,22 +977,21 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
        */
       if (ch[1] == 'Q')
       {
-        para[0] = cptr->name;
+        para[0] = cli_name(cptr);
         from = cptr;
       }
       else
         return 0;
     }
-    else if (from->from != cptr)
+    else if (cli_from(from) != cptr)
     {
       ++ServerStats->is_wrdi;
       Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
-          buffer, cptr->name));
+          buffer, cli_name(cptr)));
       return 0;
     }
   }
-  else if (Protocol(cptr) > 9)  /* Well, not ALWAYS, 2.9 can send no prefix */
-  {
+  else {
     char numeric_prefix[6];
     int  i;
     for (i = 0; i < 5; ++i) {
@@ -1012,12 +1000,17 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
       }
     }
     numeric_prefix[i] = '\0';
+
     /*
      * We got a numeric nick as prefix
      * 1 or 2 character prefixes are from servers
      * 3 or 5 chars are from clients
      */
-    if (' ' == ch[1] || ' ' == ch[2])
+    if (0 == i) {
+      protocol_violation(cptr,"Missing Prefix");
+      from = cptr;
+    }
+    else if (' ' == ch[1] || ' ' == ch[2])
       from = FindNServer(numeric_prefix);
     else 
       from = findNUser(numeric_prefix);
@@ -1051,9 +1044,9 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
         struct Client *server;
         /* Kill the unknown numeric prefix upstream if
          * it's server still exists: */
-        if ((server = FindNServer(numeric_prefix)) && server->from == cptr)
+        if ((server = FindNServer(numeric_prefix)) && cli_from(server) == cptr)
          sendcmdto_one(&me, CMD_KILL, cptr, "%s :%s (Unknown numeric nick)",
-                       numeric_prefix, me.name);
+                       numeric_prefix, cli_name(&me));
       }
       /*
        * Things that must be allowed to travel
@@ -1067,13 +1060,13 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     }
 
     /* Let para[0] point to the name of the sender */
-    para[0] = from->name;
+    para[0] = cli_name(from);
 
-    if (from->from != cptr)
+    if (cli_from(from) != cptr)
     {
       ServerStats->is_wrdi++;
       Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
-          buffer, cptr->name));
+          buffer, cli_name(cptr)));
       return 0;
     }
   }
@@ -1084,7 +1077,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
   {
     ServerStats->is_empt++;
     Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
-        cptr->name, from->name));
+        cli_name(cptr), cli_name(from)));
     return (-1);
   }
 
@@ -1212,5 +1205,5 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
   mptr->count++;
 
-  return (*mptr->handlers[cptr->handler]) (cptr, from, i, para);
+  return (*mptr->handlers[cli_handler(cptr)]) (cptr, from, i, para);
 }