]>
jfr.im git - irc/quakenet/newserv.git/blob - lameisp/lameisp.c
3 #include "../control/control.h"
4 #include "../lib/irc_string.h"
5 #include "../localuser/localuserchannel.h"
8 #define LI_KILL_MESSAGE "excess clones from your host"
10 static char *li_isps
[] = {"*.t-dialin.net", NULL
};
12 void li_nick(int hooknum
, void *arg
);
13 void li_killyoungest(nick
*np
);
14 int li_stats(void *source
, int cargc
, char **cargv
);
23 /* little optimisation */
24 for(i
=0;li_isps
[i
];i
++);
27 /* ok, first time loading we have to go through every host
28 and check for excess clones, and obviously kill the excess */
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
);
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
);
44 deregisterhook(HOOK_NICK_NEWNICK
, &li_nick
);
45 deregistercontrolcmd("victims", li_stats
);
48 void li_nick(int hooknum
, void *arg
) {
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 */
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 */
63 li_victims
++; /* ah, fresh victims for my ever-growing army of the undead */
64 killuser(NULL
, youngest
, LI_KILL_MESSAGE
); /* byebye */
67 int li_stats(void *source
, int cargc
, char **cargv
) {
68 controlreply((nick
*)source
, "Victims: %d clients", li_victims
);