]> jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-gline.c
7675f64c36dc181a1757383587a9ca0542afb823
[irc/quakenet/newserv.git] / newsearch / ns-gline.c
1 /*
2 * GLINE 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 "../irc/irc.h" /* irc_send() */
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 *gline_exe(struct searchNode *thenode, int type, void *theinput);
19 void gline_free(struct searchNode *thenode);
20
21 struct gline_localdata {
22 unsigned int marker;
23 int count;
24 searchNode **nodes;
25 };
26
27 struct searchNode *gline_parse(int type, int argc, char **argv) {
28 struct gline_localdata *localdata;
29 struct searchNode *thenode;
30
31 localdata = (struct gline_localdata *) malloc(sizeof(struct gline_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 = gline_exe;
41 thenode->free = gline_free;
42
43 return thenode;
44 }
45
46 void *gline_exe(struct searchNode *thenode, int type, void *theinput) {
47 struct gline_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 gline_free(struct searchNode *thenode) {
66 struct gline_localdata *localdata;
67 nick *np, *nnp;
68 int i, safe=0;
69
70 localdata = thenode->localdata;
71
72 if (localdata->count > NSMAX_GLINE_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 if (np->ident[0] == '~')
87 irc_send("%s GL * +*@%s %u 1 :You (%s!%s@%s) have been glined for violating our terms of service.",
88 mynumeric->content, IPtostr(np->ipaddress), NSGLINE_DURATION, np->nick, np->ident, IPtostr(np->ipaddress));
89 else
90 irc_send("%s GL * +%s@%s %u 1 :You (%s!%s@%s) have been glined for violating our terms of service.",
91 mynumeric->content, np->ident, IPtostr(np->ipaddress), NSGLINE_DURATION, np->nick, np->ident, IPtostr(np->ipaddress));
92 }
93 else
94 safe++;
95 }
96 }
97 }
98 if (safe)
99 controlreply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
100 free(localdata->nodes);
101 free(localdata);
102 free(thenode);
103 }