]>
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
{
25 char message
[NSMAX_NOTICE_LEN
];
28 struct searchNode
*notice_parse(searchCtx
*ctx
, int argc
, char **argv
) {
29 struct notice_localdata
*localdata
;
30 struct searchNode
*thenode
, *message
;
33 if (!(localdata
= (struct notice_localdata
*) malloc(sizeof(struct notice_localdata
)))) {
34 parseError
= "malloc: could not allocate memory for this search.";
38 if (ctx
->searchcmd
== reg_chansearch
)
39 localdata
->marker
= nextchanmarker();
40 else if (ctx
->searchcmd
== reg_nicksearch
)
41 localdata
->marker
= nextnickmarker();
44 parseError
= "notice: invalid search type";
48 parseError
= "notice: warning: you did not specify a message to notice out.";
53 if (!(message
=argtoconststr("notice", ctx
, argv
[0], &p
))) {
58 strlcpy(localdata
->message
, p
, sizeof(localdata
->message
));
59 (message
->free
)(ctx
, message
);
61 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
62 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
63 parseError
= "malloc: could not allocate memory for this search.";
68 thenode
->returntype
= RETURNTYPE_BOOL
;
69 thenode
->localdata
= localdata
;
70 thenode
->exe
= notice_exe
;
71 thenode
->free
= notice_free
;
76 void *notice_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
77 struct notice_localdata
*localdata
;
81 localdata
= thenode
->localdata
;
83 if (ctx
->searchcmd
== reg_chansearch
) {
84 cip
= (chanindex
*)theinput
;
85 cip
->marker
= localdata
->marker
;
86 localdata
->count
+= cip
->channel
->users
->totalusers
;
89 np
= (nick
*)theinput
;
90 np
->marker
= localdata
->marker
;
97 void notice_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
98 struct notice_localdata
*localdata
;
100 chanindex
*cip
, *ncip
;
102 unsigned int nickmarker
;
104 localdata
= thenode
->localdata
;
106 if (ctx
->searchcmd
== reg_chansearch
) {
107 nickmarker
=nextnickmarker();
108 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
109 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
111 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
112 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
113 if (cip
->channel
->users
->content
[j
]==nouser
)
116 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
])))
117 np
->marker
=nickmarker
;
122 for (i
=0;i
<NICKHASHSIZE
;i
++) {
123 for(np
=nicktable
[i
];np
;np
=nnp
) {
125 if (np
->marker
== nickmarker
)
126 controlnotice(np
, "%s", localdata
->message
);
131 for (i
=0;i
<NICKHASHSIZE
;i
++) {
132 for (np
=nicktable
[i
];np
;np
=nnp
) {
134 if (np
->marker
== localdata
->marker
)
135 controlnotice(np
, "%s", localdata
->message
);
139 /* notify opers of the action */
140 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
);