]>
jfr.im git - irc/quakenet/lightweight.git/blob - clientcommands/cleanupdb.c
2 This file is part of lightweight.
4 lightweight is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 lightweight is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with lightweight; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <lightweight.h>
20 #include <globalexterns.h>
22 #include <accountsdb.h>
23 #include <channelsdb.h>
29 * cleanupdb: removes unused (no authed join for DAYS_BEFORE_EXPIRE days) and
30 * and empty channels (ie: empty chanlev) unless they are suspended.
33 * -n Don't execute, just show what would be done.
39 #define CHAN_EXPIRED 1
42 #define CHAN_SUSPENDED_EXPIRED 98
43 #define CHAN_SUSPENDED 99
45 static int preview
, verbose
;
47 int ExpireChannel(struct reggedchannel
*chan
, struct user
*usr_ptr
, int preview
)
51 unsigned char currentflags
;
55 i
= (now
- chan
->lastused
) / (3600 * 24);
57 if (IsSuspended(chan
)) {
58 if (now
- chan
->lastused
> (SUSPEND_EXPIRY_TIME
* 3600 * 24)) {
60 NoticeToUser(usr_ptr
, "%s has been deleted. (suspended for %d days)", chan
->channelname
, i
);
62 Log("Cleanupdb: channel %s removed (suspended for > %d days)", chan
->channelname
, i
);
63 sprintf(buf
, "Channel removed, suspended for > %d days.", i
);
64 PartChannel(chan
, buf
);
67 return (CHAN_SUSPENDED_EXPIRED
);
69 return (CHAN_SUSPENDED
);
72 if (chan
->lastused
&& ((now
- DAYS_BEFORE_EXPIRE
* 3600 * 24) > chan
->lastused
)) {
74 NoticeToUser(usr_ptr
, "%s has expired. (unused for %d days)", chan
->channelname
, i
);
76 Log("Cleanupdb: channel %s removed (expired: unused for %d days)", chan
->channelname
, i
);
77 sprintf(buf
, "Channel expired, unused for %d days.", i
);
78 PartChannel(chan
, buf
);
81 return (CHAN_EXPIRED
);
84 /* remove empty channels and non-empty channels w/o any owner/master or op (+n/+m/+o) */
85 for (i
= 0; i
< USERSPERCHANNEL
; i
++) {
86 if (NULL
!= chan
->channeluser
[i
]) {
88 currentflags
= chan
->channeluser
[i
]->channelflags
[GetUserChannelIndex(chan
, chan
->channeluser
[i
])];
89 if (currentflags
& CFLAG_OWNER
|| currentflags
& CFLAG_MASTER
|| currentflags
& CFLAG_OP
) {
96 NoticeToUser(usr_ptr
, "%s %s.", chan
->channelname
, (empty
? "is empty" : "has no owners, masters or operators"));
98 Log("Cleanupdb: channel %s removed (%s)", chan
->channelname
, (empty
? "empty" : "no owners, masters or operators"));
99 sprintf(buf
, "Channel %s.", (empty
? "is empty" : "has no owners, masters or operators"));
100 PartChannel(chan
, buf
);
104 return (empty
? CHAN_EMPTY
: CHAN_OWNER
);
107 void docleanupdb(struct user
*usr_ptr
, char *tail
)
111 struct reggedchannel
*chan
;
112 unsigned int chan_ok
, chan_expired
, chan_empty
, chan_owner
, chan_suspended
,
113 chan_suspended_expired
, chan_unknown
, chan_total
;
115 if (!usr_ptr
->oper
) {
116 NoticeToUser(usr_ptr
, "You are not an operator");
120 if (!CheckAuthLevel(usr_ptr
, 255))
123 preview
= verbose
= 0;
127 if (option
!= NULL
) {
139 NoticeToUser(usr_ptr
, "Usage: cleanupdb [-nv]");
146 Log("Cleanupdb: %s (%s) requested cleanupdb%s", usr_ptr
->nick
, usr_ptr
->authedas
->authname
,
147 (preview
? " -n (preview mode)." : "."));
149 chan_ok
= chan_expired
= chan_empty
= chan_owner
= chan_suspended
= chan_suspended_expired
= chan_unknown
= 0;
150 for (i
= 0; i
< HASHMAX
; i
++) {
151 chan
= channelhashtable
[i
];
152 while (NULL
!= chan
) { /* go through the list */
153 switch (ExpireChannel(chan
, usr_ptr
, preview
)) {
169 case CHAN_SUSPENDED_EXPIRED
:
170 chan_suspended_expired
++;
176 chan
= chan
->nextbychannelname
; /* next in list */
180 chan_total
= chan_expired
+ chan_empty
+ chan_owner
+ chan_suspended
+ chan_unknown
+ chan_ok
+ chan_suspended_expired
;
181 NoticeToUser(usr_ptr
, "%d channel/s %s (unused for >= %d days)", chan_expired
,
182 (preview
) ? "would be removed" : "removed", DAYS_BEFORE_EXPIRE
);
183 NoticeToUser(usr_ptr
, "%d channel/s %s (empty)", chan_empty
, (preview
) ? "would be removed" : "removed");
184 NoticeToUser(usr_ptr
, "%d channel/s %s (no owners, masters or operators)", chan_owner
, (preview
) ? "would be removed" : "removed");
186 NoticeToUser(usr_ptr
, "%d channel/s (unknown)", chan_unknown
);
187 NoticeToUser(usr_ptr
, "%d channel/s suspended (untouched)", chan_suspended
);
188 NoticeToUser(usr_ptr
, "%d channel/s suspended (cleaned)", chan_suspended_expired
);
189 NoticeToUser(usr_ptr
, "%d channel/s still valid (was %d channel/s)",
190 (chan_total
- (chan_expired
+ chan_empty
+ chan_owner
+ chan_suspended_expired
)), chan_total
);
193 Log("Cleanupdb: %s (%s) deleted %d channel/s (%d expired, %d empty, %d no owner/master/op) of %d channel/s", usr_ptr
->nick
,
194 usr_ptr
->authedas
->authname
, (chan_expired
+ chan_empty
+ chan_owner
), chan_expired
, chan_empty
, chan_owner
,
197 NoticeToUser(usr_ptr
, "Done.");