]>
jfr.im git - irc/quakenet/newserv.git/blob - newsearch/ns-gline.c
4c2ba5e67ad3455899968c0a57c77f7818d37a66
10 #include "../control/control.h" /* controlreply() */
11 #include "../irc/irc.h" /* irc_send() */
12 #include "../lib/irc_string.h" /* IPtostr(), longtoduration(), durationtolong() */
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
;
18 void *gline_exe(struct searchNode
*thenode
, int type
, void *theinput
);
19 void gline_free(struct searchNode
*thenode
);
21 struct gline_localdata
{
23 unsigned int duration
;
27 struct searchNode
*gline_parse(int type
, int argc
, char **argv
) {
28 struct gline_localdata
*localdata
;
29 struct searchNode
*thenode
;
31 if (!(localdata
= (struct gline_localdata
*) malloc(sizeof(struct gline_localdata
)))) {
32 parseError
= "malloc: could not allocate memory for this search.";
36 localdata
->marker
= nextnickmarker();
40 localdata
->duration
= NSGLINE_DURATION
;
42 localdata
->duration
= durationtolong(argv
[0]);
43 /* error checking on gline duration */
44 if (localdata
->duration
== 0)
45 localdata
->duration
= NSGLINE_DURATION
;
48 if (!(thenode
=(struct searchNode
*)malloc(sizeof (struct searchNode
)))) {
49 /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
50 parseError
= "malloc: could not allocate memory for this search.";
55 thenode
->returntype
= RETURNTYPE_BOOL
;
56 thenode
->localdata
= localdata
;
57 thenode
->exe
= gline_exe
;
58 thenode
->free
= gline_free
;
63 void *gline_exe(struct searchNode
*thenode
, int type
, void *theinput
) {
64 struct gline_localdata
*localdata
;
65 nick
*np
= (nick
*)theinput
;
67 localdata
= thenode
->localdata
;
69 np
->marker
= localdata
->marker
;
76 case RETURNTYPE_STRING
:
82 void gline_free(struct searchNode
*thenode
) {
83 struct gline_localdata
*localdata
;
87 localdata
= thenode
->localdata
;
89 if (localdata
->count
> NSMAX_GLINE_LIMIT
) {
90 /* need to warn the user that they have just tried to twat half the network ... */
91 controlreply(senderNSExtern
, "Warning: your pattern matches too many users (%d) - nothing done.", localdata
->count
);
97 for (i
=0;i
<NICKHASHSIZE
;i
++) {
98 for (np
=nicktable
[i
];np
;np
=nnp
) {
100 if (np
->marker
== localdata
->marker
) {
101 if (!IsOper(np
) && !IsService(np
) && !IsXOper(np
)) {
102 if (np
->ident
[0] == '~')
103 irc_send("%s GL * +*@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.",
104 mynumeric
->content
, IPtostr(np
->ipaddress
), localdata
->duration
, np
->nick
, np
->ident
, IPtostr(np
->ipaddress
));
106 irc_send("%s GL * +%s@%s %u :You (%s!%s@%s) have been glined for violating our terms of service.",
107 mynumeric
->content
, np
->ident
, IPtostr(np
->ipaddress
), localdata
->duration
, np
->nick
, np
->ident
, IPtostr(np
->ipaddress
));
115 controlreply(senderNSExtern
, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe
);
116 /* notify opers of the action */
117 controlwall(NO_OPER
, NL_GLINES
, "%s/%s glined %d %s via nicksearch for %s [%d untouched].", senderNSExtern
->nick
, senderNSExtern
->authname
, (localdata
->count
- safe
),
118 (localdata
->count
- safe
) != 1 ? "users" : "user", longtoduration(localdata
->duration
, 1), safe
);