<?php
declare(strict_types=1);

// Housekeeping, once a minute:
//   * * * * *  php /srv/http/nergmud/bin/cron.php >> /var/log/nergmud-cron.log 2>&1

if (PHP_SAPI !== 'cli') {
    exit("Run this from the command line.\n");
}

require __DIR__ . '/../src/bootstrap.php';

use App\Db;

App\RateLimit::prune();

// Old events: nobody will poll for them again.
Db::run('DELETE FROM events WHERE created_at < ?', [now() - 86400]);

// Expired puzzle switches.
Db::run('DELETE FROM world_state WHERE until_at > 0 AND until_at < ?', [now()]);

// Items dropped away from home and left lying for 2 hours are tidied away
// (spawns replace them), so the world doesn't fill up with litter.
Db::run('DELETE FROM items WHERE player_id IS NULL AND dropped_at IS NOT NULL AND dropped_at < ?
         AND (home IS NULL OR room <> home)', [now() - 7200]);
