]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kill.c
10 #include "../control/control.h"
11 #include "../localuser/localuser.h" /* killuser() */
12 #include "../lib/irc_string.h" /* IPtostr() */
13 #include "../lib/strlfunc.h"
15 /* used for *_free functions that need to warn users of certain things
16 i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
17 extern nick
*senderNSExtern
;
19 void *kill_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
);
20 void kill_free(searchCtx
*ctx
, struct searchNode
*thenode
);
21 static const char *defaultreason
= "You (%n) have been disconnected for violating our terms of service";
23 struct kill_localdata
{
27 char reason
[NSMAX_REASON_LEN
];
30 struct searchNode
*kill_parse(searchCtx
*ctx
, int type
, int argc
, char **argv
) {
31 struct kill_localdata
*localdata
;
32 struct searchNode
*thenode
;
35 if (!(localdata
= (struct kill_localdata
*) malloc(sizeof(struct kill_localdata
)))) {
36 parseError
= "malloc: could not allocate memory for this search.";
40 localdata
->type
= type
;
41 if (type
== SEARCHTYPE_CHANNEL
)
42 localdata
->marker
= nextchanmarker();
44 localdata
->marker
= nextnickmarker();
50 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
51 if(len
>= sizeof(localdata
->reason
)) {
52 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
54 localdata
->reason
[len
-1] = '\0';
58 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
60 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
61 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
62 parseError
= "malloc: could not allocate memory for this search.";
67 thenode
->returntype
= RETURNTYPE_BOOL
;
68 thenode
->localdata
= localdata
;
69 thenode
->exe
= kill_exe
;
70 thenode
->free
= kill_free
;
75 void *kill_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
76 struct kill_localdata
*localdata
;
80 localdata
= thenode
->localdata
;
82 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
83 cip
= (chanindex
*)theinput
;
84 cip
->marker
= localdata
->marker
;
85 localdata
->count
+= cip
->channel
->users
->totalusers
;
88 np
= (nick
*)theinput
;
89 np
->marker
= localdata
->marker
;
96 void kill_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
97 struct kill_localdata
*localdata
;
101 unsigned int nickmarker
;
104 localdata
= thenode
->localdata
;
106 if (localdata
->count
> NSMAX_KILL_LIMIT
) {
107 /* need to warn the user that they have just tried to twat half the network ... */
108 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
114 /* For channel searches, mark up all the nicks in the relevant channels first */
115 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
116 nickmarker
=nextnickmarker();
117 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
118 for (cip
=chantable
[i
];cip
;cip
=cip
->next
) {
119 /* Skip empty and non-matching channels */
120 if (!cip
->channel
|| cip
->marker
!= localdata
->marker
)
123 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
124 if (cip
->channel
->users
->content
[j
]==nouser
)
127 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
])))
128 np
->marker
=nickmarker
;
133 /* For nick searches they're already marked, pick up the saved value */
134 nickmarker
=localdata
->marker
;
137 /* Now do the actual kills */
138 for (i
=0;i
<NICKHASHSIZE
;i
++) {
139 for (np
=nicktable
[i
];np
;np
=nnp
) {
142 if (np
->marker
!= nickmarker
)
145 if (IsOper(np
) || IsService(np
) || IsXOper(np
)) {
150 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
151 killuser(NULL
, np
, "%s", msgbuf
);
156 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
157 /* notify opers of the action */
158 ctx
->wall(NL_KICKKILLS
, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
159 (localdata
->count
- safe
) != 1 ? "users" : "user", (localdata
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", safe
);