]> jfr.im git - solanum.git/blobdiff - ircd/send.c
More cleanup
[solanum.git] / ircd / send.c
index 944f329c26d0cd5100eaf109b92ed26d52e5e13c..a733f0497e4a8c4c09875633fce96f9971ecefde 100644 (file)
@@ -20,8 +20,6 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
- *
- *  $Id: send.c 3520 2007-06-30 22:15:35Z jilles $
  */
 
 #include "stdinc.h"
@@ -225,7 +223,7 @@ linebuf_put_msgvbuf(struct MsgBuf *msgbuf, buf_head_t *linebuf, unsigned int cap
        rb_linebuf_newbuf(linebuf);
        msgbuf_unparse_prefix(buf, sizeof buf, msgbuf, capmask);
        rb_linebuf_putprefix(linebuf, pattern, va, buf);
-} 
+}
 
 /* linebuf_put_msgbuf
  *
@@ -261,10 +259,12 @@ build_msgbuf_from(struct MsgBuf *msgbuf, struct Client *from, const char *cmd)
        msgbuf->origin = buf;
        msgbuf->cmd = cmd;
 
-       if (IsPerson(from))
+       if (from != NULL && IsPerson(from))
                snprintf(buf, sizeof buf, "%s!%s@%s", from->name, from->username, from->host);
-       else
+       else if (from != NULL)
                rb_strlcpy(buf, from->name, sizeof buf);
+       else
+               rb_strlcpy(buf, me.name, sizeof buf);
 
        hdata.client = from;
        hdata.arg1 = msgbuf;
@@ -497,7 +497,7 @@ void
 sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                     struct Channel *chptr, const char *pattern, ...)
 {
-       static char buf[BUFSIZE];
+       char buf[IRCD_BUFSIZE];
        va_list args;
        buf_head_t rb_linebuf_local;
        buf_head_t rb_linebuf_id;
@@ -505,25 +505,21 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
        struct membership *msptr;
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
+       int current_capmask = 0;
+       struct MsgBuf msgbuf;
 
        rb_linebuf_newbuf(&rb_linebuf_local);
        rb_linebuf_newbuf(&rb_linebuf_id);
 
        current_serial++;
 
+       build_msgbuf_from(&msgbuf, source_p, NULL);
+
        va_start(args, pattern);
-       vsnprintf(buf, sizeof(buf), pattern, args);
+       vsnprintf(buf, sizeof buf, pattern, args);
        va_end(args);
 
-       if(IsServer(source_p))
-               rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
-                              ":%s %s", source_p->name, buf);
-       else
-               rb_linebuf_putmsg(&rb_linebuf_local, NULL, NULL,
-                              ":%s!%s@%s %s",
-                              source_p->name, source_p->username,
-                              source_p->host, buf);
-
+       linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, NOCAPS, "%s", buf);
        rb_linebuf_putmsg(&rb_linebuf_id, NULL, NULL, ":%s %s", use_id(source_p), buf);
 
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->members.head)
@@ -531,7 +527,10 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                msptr = ptr->data;
                target_p = msptr->client_p;
 
-               if(IsIOError(target_p->from) || target_p->from == one)
+               if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
+                       continue;
+
+               if(MyClient(source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
                        continue;
 
                if(type && ((msptr->flags & type) == 0))
@@ -555,7 +554,20 @@ sendto_channel_flags(struct Client *one, int type, struct Client *source_p,
                        }
                }
                else
+               {
+                       if (target_p->localClient->caps != current_capmask)
+                       {
+                               /* reset the linebuf */
+                               rb_linebuf_donebuf(&rb_linebuf_local);
+                               rb_linebuf_newbuf(&rb_linebuf_local);
+
+                               /* render the new linebuf and attach it */
+                               linebuf_put_msgbuf(&msgbuf, &rb_linebuf_local, target_p->localClient->caps, "%s", buf);
+                               current_capmask = target_p->localClient->caps;
+                       }
+
                        _send_linebuf(target_p, &rb_linebuf_local);
+               }
        }
 
        rb_linebuf_donebuf(&rb_linebuf_local);
@@ -615,7 +627,10 @@ sendto_channel_opmod(struct Client *one, struct Client *source_p,
                msptr = ptr->data;
                target_p = msptr->client_p;
 
-               if(IsIOError(target_p->from) || target_p->from == one)
+               if(!MyClient(source_p) && (IsIOError(target_p->from) || target_p->from == one))
+                       continue;
+
+               if(MyClient(source_p) && !IsCapable(source_p, CLICAP_ECHO_MESSAGE) && target_p == one)
                        continue;
 
                if((msptr->flags & CHFL_CHANOP) == 0)
@@ -786,7 +801,6 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
        struct MsgBuf msgbuf;
        rb_dlink_node *ptr;
        rb_dlink_node *next_ptr;
-       unsigned int current_capmask = 0;
 
        rb_linebuf_newbuf(&linebuf);
 
@@ -794,6 +808,7 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
 
        va_start(args, pattern);
        rb_linebuf_putmsg(&linebuf, pattern, &args, NULL);
+       va_end(args);
 
        RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
        {
@@ -809,23 +824,10 @@ sendto_channel_local_butone(struct Client *one, int type, struct Channel *chptr,
                if(type && ((msptr->flags & type) == 0))
                        continue;
 
-               if (target_p->localClient->caps != current_capmask)
-               {
-                       /* reset the linebuf */
-                       rb_linebuf_donebuf(&linebuf);
-                       rb_linebuf_newbuf(&linebuf);
-
-                       /* render the new linebuf and attach it */
-                       linebuf_put_msgvbuf(&msgbuf, &linebuf, target_p->localClient->caps, pattern, &args);
-                       current_capmask = target_p->localClient->caps;
-               }
-
                /* attach the present linebuf to the target */
                _send_linebuf(target_p, &linebuf);
        }
 
-       va_end(args);
-
        rb_linebuf_donebuf(&linebuf);
 }
 
@@ -1162,6 +1164,8 @@ sendto_anywhere(struct Client *target_p, struct Client *source_p,
        va_list args;
        buf_head_t linebuf;
 
+       rb_linebuf_newbuf(&linebuf);
+
        va_start(args, pattern);
 
        if(MyClient(target_p))