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