Author: Kev <klmitch@undernet.org>
[ircu2.10.12-pk.git] / ircd / send.c
index aaf952f3cb0774e94c2d818e50e3ad1113f4dbc0..5bdd1048c58e010a078fbf4a9a104478489e76a4 100644 (file)
@@ -24,6 +24,7 @@
 #include "class.h"
 #include "client.h"
 #include "ircd.h"
+#include "ircd_snprintf.h"
 #include "ircd_string.h"
 #include "list.h"
 #include "match.h"
@@ -190,6 +191,40 @@ void vsendto_one(struct Client *to, const char* pattern, va_list vl)
   sendbufto_one(to);
 }
 
+/*
+ * Send a (prefixed) command to a single client; 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_one(struct Client *to, const char *cmd, const char *tok,
+                  struct Client *from, const char *pattern, ...)
+{
+  va_list vl;
+
+  va_start(vl, pattern);
+  vsendcmdto_one(to, cmd, tok, from, pattern, vl);
+  va_end(vl);
+}
+
+void vsendcmdto_one(struct Client *to, const char *cmd, const char *tok,
+                   struct Client *from, const char *pattern, va_list vl)
+{
+  struct VarData vd;
+  char sndbuf[IRC_BUFSIZE];
+
+  vd.vd_format = pattern; /* set up the struct VarData for %v */
+  vd.vd_args = vl;
+
+  if (MyUser(to)) /* :nick!user@host form; use cmd */
+    ircd_snprintf(to, sndbuf, sizeof(sndbuf) - 2, ":%s!%s@%s %s %v",
+                 from->name, from->user->username, from->user->host,
+                 cmd, &vd);
+  else /* numeric form; use tok */
+    ircd_snprintf(to, sndbuf, sizeof(sndbuf) - 2, "%C %s %v", from, tok, &vd);
+
+  send_buffer(to, sndbuf);
+}
+
 #ifdef GODMODE
 static void send_to_god(struct Client* to, const char* buf)
 {
@@ -561,6 +596,33 @@ void sendto_serv_butone(struct Client *one, const char* pattern, ...)
 
 }
 
+void sendcmdto_serv_butone(struct Client *one, const char *cmd,
+                          const char *tok, struct Client *from,
+                          const char *pattern, ...)
+{
+  struct VarData vd;
+  va_list vl;
+  char sndbuf[IRC_BUFSIZE];
+  struct DLink *lp;
+
+  cmd = 0; /* try to suppress compile warning */
+
+  va_start(vl, pattern);
+  vd.vd_format = pattern; /* set up the struct VarData for %v */
+  vd.vd_args = vl;
+
+  /* use token */
+  ircd_snprintf(&me, sndbuf, sizeof(sndbuf) - 2, "%C %s %v", from, tok, &vd);
+  va_end(vl);
+
+  /* send it to our downlinks */
+  for (lp = me.serv->down; lp; lp = lp->next) {
+    if (one && lp->value.cptr == one->from)
+      continue;
+    send_buffer(lp->value.cptr, sndbuf);
+  }
+}
+
 /*
  * sendbufto_serv_butone()
  *