]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kill.c
6f8b474c73b832b89e6462a7b6bb3171b8cf7bee
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
{
26 char reason
[NSMAX_REASON_LEN
];
29 struct searchNode
*kill_parse(searchCtx
*ctx
, int argc
, char **argv
) {
30 struct kill_localdata
*localdata
;
31 struct searchNode
*thenode
;
34 if (!(localdata
= (struct kill_localdata
*) malloc(sizeof(struct kill_localdata
)))) {
35 parseError
= "malloc: could not allocate memory for this search.";
39 if (ctx
->type
== SEARCHTYPE_CHANNEL
)
40 localdata
->marker
= nextchanmarker();
42 localdata
->marker
= nextnickmarker();
48 len
= strlcpy(localdata
->reason
, p
, sizeof(localdata
->reason
));
49 if(len
>= sizeof(localdata
->reason
)) {
50 localdata
->reason
[sizeof(localdata
->reason
)-1] = '\0';
52 localdata
->reason
[len
-1] = '\0';
56 strlcpy(localdata
->reason
, defaultreason
, sizeof(localdata
->reason
));
58 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
59 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
60 parseError
= "malloc: could not allocate memory for this search.";
65 thenode
->returntype
= RETURNTYPE_BOOL
;
66 thenode
->localdata
= localdata
;
67 thenode
->exe
= kill_exe
;
68 thenode
->free
= kill_free
;
73 void *kill_exe(searchCtx
*ctx
, struct searchNode
*thenode
, void *theinput
) {
74 struct kill_localdata
*localdata
;
78 localdata
= thenode
->localdata
;
80 if (ctx
->type
== SEARCHTYPE_CHANNEL
) {
81 cip
= (chanindex
*)theinput
;
82 cip
->marker
= localdata
->marker
;
83 localdata
->count
+= cip
->channel
->users
->totalusers
;
86 np
= (nick
*)theinput
;
87 np
->marker
= localdata
->marker
;
94 void kill_free(searchCtx
*ctx
, struct searchNode
*thenode
) {
95 struct kill_localdata
*localdata
;
99 unsigned int nickmarker
;
102 localdata
= thenode
->localdata
;
104 if (localdata
->count
> NSMAX_KILL_LIMIT
) {
105 /* need to warn the user that they have just tried to twat half the network ... */
106 ctx
->reply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
112 /* For channel searches, mark up all the nicks in the relevant channels first */
113 if (ctx
->type
== SEARCHTYPE_CHANNEL
) {
114 nickmarker
=nextnickmarker();
115 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
116 for (cip
=chantable
[i
];cip
;cip
=cip
->next
) {
117 /* Skip empty and non-matching channels */
118 if (!cip
->channel
|| cip
->marker
!= localdata
->marker
)
121 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
122 if (cip
->channel
->users
->content
[j
]==nouser
)
125 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
])))
126 np
->marker
=nickmarker
;
131 /* For nick searches they're already marked, pick up the saved value */
132 nickmarker
=localdata
->marker
;
135 /* Now do the actual kills */
136 for (i
=0;i
<NICKHASHSIZE
;i
++) {
137 for (np
=nicktable
[i
];np
;np
=nnp
) {
140 if (np
->marker
!= nickmarker
)
143 if (IsOper(np
) || IsService(np
) || IsXOper(np
)) {
148 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
149 killuser(NULL
, np
, "%s", msgbuf
);
154 ctx
->reply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
155 /* notify opers of the action */
156 ctx
->wall(NL_KICKKILLS
, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
157 (localdata
->count
- safe
) != 1 ? "users" : "user", (ctx
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", safe
);