]>
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"
6 #include "../lib/version.h"
11 #define LI_KILL_MESSAGE "excess clones from your host"
13 static char *li_isps
[] = {"*.t-dialin.net", NULL
};
15 void li_nick(int hooknum
, void *arg
);
16 void li_killyoungest(nick
*np
);
17 int li_stats(void *source
, int cargc
, char **cargv
);
26 /* little optimisation */
27 for(i
=0;li_isps
[i
];i
++);
30 /* ok, first time loading we have to go through every host
31 and check for excess clones, and obviously kill the excess */
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
);
42 registercontrolhelpcmd("victims", NO_OPER
, 0, li_stats
, "Usage: victims\nShows the amount of clients victimised by lameisp.");
43 registerhook(HOOK_NICK_NEWNICK
, &li_nick
);
47 deregisterhook(HOOK_NICK_NEWNICK
, &li_nick
);
48 deregistercontrolcmd("victims", li_stats
);
51 void li_nick(int hooknum
, void *arg
) {
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 */
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 */
66 li_victims
++; /* ah, fresh victims for my ever-growing army of the undead */
67 killuser(NULL
, youngest
, LI_KILL_MESSAGE
); /* byebye */
70 int li_stats(void *source
, int cargc
, char **cargv
) {
71 controlreply((nick
*)source
, "Victims: %d clients", li_victims
);