]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-kill.c
added gline time support as (and (channel #tlz) (gline 2w)). changed gline format...
[irc/quakenet/newserv.git] / newsearch / ns-kill.c
1 /*
2 * KILL functionality
3 */
4
5 #include "newsearch.h"
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 #include "../control/control.h" /* controlreply() */
11 #include "../localuser/localuser.h" /* killuser() */
12 #include "../lib/irc_string.h" /* IPtostr() */
13
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 const struct nick *senderNSExtern;
17
18 void *kill_exe(struct searchNode *thenode, int type, void *theinput);
19 void kill_free(struct searchNode *thenode);
20
21 struct kill_localdata {
22 unsigned int marker;
23 int count;
24 searchNode **nodes;
25 };
26
27 struct searchNode *kill_parse(int type, int argc, char **argv) {
28 struct kill_localdata *localdata;
29 struct searchNode *thenode;
30
31 localdata = (struct kill_localdata *) malloc(sizeof(struct kill_localdata));
32 localdata->nodes = (struct searchNode **) malloc(sizeof(struct searchNode *) * argc);
33 localdata->count = 0;
34 localdata->marker = nextnickmarker();
35
36 thenode=(struct searchNode *)malloc(sizeof (struct searchNode));
37
38 thenode->returntype = RETURNTYPE_BOOL;
39 thenode->localdata = localdata;
40 thenode->exe = kill_exe;
41 thenode->free = kill_free;
42
43 return thenode;
44 }
45
46 void *kill_exe(struct searchNode *thenode, int type, void *theinput) {
47 struct kill_localdata *localdata;
48 nick *np = (nick *)theinput;
49
50 localdata = thenode->localdata;
51
52 np->marker = localdata->marker;
53 localdata->count++;
54
55 switch (type) {
56 case RETURNTYPE_INT:
57 case RETURNTYPE_BOOL:
58 return (void *)1;
59 case RETURNTYPE_STRING:
60 return "1";
61 }
62 return NULL;
63 }
64
65 void kill_free(struct searchNode *thenode) {
66 struct kill_localdata *localdata;
67 nick *np, *nnp;
68 int i, safe=0;
69
70 localdata = thenode->localdata;
71
72 if (localdata->count > NSMAX_KILL_LIMIT) {
73 /* need to warn the user that they have just tried to twat half the network ... */
74 controlreply(senderNSExtern, "Warning: your pattern matches too many users (%d) - nothing done.", localdata->count);
75 free(localdata->nodes);
76 free(localdata);
77 free(thenode);
78 return;
79 }
80
81 for (i=0;i<NICKHASHSIZE;i++) {
82 for (np=nicktable[i];np;np=nnp) {
83 nnp = np->next;
84 if (np->marker == localdata->marker) {
85 if (!IsOper(np) && !IsService(np) && !IsXOper(np)) {
86 killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service.", np->nick,
87 np->ident, IPtostr(np->ipaddress));
88 }
89 else
90 safe++;
91 }
92 }
93 }
94 if (safe)
95 controlreply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
96 /* notify opers of the action */
97 controlwall(NO_OPER, NL_KICKKILLS, "%s/%s killed %d %s via nicksearch [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, localdata->count,
98 localdata->count != 1 ? "users" : "user", safe);
99 free(localdata->nodes);
100 free(localdata);
101 free(thenode);
102 }