]>
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() */
14 /* used for *_free functions that need to warn users of certain things
15 i.e. hitting too many users in a (kill) or (gline) - declared in newsearch.c */
16 extern nick
*senderNSExtern
;
18 void *kill_exe(struct searchNode
*thenode
, void *theinput
);
19 void kill_free(struct searchNode
*thenode
);
21 struct kill_localdata
{
25 char reason
[NSMAX_REASON_LEN
];
28 struct searchNode
*kill_parse(int type
, int argc
, char **argv
) {
29 struct kill_localdata
*localdata
;
30 struct searchNode
*thenode
;
33 if (!(localdata
= (struct kill_localdata
*) malloc(sizeof(struct kill_localdata
)))) {
34 parseError
= "malloc: could not allocate memory for this search.";
38 localdata
->type
= type
;
39 if (type
== SEARCHTYPE_CHANNEL
)
40 localdata
->marker
= nextchanmarker();
42 localdata
->marker
= nextnickmarker();
45 len
= snprintf(localdata
->reason
, NSMAX_REASON_LEN
, ":%s", argv
[0]);
46 /* strip leading and trailing '"'s */
47 localdata
->reason
[1] = ' ';
48 localdata
->reason
[len
-1] = '\0';
51 snprintf(localdata
->reason
, NSMAX_REASON_LEN
, ".");
53 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
54 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
55 parseError
= "malloc: could not allocate memory for this search.";
60 thenode
->returntype
= RETURNTYPE_BOOL
;
61 thenode
->localdata
= localdata
;
62 thenode
->exe
= kill_exe
;
63 thenode
->free
= kill_free
;
68 void *kill_exe(struct searchNode
*thenode
, void *theinput
) {
69 struct kill_localdata
*localdata
;
73 localdata
= thenode
->localdata
;
75 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
76 cip
= (chanindex
*)theinput
;
77 cip
->marker
= localdata
->marker
;
78 localdata
->count
+= cip
->channel
->users
->totalusers
;
81 np
= (nick
*)theinput
;
82 np
->marker
= localdata
->marker
;
89 void kill_free(struct searchNode
*thenode
) {
90 struct kill_localdata
*localdata
;
92 chanindex
*cip
, *ncip
;
95 localdata
= thenode
->localdata
;
97 if (localdata
->count
> NSMAX_KILL_LIMIT
) {
98 /* need to warn the user that they have just tried to twat half the network ... */
99 controlreply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
105 if (localdata
->type
== SEARCHTYPE_CHANNEL
) {
106 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
107 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
109 if (cip
!= NULL
&& cip
->channel
!= NULL
&& cip
->marker
== localdata
->marker
) {
110 for (j
=0;j
<cip
->channel
->users
->hashsize
;j
++) {
111 if (cip
->channel
->users
->content
[j
]==nouser
)
114 if ((np
=getnickbynumeric(cip
->channel
->users
->content
[j
]))) {
115 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
116 killuser(NULL
, np
, "You (%s!%s@%s) have been disconnected for violating our terms of service%s", np
->nick
,
117 np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->reason
);
128 for (i
=0;i
<NICKHASHSIZE
;i
++) {
129 for (np
=nicktable
[i
];np
;np
=nnp
) {
131 if (np
->marker
== localdata
->marker
) {
132 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
133 killuser(NULL
, np
, "You (%s!%s@%s) have been disconnected for violating our terms of service%s", np
->nick
,
134 np
->ident
, IPtostr(np
->p_ipaddr
), localdata
->reason
);
143 controlreply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
144 /* notify opers of the action */
145 controlwall(NO_OPER
, NL_KICKKILLS
, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
146 (localdata
->count
- safe
) != 1 ? "users" : "user", (localdata
->type
== SEARCHTYPE_CHANNEL
) ? "chansearch" : "nicksearch", safe
);