return CMD_ERROR;
}
+ if (rcp->ID == lastchannelID) {
+ chanservsendmessage(sender, "Sorry, can't delete last channel -- wait a while and try again.");
+ return CMD_ERROR;
+ }
+
cs_log(sender,"DELCHAN %s (%s)",cip->name->content,cargc>1?cargv[1]:"");
cs_removechannel(rcp, "Channel deleted.");
chanservstdmessage(sender, QM_DONE);
authname *anp;
int i,j;
time_t t, to_age, unused_age, maxchan_age, authhistory_age;
- int expired = 0, unauthed = 0, chansvaped = 0;
+ int expired = 0, unauthed = 0, chansvaped = 0, chansempty = 0;
chanindex *cip, *ncip;
regchan *rcp;
DBResult *pgres;
cs_log(NULL, "Removing user %s from channel %s (no flags)",rcup->user->username,rcp->index->name->content);
csdb_deletechanuser(rcup);
delreguserfromchannel(rcp, rcup->user);
+ freeregchanuser(rcup);
}
}
+
+ if (cs_removechannelifempty(NULL, rcp)) {
+ /* logged+parted by cs_removechannelifempty */
+ chansempty++;
+ }
}
}
}
csdb_cleanuphistories(authhistory_age);
- cleanuplog("Stats: %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);
+ cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days, %d channels empty.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE, chansempty);
out:
cleanupdb_active=0;
return 0;
}
}
-
+
+ /*
+ * don't cleanup the last channel to prevent channel id reuse.
+ * the channel will be orphaned but will be cleaned up by cleanup eventually
+ */
+ if(rcp->ID == lastchannelID) {
+ cs_log(sender,"DELCHAN FAILED %s (last id)",rcp->index->name->content);
+ return 0;
+ }
+
cs_log(sender,"DELCHAN %s (Empty)",rcp->index->name->content);
cs_removechannel(rcp, "Last user removed - channel deleted.");
if (!(target=findreguser(sender, cargv[0])))
return CMD_ERROR;
-
+
+ if(target->ID == lastuserID) {
+ chanservsendmessage(sender, "Sorry, can't delete last user -- wait a while and try again.");
+ return CMD_ERROR;
+ }
+
if(UHasStaffPriv(target)) {
cs_log(sender,"DELUSER FAILED username %s (reason: %s)",target->username,reason);
chanservwallmessage("%s (%s) just FAILED using DELUSER on %s (reason: %s)", sender->nick, rup->username, target->username, reason);