Fix typos in various comments.
[ircu2.10.12-pk.git] / ircd / m_create.c
index c3d537bf9a6c8058c36d6b04440fc4901ace6a45..da94f5e51c3683dbeb67a0f8c418072cb02f34e7 100644 (file)
  *            note:   it is guaranteed that parv[0]..parv[parc-1] are all
  *                    non-NULL pointers.
  */
-#if 0
-/*
- * No need to include handlers.h here the signatures must match
- * and we don't need to force a rebuild of all the handlers everytime
- * we add a new one to the list. --Bleep
- */
-#include "handlers.h"
-#endif /* 0 */
+#include "config.h"
+
 #include "channel.h"
 #include "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_log.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
 #include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
 #include "s_debug.h"
+#include "s_misc.h"
+#include "s_user.h"
 #include "send.h"
 
-#include <assert.h>
+/* #include <assert.h> -- Now using assert in ircd_log.h */
 #include <stdlib.h>
 #include <string.h>
 
@@ -117,28 +114,42 @@ int ms_create(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
   struct ModeBuf mbuf; /* a mode buffer */
   int badop; /* a flag */
 
-  if (IsServer(sptr)) {
-    Debug((DEBUG_ERROR, "%s tried to CREATE a channel", sptr->name));
-    return 0;
-  }
+  if (IsServer(sptr))
+    return protocol_violation(sptr,"%s tried to CREATE a channel", cli_name(sptr));
 
   /* sanity checks: Only accept CREATE messages from servers */
-  if (!IsServer(cptr) || parc < 3 || *parv[2] == '\0')
-    return 0;
+  if (parc < 3 || *parv[2] == '\0')
+    return need_more_params(sptr,"CREATE");
 
   chanTS = atoi(parv[2]);
 
-  joinbuf_init(&join, sptr, cptr, JOINBUF_TYPE_JOIN, 0, 0);
-  joinbuf_init(&create, sptr, cptr, JOINBUF_TYPE_CREATE, 0, chanTS);
-
   /* A create that didn't appear during a burst has that servers idea of
    * the current time.  Use it for lag calculations.
    */
   if (!IsBurstOrBurstAck(sptr) && 0 != chanTS &&
       MAGIC_REMOTE_JOIN_TS != chanTS)
-    sptr->user->server->serv->lag = TStime() - chanTS;
+    cli_serv(cli_user(sptr)->server)->lag = TStime() - chanTS;
+
+  /* If this server is >1 minute fast, warn */
+  if (TStime() - chanTS<-60)
+  {
+    static time_t rate;
+    sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
+                                     "Timestamp drift from %C (%is); issuing "
+                                     "SETTIME to correct this",
+                                    cli_user(sptr)->server,
+                                    chanTS - TStime());
+    /* Now issue a SETTIME to resync.  If we're in the wrong, our
+     * (RELIABLE_CLOCK) hub will bounce a SETTIME back to us.
+     */
+    sendcmdto_prio_one(&me, CMD_SETTIME, cli_user(sptr)->server,
+                       "%Tu %C", TStime(), cli_user(sptr)->server);
+  }
+
+  joinbuf_init(&join, sptr, cptr, JOINBUF_TYPE_JOIN, 0, 0);
+  joinbuf_init(&create, sptr, cptr, JOINBUF_TYPE_CREATE, 0, chanTS);
 
-  /* For each channel in the comma seperated list: */
+  /* For each channel in the comma separated list: */
   for (name = ircd_strtok(&p, parv[1], ","); name;
        name = ircd_strtok(&p, 0, ",")) {
     badop = 0;
@@ -146,8 +157,13 @@ int ms_create(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     if (IsLocalChannel(name))
       continue;
 
-    if ((chptr = FindChannel(name))) {
-      name = chptr->chname;
+    if ((chptr = FindChannel(name)))
+    {
+      /* Is the remote server confused? */
+      if (find_member_link(chptr, sptr)) {
+        protocol_violation(sptr, "%s tried to CREATE a channel already joined", cli_name(sptr));
+        continue;
+      }
 
       /* Check if we need to bounce a mode */
       if (TStime() - chanTS > TS_LAG_TIME ||
@@ -164,15 +180,15 @@ int ms_create(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
        badop = 1;
       }
-    } else                        /* Channel doesn't exist: create it */
+    }
+    else /* Channel doesn't exist: create it */
       chptr = get_channel(sptr, name, CGT_CREATE);
 
     if (!badop) /* Set/correct TS */
       chptr->creationtime = chanTS;
 
     joinbuf_join(badop ? &join : &create, chptr,
-                (badop || IsModelessChannel(name)) ?
-                CHFL_DEOPPED : CHFL_CHANOP);
+                (badop ? 0 : CHFL_CHANOP));
   }
 
   joinbuf_flush(&join); /* flush out the joins and creates */