]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-notice.c
4 * Use of markers allows us to use notice in both channel and nick searches so we can have newserv notice everyone on a channel and/or
5 * everyone matching a certain nick_search pattern.
13 #include "../control/control.h" /* controlreply() */
14 #include "../lib/irc_string.h" /* IPtostr() */
15 #include "../lib/strlfunc.h"
17 extern nick
*senderNSExtern
;
19 void *notice_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
20 void notice_free(searchCtx
*ctx
, struct searchNode
*thenode
);
22 struct notice_localdata
{
26 char message
[NSMAX_NOTICE_LEN
];
29 struct searchNode
*notice_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
) {
30 struct notice_localdata
*localdata
;
31 struct searchNode
*thenode
;
34 if (!(localdata
= (struct notice_localdata
*) malloc(sizeof(struct notice_localdata
)))) {
35 parseError
= "malloc: could not allocate memory for this search.";
39 localdata
->type
= type
;
40 if (type
== SEARCHTYPE_CHANNEL
)
41 localdata
->marker
= nextchanmarker();
43 localdata
->marker
= nextnickmarker();
49 len
= strlcpy(localdata
->message
, p
, sizeof(localdata
->message
));
50 if(len
>= sizeof(localdata
->message
)) {
51 localdata
->message
[sizeof(localdata
->message
)-1] = '\0';
53 localdata
->message
[len
-1] = '\0';
57 /* no notice to send out ... */
58 parseError
= "Warning: you did not specify a message to notice out.";
63 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
64 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
65 parseError
= "malloc: could not allocate memory for this search.";
70 thenode
->returntype
= RETURNTYPE_BOOL
;
71 thenode
->localdata
= localdata
;
72 thenode
->exe
= notice_exe
;
73 thenode
->free
= notice_free
;
78 void *notice_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
79 struct notice_localdata
*localdata
;
83 localdata
= thenode
->localdata
;
85 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
86 cip
= (chanindex
*)theinput
;
87 cip
->marker
= localdata
->marker
;
88 localdata
->count
+= cip
->channel
->users
->totalusers
;
91 np
= (nick
*)theinput
;
92 np
->marker
= localdata
->marker
;
99 void notice_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
100 struct notice_localdata
*localdata
;
102 chanindex
*cip
, *ncip
;
104 unsigned int nickmarker
;
106 localdata
= thenode
->localdata
;
108 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
109 nickmarker
=nextnickmarker();
110 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
111 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
113 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
114 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
115 if (cip
->channel
->users
->content
[j
]==nouser
)
118 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
])))
119 np
->marker
=nickmarker
;
124 for (i
=0;i
<NICKHASHSIZE
;i
++) {
125 for(np
=nicktable
[i
];np
;np
=nnp
) {
127 if (np
->marker
== nickmarker
)
128 controlnotice(np
, localdata
->message
);
133 for (i
=0;i
<NICKHASHSIZE
;i
++) {
134 for (np
=nicktable
[i
];np
;np
=nnp
) {
136 if (np
->marker
== localdata
->marker
)
137 controlnotice(np
, localdata
->message
);
141 /* notify opers of the action */
142 ctx
->wall(NL_BROADCASTS
, "%s/%s sent the following message to %d %s: %s", senderNSExtern
->nick
, senderNSExtern
->authname
, localdata
->count
, localdata
->count
!= 1 ? "users" : "user", localdata
->message
);