]>
Commit | Line | Data |
---|---|---|
4278cc14 IB |
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 */ | |
219d27f1 | 16 | extern nick *senderNSExtern; |
4278cc14 | 17 | |
c7f7a584 | 18 | void *kill_exe(struct searchNode *thenode, void *theinput); |
4278cc14 IB |
19 | void kill_free(struct searchNode *thenode); |
20 | ||
21 | struct kill_localdata { | |
22 | unsigned int marker; | |
23 | int count; | |
8e257015 | 24 | int type; |
4278cc14 IB |
25 | }; |
26 | ||
27 | struct searchNode *kill_parse(int type, int argc, char **argv) { | |
28 | struct kill_localdata *localdata; | |
29 | struct searchNode *thenode; | |
30 | ||
9ce4f0be IB |
31 | if (!(localdata = (struct kill_localdata *) malloc(sizeof(struct kill_localdata)))) { |
32 | parseError = "malloc: could not allocate memory for this search."; | |
33 | return NULL; | |
34 | } | |
4278cc14 | 35 | localdata->count = 0; |
8e257015 IB |
36 | localdata->type = type; |
37 | if (type == SEARCHTYPE_CHANNEL) | |
38 | localdata->marker = nextchanmarker(); | |
39 | else | |
40 | localdata->marker = nextnickmarker(); | |
4278cc14 | 41 | |
9ce4f0be IB |
42 | if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) { |
43 | /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */ | |
44 | parseError = "malloc: could not allocate memory for this search."; | |
45 | free(localdata); | |
46 | return NULL; | |
47 | } | |
4278cc14 IB |
48 | |
49 | thenode->returntype = RETURNTYPE_BOOL; | |
50 | thenode->localdata = localdata; | |
51 | thenode->exe = kill_exe; | |
52 | thenode->free = kill_free; | |
53 | ||
54 | return thenode; | |
55 | } | |
56 | ||
c7f7a584 | 57 | void *kill_exe(struct searchNode *thenode, void *theinput) { |
4278cc14 | 58 | struct kill_localdata *localdata; |
8e257015 IB |
59 | nick *np; |
60 | chanindex *cip; | |
4278cc14 IB |
61 | |
62 | localdata = thenode->localdata; | |
63 | ||
8e257015 IB |
64 | if (localdata->type == SEARCHTYPE_CHANNEL) { |
65 | cip = (chanindex *)theinput; | |
66 | cip->marker = localdata->marker; | |
67 | localdata->count += (localdata->count + cip->channel->users->totalusers); | |
68 | } | |
69 | else { | |
70 | np = (nick *)theinput; | |
71 | np->marker = localdata->marker; | |
72 | localdata->count++; | |
73 | } | |
4278cc14 | 74 | |
c7f7a584 | 75 | return (void *)1; |
4278cc14 IB |
76 | } |
77 | ||
78 | void kill_free(struct searchNode *thenode) { | |
79 | struct kill_localdata *localdata; | |
80 | nick *np, *nnp; | |
8e257015 IB |
81 | chanindex *cip, *ncip; |
82 | int i, j, safe=0; | |
4278cc14 IB |
83 | |
84 | localdata = thenode->localdata; | |
85 | ||
86 | if (localdata->count > NSMAX_KILL_LIMIT) { | |
87 | /* need to warn the user that they have just tried to twat half the network ... */ | |
88 | controlreply(senderNSExtern, "Warning: your pattern matches too many users (%d) - nothing done.", localdata->count); | |
4278cc14 IB |
89 | free(localdata); |
90 | free(thenode); | |
91 | return; | |
92 | } | |
93 | ||
8e257015 IB |
94 | if (localdata->type == SEARCHTYPE_CHANNEL) { |
95 | for (i=0;i<CHANNELHASHSIZE;i++) { | |
96 | for (cip=chantable[i];cip;cip=ncip) { | |
97 | ncip = cip->next; | |
98 | if (cip != NULL && cip->channel != NULL && cip->marker == localdata->marker) { | |
99 | for (j=0;j<cip->channel->users->hashsize;j++) { | |
100 | if (cip->channel->users->content[j]==nouser) | |
101 | continue; | |
102 | ||
103 | if ((np=getnickbynumeric(cip->channel->users->content[j]))) { | |
104 | if (!IsOper(np) && !IsService(np) && !IsXOper(np)) { | |
105 | killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service.", np->nick, | |
106 | np->ident, IPtostr(np->p_ipaddr)); | |
107 | } | |
108 | else | |
109 | safe++; | |
110 | } | |
111 | } | |
112 | } | |
113 | } | |
114 | } | |
115 | } | |
116 | else { | |
117 | for (i=0;i<NICKHASHSIZE;i++) { | |
118 | for (np=nicktable[i];np;np=nnp) { | |
119 | nnp = np->next; | |
120 | if (np->marker == localdata->marker) { | |
121 | if (!IsOper(np) && !IsService(np) && !IsXOper(np)) { | |
122 | killuser(NULL, np, "You (%s!%s@%s) have been disconnected for violating our terms of service.", np->nick, | |
123 | np->ident, IPtostr(np->p_ipaddr)); | |
124 | } | |
125 | else | |
126 | safe++; | |
4278cc14 | 127 | } |
4278cc14 IB |
128 | } |
129 | } | |
130 | } | |
131 | if (safe) | |
132 | controlreply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe); | |
f16cabe4 | 133 | /* notify opers of the action */ |
8e257015 IB |
134 | controlwall(NO_OPER, NL_KICKKILLS, "%s/%s killed %d %s via %s [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, (localdata->count - safe), |
135 | (localdata->count - safe) != 1 ? "users" : "user", (localdata->type == SEARCHTYPE_CHANNEL) ? "chansearch" : "nicksearch", safe); | |
4278cc14 IB |
136 | free(localdata); |
137 | free(thenode); | |
138 | } |