]>
jfr.im git - irc/quakenet/newserv.git/blob - chanserv/usercmds/cleanupdb.c
2f79b09f3d34344f2cc79ef1e498119461e00460
1 /* Automatically generated by refactor.pl.
7 * CMDDESC: Clean up database.
8 * CMDFUNC: csu_docleanupdb
9 * CMDPROTO: int csu_docleanupdb(void *source, int cargc, char **cargv);
10 * CMDHELP: Usage: cleanupdb
11 * CMDHELP: Cleans up inactive accounts, unused accounts and inactive channels.
14 #include "../chanserv.h"
15 #include "../../lib/irc_string.h"
19 int csu_docleanupdb(void *source
, int cargc
, char **cargv
) {
21 reguser
*vrup
, *srup
, *founder
;
22 regchanuser
*rcup
, *nrcup
;
26 long to_age
, unused_age
, maxchan_age
;
27 int expired
= 0, unauthed
= 0, chansvaped
= 0;
28 chanindex
*cip
, *ncip
;
32 to_age
= t
- (CLEANUP_ACCOUNT_INACTIVE
* 3600 * 24);
33 unused_age
= t
- (CLEANUP_ACCOUNT_UNUSED
* 3600 * 24);
34 maxchan_age
= t
- (CLEANUP_CHANNEL_INACTIVE
* 3600 * 24);
36 cs_log(sender
, "CLEANUPDB started");
38 chanservsendmessage(sender
, "Scanning regusers...");
39 for (i
=0;i
<REGUSERHASHSIZE
;i
++) {
40 for (vrup
=regusernicktable
[i
]; vrup
; vrup
=srup
) {
41 srup
=vrup
->nextbyname
;
42 if (!(anp
=findauthname(vrup
->ID
)))
43 continue; /* should maybe raise hell instead */
45 if(!anp
->nicks
&& !UHasHelperPriv(vrup
) && !UIsCleanupExempt(vrup
)) {
46 if(vrup
->lastauth
&& (vrup
->lastauth
< to_age
)) {
48 cs_log(sender
, "CLEANUPDB inactive user %s %u", vrup
->username
, vrup
->ID
);
49 } else if(!vrup
->lastauth
&& (vrup
->created
< unused_age
)) {
51 cs_log(sender
, "CLEANUPDB unused user %s %u", vrup
->username
, vrup
->ID
);
61 chanservsendmessage(sender
, "Scanning chanindicies...");
62 for (i
=0;i
<CHANNELHASHSIZE
;i
++) {
63 for (cip
=chantable
[i
];cip
;cip
=ncip
) {
65 if (!(rcp
=cip
->exts
[chanservext
]))
68 if(rcp
->lastactive
< maxchan_age
) {
69 /* don't remove channels with the original founder as an oper */
70 founder
=findreguserbyID(rcp
->founder
);
71 if(founder
&& UHasOperPriv(founder
))
74 cs_log(sender
, "CLEANUPDB inactive channel %s", cip
->name
?cip
->name
->content
:"??");
75 cs_removechannel(rcp
);
79 /* Get rid of any dead chanlev entries */
80 for (j
=0;j
<REGCHANUSERHASHSIZE
;j
++) {
81 for (rcup
=rcp
->regusers
[j
];rcup
;rcup
=nrcup
) {
82 nrcup
=rcup
->nextbychan
;
85 chanservsendmessage(sender
, "Removing user %s from channel %s (no flags)",rcup
->user
->username
,rcp
->index
->name
->content
);
86 csdb_deletechanuser(rcup
);
87 delreguserfromchannel(rcp
, rcup
->user
);
94 cs_log(sender
, "CLEANUPDB complete %d inactive accounts %d unused accounts %d channels", expired
, unauthed
, chansvaped
);
95 chanservsendmessage(sender
, "Cleanup complete, %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days.", expired
, CLEANUP_ACCOUNT_INACTIVE
, unauthed
, CLEANUP_ACCOUNT_UNUSED
, chansvaped
, CLEANUP_CHANNEL_INACTIVE
);