4141#include "s_newconf.h"
4242#include "s_stats.h"
4343#include "tgchange.h"
44+ #include "client_tags.h"
4445#include "inline/stringops.h"
4546
4647static const char message_desc [] =
47- "Provides the PRIVMSG and NOTICE commands to send messages to users and channels" ;
48+ "Provides the PRIVMSG, NOTICE, TAGMSG commands to send messages to users and channels with message-tags support " ;
4849
4950static void m_message (enum message_type , struct MsgBuf * , struct Client * , struct Client * , int , const char * * );
5051static void m_privmsg (struct MsgBuf * , struct Client * , struct Client * , int , const char * * );
5152static void m_notice (struct MsgBuf * , struct Client * , struct Client * , int , const char * * );
53+ static void m_tagmsg (struct MsgBuf * , struct Client * , struct Client * , int , const char * * );
5254static void m_echo (struct MsgBuf * , struct Client * , struct Client * , int , const char * * );
5355
5456static void echo_msg (struct Client * , struct Client * , enum message_type , const char * );
@@ -57,6 +59,14 @@ static void expire_tgchange(void *unused);
5759static struct ev_entry * expire_tgchange_event ;
5860
5961static unsigned int CAP_ECHO ;
62+ static unsigned int CAP_TAGS ;
63+
64+ struct entity
65+ {
66+ void * ptr ;
67+ int type ;
68+ int flags ;
69+ };
6070
6171static int
6272modinit (void )
@@ -80,27 +90,25 @@ struct Message notice_msgtab = {
8090 "NOTICE" , 0 , 0 , 0 , 0 ,
8191 {mg_unreg , {m_notice , 0 }, {m_notice , 0 }, {m_notice , 0 }, mg_ignore , {m_notice , 0 }}
8292};
93+ struct Message tagmsg_msgtab = {
94+ "TAGMSG" , 0 , 0 , 0 , 0 ,
95+ {mg_unreg , {m_tagmsg , 0 }, {m_tagmsg , 0 }, mg_ignore , mg_ignore , {m_tagmsg , 0 }}
96+ };
8397struct Message echo_msgtab = {
8498 "ECHO" , 0 , 0 , 0 , 0 ,
8599 {mg_unreg , mg_ignore , {m_echo , 3 }, mg_ignore , mg_ignore , mg_ignore }
86100};
87101
88- mapi_clist_av1 message_clist [] = { & privmsg_msgtab , & notice_msgtab , & echo_msgtab , NULL };
102+ mapi_clist_av1 message_clist [] = { & privmsg_msgtab , & notice_msgtab , & echo_msgtab , & tagmsg_msgtab , NULL };
89103
90104mapi_cap_list_av2 message_cap_list [] = {
91105 { MAPI_CAP_SERVER , "ECHO" , NULL , & CAP_ECHO },
106+ { MAPI_CAP_SERVER , "TAGS" , NULL , & CAP_TAGS },
92107 { 0 , NULL , NULL , NULL }
93108};
94109
95110DECLARE_MODULE_AV2 (message , modinit , moddeinit , message_clist , NULL , NULL , message_cap_list , NULL , message_desc );
96111
97- struct entity
98- {
99- void * ptr ;
100- int type ;
101- int flags ;
102- };
103-
104112static int build_target_list (enum message_type msgtype ,
105113 struct Client * client_p ,
106114 struct Client * source_p , const char * nicks_channels , const char * text );
@@ -163,6 +171,7 @@ static void handle_special(enum message_type msgtype,
163171const char * cmdname [MESSAGE_TYPE_COUNT ] = {
164172 [MESSAGE_TYPE_PRIVMSG ] = "PRIVMSG" ,
165173 [MESSAGE_TYPE_NOTICE ] = "NOTICE" ,
174+ [MESSAGE_TYPE_TAGMSG ] = "TAGMSG"
166175};
167176
168177static void
@@ -177,6 +186,14 @@ m_notice(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source
177186 m_message (MESSAGE_TYPE_NOTICE , msgbuf_p , client_p , source_p , parc , parv );
178187}
179188
189+
190+ static void
191+ m_tagmsg (struct MsgBuf * msgbuf_p , struct Client * client_p , struct Client * source_p , int parc , const char * parv []) {
192+ // TODO: test if target supports tags, if not, ignore.
193+ m_message (MESSAGE_TYPE_TAGMSG , msgbuf_p , client_p , source_p , parc , parv );
194+ }
195+
196+
180197/*
181198 * inputs - flag privmsg or notice
182199 * - pointer to client_p
@@ -217,6 +234,17 @@ m_message(enum message_type msgtype, struct MsgBuf *msgbuf_p,
217234
218235 for (i = 0 ; i < ntargets ; i ++ )
219236 {
237+ /* Process client tags for each target
238+ */
239+ if (incoming_client != NULL ) {
240+ for (size_t tag_index = 0 ; tag_index < incoming_message -> n_tags ; tag_index ++ ) {
241+ struct MsgTag tag = incoming_message -> tags [tag_index ];
242+ if (!accept_client_tag (tag .key , tag .value , & targets [i ])) {
243+ msgbuf_append_tag (msgbuf_p , tag .key , tag .value , CLICAP_MESSAGE_TAGS );
244+ }
245+ }
246+ }
247+
220248 switch (targets [i ].type )
221249 {
222250 case ENTITY_CHANNEL :
@@ -257,6 +285,7 @@ m_echo(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p
257285 {
258286 case 'P' : msgtype = MESSAGE_TYPE_PRIVMSG ; break ;
259287 case 'N' : msgtype = MESSAGE_TYPE_NOTICE ; break ;
288+ case 'T' : msgtype = MESSAGE_TYPE_TAGMSG ; break ;
260289 default : return ;
261290 }
262291
0 commit comments