]> jfr.im git - irc/quakenet/newserv.git/blob - lameisp/lameisp.c
Began manual merge.
[irc/quakenet/newserv.git] / lameisp / lameisp.c
1 /* lameisp.c */
2
3 #include "../control/control.h"
4 #include "../lib/irc_string.h"
5 #include "../localuser/localuserchannel.h"
6
7 #define LI_CLONEMAX 2
8 #define LI_KILL_MESSAGE "excess clones from your host"
9
10 static char *li_isps[] = {"*.t-dialin.net", NULL};
11
12 void li_nick(int hooknum, void *arg);
13 void li_killyoungest(nick *np);
14 int li_stats(void *source, int cargc, char **cargv);
15
16 int li_victims = 0;
17 int li_ispscount;
18
19 void _init() {
20 host *hp;
21 int i, j;
22
23 /* little optimisation */
24 for(i=0;li_isps[i];i++);
25 li_ispscount = i;
26
27 /* ok, first time loading we have to go through every host
28 and check for excess clones, and obviously kill the excess */
29
30 for (j=0;j<HOSTHASHSIZE;j++)
31 for(hp=hosttable[j];hp;hp=hp->next)
32 if (hp->clonecount > LI_CLONEMAX) /* if we have too many clones */
33 for(i=0;i<li_ispscount;) /* cycle through the list of isps */
34 if (match2strings(li_isps[i++], hp->name->content)) /* if our isp matches */
35 do { /* repeatedly kill the youngest until we're within acceptable boundaries */
36 li_killyoungest(hp->nicks);
37 } while (hp->clonecount > LI_CLONEMAX);
38
39 registercontrolhelpcmd("victims", NO_OPER, 0, li_stats, "Usage: victims\nShows the amount of clients victimised by lameisp.");
40 registerhook(HOOK_NICK_NEWNICK, &li_nick);
41 }
42
43 void _fini () {
44 deregisterhook(HOOK_NICK_NEWNICK, &li_nick);
45 deregistercontrolcmd("victims", li_stats);
46 }
47
48 void li_nick(int hooknum, void *arg) {
49 nick *np=(nick *)arg;
50 int i;
51 if (np->host->clonecount > LI_CLONEMAX)
52 for(i=0;i<li_ispscount;) /* cycle through isps */
53 if (match2strings(li_isps[i++], np->host->name->content))
54 li_killyoungest(np->host->nicks); /* kill only youngest as we have exactly LI_CLONEMAX clones */
55 }
56
57 void li_killyoungest(nick *np) {
58 nick *list = np, *youngest = list;
59 for(list=list->host->nicks;list->next;list=list->nextbyhost) /* cycle through all nicks with this host */
60 if (list->timestamp < youngest->timestamp) /* if we've got the youngest here */
61 youngest = list; /* set value to this one */
62
63 li_victims++; /* ah, fresh victims for my ever-growing army of the undead */
64 killuser(NULL, youngest, LI_KILL_MESSAGE); /* byebye */
65 }
66
67 int li_stats(void *source, int cargc, char **cargv) {
68 controlreply((nick *)source, "Victims: %d clients", li_victims);
69
70 return CMD_OK;
71 }