<?php

$sql = "SELECT name from " . db_prefix("accounts") . " WHERE acctid='{$userid}'";
$res = db_query($sql);
require_once "lib/charcleanup.php";
$acctids = array();
$acctids[] = $userid;
char_cleanup_allinone($acctids, CHAR_DELETE_MANUAL);
while ($row = db_fetch_assoc($res)) {
    addnews("`#%s was unmade by the gods.", $row['name'], true);
    debuglog("deleted user" . $row['name'] . "'0");
}
$sql = "DELETE FROM " . db_prefix("accounts") . " WHERE acctid='{$userid}'";
db_query($sql);
output(db_affected_rows() . " user deleted.");
//$lastexpire = 0;
$needtoexpire = strtotime("-23 hours");
if ($lastexpire < $needtoexpire) {
    savesetting("last_char_expire", date("Y-m-d H:i:s"));
    $old = getsetting("expireoldacct", 45);
    $new = getsetting("expirenewacct", 10);
    $trash = getsetting("expiretrashacct", 1);
    # First, get the account ids to delete the user prefs.
    $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE (superuser&" . NO_ACCOUNT_EXPIRATION . ")=0 AND (1=0\n" . ($old > 0 ? "OR (laston < \"" . date("Y-m-d H:i:s", strtotime("-{$old} days")) . "\")\n" : "") . ($new > 0 ? "OR (laston < \"" . date("Y-m-d H:i:s", strtotime("-{$new} days")) . "\" AND level=1 AND dragonkills=0)\n" : "") . ($trash > 0 ? "OR (laston < \"" . date("Y-m-d H:i:s", strtotime("-" . ($trash + 1) . " days")) . "\" AND level=1 AND experience < 10 AND dragonkills=0)\n" : "") . ")";
    $result = db_query($sql);
    $acctids = array();
    while ($row = db_fetch_assoc($result)) {
        $acctids[] = $row['acctid'];
    }
    require_once "lib/charcleanup.php";
    char_cleanup_allinone($acctids, $type);
    // $acctids = array();
    // $pinfo = array();
    // $dk0lvl = 0;
    // $dk0ct = 0;
    // $dk1lvl = 0;
    // $dk1ct = 0;
    // $dks = 0;
    // require_once("lib/charcleanup.php");
    // while($row1 = db_fetch_assoc($result1)) {
    // if(!char_cleanup($row1['acctid'], CHAR_DELETE_AUTO)) continue;
    // array_push($acctids,$row1['acctid']);
    // array_push($pinfo,"{$row1['login']}:dk{$row1['dragonkills']}-lv{$row1['level']}");
    // if ($row1['dragonkills']==0) {
    // $dk0lvl += $row1['level'];
    // $dk0ct++;