game/_incl_data/crons/game_clear.php

77 lines
3.1 KiB
PHP

<?php
use Core\Db;
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'autoload.php';
/**
* CRON Очистки сервера от ненужной информации
* Каждый день в 3 часа 15 минут.
*/
# DAY: 86400
function getIds($query): string
{
return implode(',', Db::getColumn($query));
}
// Заявки в клан
Db::sql('update users set clan_zv = 0 where clan_zv > 0');
// Очистка чата, остается 30 минут.
Db::sql('delete from chat where time < unix_timestamp() - 1800');
// Очистка заявок в поединки
Db::sql('delete from zayvki where start > 0 or cancel > 0 or time < unix_timestamp() - 43200');
// Очистка заявок в пещеры
Db::sql('delete from dungeon_zv where `delete` > 0 or time < unix_timestamp() - 43200');
// Очистка походов
$uids = getIds('select id from dungeon_now where time_start < unix_timestamp() - 43200 or time_finish > 0');
Db::sql('delete from dungeon_actions where dn in (?)', [$uids]);
Db::sql('delete from dungeon_bots where dn in (?)', [$uids]);
Db::sql('delete from dungeon_items where dn in (?)', [$uids]);
Db::sql('delete from dungeon_obj where dn in (?)', [$uids]);
Db::sql('delete from dungeon_now where id in (?)', [$uids]);
unset($uids);
// Очистка банов (10 дней) и отсутствующих (30 дней) и "явных ботов"
$uids = getIds(
'select id from users where
banned between 1 and unix_timestamp() - 86400 * 10 or
level < 10 and admin = 0 and online between 1 and unix_timestamp() - 86400 * 30 or
ip = 0 and online = 0 and battle = 0
'
);
Db::sql('delete from items_users where uid in (?)', [$uids]);
Db::sql('delete from eff_users where uid in (?)', [$uids]);
Db::sql('delete from users where id in (?)', [$uids]);
Db::sql('delete from rep where id in (?)', [$uids]);
Db::sql('delete from stats where id in (?)', [$uids]);
Db::sql('delete from online where uid in (?)', [$uids]);
Db::sql('delete from actions where uid in (?)', [$uids]);
unset($uids);
// Прочее
$uids = getIds('select id from users');
Db::sql('delete from items_users where uid > 0 and uid not in (?)', [$uids]);
Db::sql('delete from eff_users where uid > 0 and uid not in (?)', [$uids]);
Db::sql('delete from users_achiv where id > 0 and id not in (?)', [$uids]);
Db::sql('delete from users_delo where uid > 0 and uid not in (?) or time < unix_timestamp() - 86400 * 10', [$uids]);
Db::sql('delete from users_reting where uid > 0 and uid not in (?)', [$uids]);
Db::sql('delete from aaa_reting_list where uid > 0 and uid not in (?)', [$uids]);
Db::sql('delete from rep where id > 0 and id not in (?)', [$uids]);
Db::sql('delete from aaa_znahar where uid > 0 and uid not in (?)', [$uids]);
Db::sql('delete from user_operation where uid > 0 and uid not in (?)', [$uids]);
Db::sql(
'delete from actions where
uid > 0 and uid not in (?) or
vars = ? or
vals = ? or
vars != ? and time < unix_timestamp() - 86400 * 60',
[$uids, 'day_quest', 'loto', 'read']
);
unset($uids);
// Голосовые сообщения
Db::sql('delete from uploads where id > 0');