]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kill.c
10 #include "../control/control.h" /* controlreply() */
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(struct searchNode
*thenode
, void *theinput
);
20 void kill_free(struct searchNode
*thenode
);
21 static const char *defaultreason
= "You (%u) have been disconnected for violating our terms of service";
23 struct kill_localdata
{
27 char reason
[NSMAX_REASON_LEN
];
30 struct searchNode
*kill_parse(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(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(struct searchNode
*thenode
) {
97 struct kill_localdata
*localdata
;
99 chanindex
*cip
, *ncip
;
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 controlreply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
114 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
115 nickmarker
=nextnickmarker();
116 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
117 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
119 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
120 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
121 if (cip
->channel
->users
->content
[j
]==nouser
)
124 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
125 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
126 np
->marker
=nickmarker
;
135 for (i
=0;i
<NICKHASHSIZE
;i
++) {
136 for(np
=nicktable
[i
];np
;np
=nnp
) {
138 if (np
->marker
== nickmarker
) {
139 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
140 killuser(NULL
, np
, "%s", msgbuf
);
146 for (i
=0;i
<NICKHASHSIZE
;i
++) {
147 for (np
=nicktable
[i
];np
;np
=nnp
) {
149 if (np
->marker
== localdata
->marker
) {
150 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
151 nssnprintf(msgbuf
, sizeof(msgbuf
), localdata
->reason
, np
);
152 killuser(NULL
, np
, "%s", msgbuf
);
161 controlreply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
162 /* notify opers of the action */
163 controlwall(NO_OPER
, NL_KICKKILLS
, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
164 (localdata
->count
- safe
) != 1 ? "users" : "user", (localdata
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", safe
);