Author: Kev <klmitch@mit.edu>
[ircu2.10.12-pk.git] / ircd / m_settime.c
index 7077690f696337b93af9b9b17e252f2de01fd170..ad6ac3c13757fadf4f11b295d93e88c751b24b1a 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 "client.h"
 #include "hash.h"
 #include "ircd.h"
+#include "ircd_features.h"
 #include "ircd_reply.h"
+#include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "msg.h"
@@ -124,7 +120,7 @@ int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     return need_more_params(sptr, "SETTIME");
 
   if (parc == 2 && MyUser(sptr))
-    parv[parc++] = me.name;
+    parv[parc++] = cli_name(&me);
 
   t = atoi(parv[1]);
   dt = TStime() - t;
@@ -137,45 +133,45 @@ int ms_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   if (IsServer(sptr))           /* send to unlagged servers */
   {
-#ifdef RELIABLE_CLOCK
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
-    parv[1] = tbuf;
-#endif
-    for (lp = me.serv->down; lp; lp = lp->next)
-      if (cptr != lp->value.cptr && MsgQLength(&lp->value.cptr->sendQ) < 8000)
+    if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+      ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
+      parv[1] = tbuf;
+    }
+
+    for (lp = cli_serv(&me)->down; lp; lp = lp->next)
+      if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
        sendcmdto_one(sptr, CMD_NOTICE, lp->value.cptr, "%s", parv[1]);
   }
   else
   {
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
+    ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
     parv[1] = tbuf;
-    if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
-        HUNTED_ISME)
+    if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
+                            parv) != HUNTED_ISME)
       return 0;
   }
 
-#ifdef RELIABLE_CLOCK
-  if ((dt > 600) || (dt < -600))
-    sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
-                         sptr->name, t);
-  if (IsUser(sptr))
-  {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds %s "
-                 ": RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
-                 (dt < 0) ? "forwards" : "backwards");
-  }
-#else
-  sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
-                      "seconds %s", sptr->name, (dt < 0) ? -dt : dt,
-                      (dt < 0) ? "forwards" : "backwards");
-  TSoffset -= dt;
-  if (IsUser(sptr))
-  {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
-                 sptr, (dt < 0) ? -dt : dt,
-                 (dt < 0) ? "forwards" : "backwards");
+  if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+    if ((dt > 600) || (dt < -600))
+      sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
+                           cli_name(sptr), t);
+    if (IsUser(sptr)) {
+      sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
+                   "seconds %s : RELIABLE_CLOCK is defined", sptr,
+                   (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
+    }
+  } else {
+    sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
+                        "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
+                        (dt < 0) ? "forwards" : "backwards");
+    TSoffset -= dt;
+    if (IsUser(sptr)) {
+      sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
+                   sptr, (dt < 0) ? -dt : dt,
+                   (dt < 0) ? "forwards" : "backwards");
+    }
   }
-#endif
+
   return 0;
 }
 
@@ -200,7 +196,7 @@ int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
     return need_more_params(sptr, "SETTIME");
 
   if (parc == 2 && MyUser(sptr))
-    parv[parc++] = me.name;
+    parv[parc++] = cli_name(&me);
 
   t = atoi(parv[1]);
   dt = TStime() - t;
@@ -213,132 +209,44 @@ int mo_settime(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
 
   if (IsServer(sptr))           /* send to unlagged servers */
   {
-#ifdef RELIABLE_CLOCK
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
-    parv[1] = tbuf;
-#endif
-    for (lp = me.serv->down; lp; lp = lp->next)
-      if (cptr != lp->value.cptr && MsgQLength(&lp->value.cptr->sendQ) < 8000)
-       sendcmdto_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
+    if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+      ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
+      parv[1] = tbuf;
+    }
+
+    for (lp = cli_serv(&me)->down; lp; lp = lp->next)
+      if (cptr != lp->value.cptr && MsgQLength(&(cli_sendQ(lp->value.cptr))) < 8000)
+       sendcmdto_prio_one(sptr, CMD_SETTIME, lp->value.cptr, "%s", parv[1]);
   }
   else
   {
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
+    ircd_snprintf(0, tbuf, sizeof(tbuf), "%Tu", TStime());
     parv[1] = tbuf;
-    if (hunt_server_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc, parv) !=
-        HUNTED_ISME)
+    if (hunt_server_prio_cmd(sptr, CMD_SETTIME, cptr, 1, "%s %C", 2, parc,
+                            parv) != HUNTED_ISME)
       return 0;
   }
 
-#ifdef RELIABLE_CLOCK
-  if ((dt > 600) || (dt < -600))
-    sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
-                         sptr->name, t);
-  if (IsUser(sptr))
-  {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld seconds %s "
-                 ": RELIABLE_CLOCK is defined", sptr, (dt < 0) ? -dt : dt,
-                 (dt < 0) ? "forwards" : "backwards");
+  if (feature_bool(FEAT_RELIABLE_CLOCK)) {
+    if ((dt > 600) || (dt < -600))
+      sendcmdto_serv_butone(&me, CMD_WALLOPS, 0, ":Bad SETTIME from %s: %Tu",
+                           cli_name(sptr), t);
+    if (IsUser(sptr)) {
+      sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is not set %ld "
+                   "seconds %s : RELIABLE_CLOCK is defined", sptr,
+                   (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
+    }
+  } else {
+    sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
+                        "seconds %s", cli_name(sptr), (dt < 0) ? -dt : dt,
+                        (dt < 0) ? "forwards" : "backwards");
+    TSoffset -= dt;
+    if (IsUser(sptr)) {
+      sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
+                   sptr, (dt < 0) ? -dt : dt,
+                   (dt < 0) ? "forwards" : "backwards");
+    }
   }
-#else
-  sendto_opmask_butone(0, SNO_OLDSNO, "SETTIME from %s, clock is set %ld "
-                      "seconds %s", sptr->name, (dt < 0) ? -dt : dt,
-                      (dt < 0) ? "forwards" : "backwards");
-  TSoffset -= dt;
-  if (IsUser(sptr))
-  {
-    sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :clock is set %ld seconds %s",
-                 sptr, (dt < 0) ? -dt : dt,
-                 (dt < 0) ? "forwards" : "backwards");
-  }
-#endif
-  return 0;
-}
 
-  
-#if 0
-/*
- * m_settime
- *
- * parv[0] = sender prefix
- * parv[1] = new time
- * parv[2] = servername (Only used when sptr is an Oper).
- */
-int m_settime(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
-{
-  time_t t;
-  long int dt;
-  static char tbuf[11];
-  struct DLink *lp;
-
-  if (!IsPrivileged(sptr))
-    return 0;
-
-  if (parc < 2)
-    return need_more_params(sptr, "SETTIME");
-
-  if (parc == 2 && MyUser(sptr))
-    parv[parc++] = me.name;
-
-  t = atoi(parv[1]);
-  dt = TStime() - t;
-
-  if (t < OLDEST_TS || dt < -9000000)
-  {
-    sendto_one(sptr, ":%s NOTICE %s :SETTIME: Bad value", me.name, parv[0]); /* XXX DEAD */
-    return 0;
-  }
-
-  if (IsServer(sptr))           /* send to unlagged servers */
-  {
-#ifdef RELIABLE_CLOCK
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
-    parv[1] = tbuf;
-#endif
-    for (lp = me.serv->down; lp; lp = lp->next)
-      if (cptr != lp->value.cptr && DBufLength(&lp->value.cptr->sendQ) < 8000) /* XXX DEAD */
-        sendto_one(lp->value.cptr, ":%s SETTIME %s", parv[0], parv[1]); /* XXX DEAD */
-  }
-  else
-  {
-    sprintf_irc(tbuf, TIME_T_FMT, TStime());
-    parv[1] = tbuf;
-    if (hunt_server(1, cptr, sptr, "%s%s " TOK_SETTIME " %s %s", 2, parc, parv) != /* XXX DEAD */
-        HUNTED_ISME)
-      return 0;
-  }
-
-#ifdef RELIABLE_CLOCK
-  if ((dt > 600) || (dt < -600))
-    sendto_serv_butone(0, ":%s " TOK_WALLOPS " :Bad SETTIME from %s: " TIME_T_FMT, /* XXX DEAD */
-                       me.name, sptr->name, t);
-  if (IsUser(sptr))
-  {
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      sendto_one(sptr, ":%s NOTICE %s :clock is not set %ld seconds %s : " /* XXX DEAD */
-                 "RELIABLE_CLOCK is defined", me.name, parv[0],
-                 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
-    else
-      sendto_one(sptr, "%s NOTICE %s%s :clock is not set %ld seconds %s : " /* XXX DEAD */
-                 "RELIABLE_CLOCK is defined", NumServ(&me), NumNick(sptr),
-                 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
-  }
-#else
-  sendto_ops("SETTIME from %s, clock is set %ld seconds %s", /* XXX DEAD */
-             sptr->name, (dt < 0) ? -dt : dt,
-             (dt < 0) ? "forwards" : "backwards");
-  TSoffset -= dt;
-  if (IsUser(sptr))
-  {
-    if (MyUser(sptr) || Protocol(cptr) < 10)
-      sendto_one(sptr, ":%s NOTICE %s :clock is set %ld seconds %s", me.name, /* XXX DEAD */
-                 parv[0], (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
-    else
-      sendto_one(sptr, "%s NOTICE %s%s :clock is set %ld seconds %s", /* XXX DEAD */
-                 NumServ(&me), NumNick(sptr),
-                 (dt < 0) ? -dt : dt, (dt < 0) ? "forwards" : "backwards");
-  }
-#endif
   return 0;
 }
-#endif /* 0 */