Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / send.c
index 72487d295f21035255f1818b65fba1a994541396..b7014d70eb306b3ac90c7c83da089a79c5b7f91f 100644 (file)
@@ -19,6 +19,8 @@
  *
  * $Id$
  */
+#include "config.h"
+
 #include "send.h"
 #include "channel.h"
 #include "class.h"
@@ -34,7 +36,6 @@
 #include "s_debug.h"
 #include "s_misc.h"
 #include "s_user.h"
-#include "sprintf_irc.h"
 #include "struct.h"
 #include "sys.h"
 
@@ -111,7 +112,7 @@ void flush_connections(struct Client* cptr)
   else {
     struct Connection* con;
     for (con = send_queues; con; con = con_next(con)) {
-      assert(0 > MsgQLength(&(con_sendQ(con))));
+      assert(0 < MsgQLength(&(con_sendQ(con))));
       send_queued(con_client(con));
     }
   }
@@ -138,8 +139,10 @@ void send_queued(struct Client *to)
     if ((len = deliver_it(to, &(cli_sendQ(to))))) {
       msgq_delete(&(cli_sendQ(to)), len);
       cli_lastsq(to) = MsgQLength(&(cli_sendQ(to))) / 1024;
-      if (IsBlocked(to))
+      if (IsBlocked(to)) {
+       update_write(to);
         return;
+      }
     }
     else {
       if (IsDead(to)) {
@@ -153,6 +156,7 @@ void send_queued(struct Client *to)
 
   /* Ok, sendq is now empty... */
   client_drop_sendq(cli_connect(to));
+  update_write(to);
 }
 
 void send_buffer(struct Client* to, struct MsgBuf* buf, int prio)
@@ -182,6 +186,7 @@ void send_buffer(struct Client* to, struct MsgBuf* buf, int prio)
 
   msgq_add(&(cli_sendQ(to)), buf, prio);
   client_add_sendq(cli_connect(to), &send_queues);
+  update_write(to);
 
   /*
    * Update statistics. The following is slightly incorrect
@@ -247,15 +252,31 @@ void sendrawto_one(struct Client *to, const char *pattern, ...)
 void sendcmdto_one(struct Client *from, const char *cmd, const char *tok,
                   struct Client *to, const char *pattern, ...)
 {
-  va_list vl;
+  struct VarData vd;
+  struct MsgBuf *mb;
 
-  va_start(vl, pattern);
-  vsendcmdto_one(from, cmd, tok, to, pattern, vl);
-  va_end(vl);
+  to = cli_from(to);
+
+  vd.vd_format = pattern; /* set up the struct VarData for %v */
+  va_start(vd.vd_args, pattern);
+
+  mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd,
+                &vd);
+
+  va_end(vd.vd_args);
+
+  send_buffer(to, mb, 0);
+
+  msgq_clean(mb);
 }
 
-void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok,
-                   struct Client *to, const char *pattern, va_list vl)
+/*
+ * Send a (prefixed) command to a single client in the priority queue;
+ * select  which of <cmd> <tok> to use depending on if to is a server
+ *or not.  <from> is the originator of the command.
+ */
+void sendcmdto_prio_one(struct Client *from, const char *cmd, const char *tok,
+                       struct Client *to, const char *pattern, ...)
 {
   struct VarData vd;
   struct MsgBuf *mb;
@@ -263,12 +284,14 @@ void vsendcmdto_one(struct Client *from, const char *cmd, const char *tok,
   to = cli_from(to);
 
   vd.vd_format = pattern; /* set up the struct VarData for %v */
-  vd.vd_args = vl;
+  va_start(vd.vd_args, pattern);
 
   mb = msgq_make(to, "%:#C %s %v", from, IsServer(to) || IsMe(to) ? tok : cmd,
                 &vd);
 
-  send_buffer(to, mb, 0);
+  va_end(vd.vd_args);
+
+  send_buffer(to, mb, 1);
 
   msgq_clean(mb);
 }
@@ -456,54 +479,52 @@ void sendcmdto_channel_butone(struct Client *from, const char *cmd,
  * Send a (prefixed) command to all users except <one> that have
  * <flag> set.
  */
-/* XXX sentalong_marker used XXX
- *
- * Again, we can solve this use of sentalong_marker by adding a field
- * to connections--a count of the number of +w users, and another count
- * of +g users.  Then, just walk through the local clients to send
- * those messages, and another walk through the connected servers list,
- * sending only if there's a non-zero count.  No caveats here, either,
- * beyond remembering to decrement the count when a user /quit's or is
- * killed, or a server is squit. -Kev
- */
 void sendcmdto_flag_butone(struct Client *from, const char *cmd,
                           const char *tok, struct Client *one,
                           unsigned int flag, const char *pattern, ...)
 {
   struct VarData vd;
   struct Client *cptr;
-  struct MsgBuf *user_mb;
-  struct MsgBuf *serv_mb;
+  struct MsgBuf *mb;
+  struct DLink *lp;
+  unsigned int oper_fl = 0;
+  int i;
+
+  if (flag & FLAGS_OPER) {
+    flag &= ~FLAGS_OPER;
+    oper_fl++;
+  }
 
   vd.vd_format = pattern;
 
   /* Build buffer to send to users */
   va_start(vd.vd_args, pattern);
-  user_mb = msgq_make(0, "%:#C " MSG_WALLOPS " %v", from, &vd);
+  mb = msgq_make(0, "%:#C " MSG_WALLOPS " %v", from, &vd);
   va_end(vd.vd_args);
 
+  /* send buffer along! */
+  for (i = 0; i <= HighestFd; i++) {
+    if (!(cptr = LocalClientArray[i]) || !(cli_flags(cptr) & flag) ||
+       (oper_fl && !IsAnOper(cptr)) || cli_fd(cli_from(cptr)) < 0)
+      continue; /* skip it */
+    send_buffer(cptr, mb, 1);
+  }
+
+  msgq_clean(mb);
+
   /* Build buffer to send to servers */
   va_start(vd.vd_args, pattern);
-  serv_mb = msgq_make(&me, "%C %s %v", from, tok, &vd);
+  mb = msgq_make(&me, "%C %s %v", from, tok, &vd);
   va_end(vd.vd_args);
 
   /* send buffer along! */
-  sentalong_marker++;
-  for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) {
-    if (cli_from(cptr) == one || IsServer(cptr) || !(cli_flags(cptr) & flag) ||
-       cli_fd(cli_from(cptr)) < 0 ||
-       sentalong[cli_fd(cli_from(cptr))] == sentalong_marker)
-      continue; /* skip it */
-    sentalong[cli_fd(cli_from(cptr))] = sentalong_marker;
-
-    if (MyConnect(cptr)) /* send right buffer */
-      send_buffer(cptr, user_mb, 1);
-    else
-      send_buffer(cptr, serv_mb, 1);
+  for (lp = cli_serv(&me)->down; lp; lp = lp->next) {
+    if (one && lp->value.cptr == cli_from(one))
+      continue;
+    send_buffer(lp->value.cptr, mb, 1);
   }
 
-  msgq_clean(user_mb);
-  msgq_clean(serv_mb);
+  msgq_clean(mb);
 }
 
 /*
@@ -549,8 +570,8 @@ void sendcmdto_match_butone(struct Client *from, const char *cmd,
   /* send buffer along */
   sentalong_marker++;
   for (cptr = GlobalClientList; cptr; cptr = cli_next(cptr)) {
-    if (cli_from(cptr) == one || IsServer(cptr) || IsMe(cptr) ||
-       !match_it(cptr, to, who) || cli_fd(cli_from(cptr)) < 0 ||
+    if (!IsRegistered(cptr) || cli_from(cptr) == one || IsServer(cptr) ||
+       IsMe(cptr) || !match_it(cptr, to, who) || cli_fd(cli_from(cptr)) < 0 ||
        sentalong[cli_fd(cli_from(cptr))] == sentalong_marker)
       continue; /* skip it */
     sentalong[cli_fd(cli_from(cptr))] = sentalong_marker;
@@ -579,6 +600,27 @@ void sendto_opmask_butone(struct Client *one, unsigned int mask,
   va_end(vl);
 }
 
+/*
+ * Send a server notice to all users subscribing to the indicated <mask>
+ * except for <one> - Ratelimited 1 / 30sec
+ */
+void sendto_opmask_butone_ratelimited(struct Client *one, unsigned int mask,
+                         time_t *rate, const char *pattern, ...)
+{
+  va_list vl;
+
+  if ((CurrentTime - *rate) < 30) 
+    return;
+  else 
+    *rate = CurrentTime;
+
+  va_start(vl, pattern);
+  vsendto_opmask_butone(one, mask, pattern, vl);
+  va_end(vl);
+    
+}
+
+
 /*
  * Same as above, except called with a variable argument list
  */