]> jfr.im git - irc/quakenet/newserv.git/blob - glines/glines_util.c
A4STATS: remove E style escapes and switch to createtable for indices
[irc/quakenet/newserv.git] / glines / glines_util.c
1 #include "../irc/irc.h"
2 #include "../trusts/trusts.h"
3 #include "glines.h"
4
5 int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags, const char *creator) {
6 glinebuf gbuf;
7 int hits;
8
9 glinebufinit(&gbuf, 0);
10 glinebufcommentf(&gbuf, "on IP mask %s@%s, set by %s", user, CIDRtostr(*ip, bits), creator);
11 glinebufaddbyip(&gbuf, user, ip, bits, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
12
13 glinebufcounthits(&gbuf, &hits, NULL);
14
15 if (flags & GLINE_SIMULATE)
16 glinebufabort(&gbuf);
17 else
18 glinebufcommit(&gbuf, 1);
19
20 return hits;
21 }
22
23 glineinfo *glinebynickex(nick *np, int duration, const char *reason, int flags, const char *creator) {
24 static glineinfo info;
25 glinebuf gbuf;
26
27 glinebufinit(&gbuf, 0);
28 glinebufcommentf(&gbuf, "on nick %s!%s@%s, set by %s", np->nick, np->ident, np->host->name->content, creator);
29 info.mask = glinebufaddbynick(&gbuf, np, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration);
30
31 glinebufcounthits(&gbuf, &info.hits, NULL);
32
33 if (flags & GLINE_SIMULATE)
34 glinebufabort(&gbuf);
35 else
36 glinebufcommit(&gbuf, 1);
37
38 return &info;
39 }
40
41 int glinebynick(nick *np, int duration, const char *reason, int flags, const char *creator) {
42 glineinfo *result = glinebynickex(np, duration, reason, flags, creator);
43 return result->hits;
44 }
45
46 void glineunsetmask(const char *mask) {
47 gline *gl;
48
49 gl = findgline(mask);
50
51 if (!gl)
52 return;
53
54 gline_deactivate(gl, 0, 1);
55 }